Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

swagger-to-flowtype

0.3.0 • Public • Published

swagger-to-flowtype

swagger-to-flowtype is a tool for generating type definitions of Flow from swagger file.

Getting started

Install package

npm i -g swagger-to-flowtype

Generating flow type definitions

$swagger-to-flowtype <YOUR SWAGGER FILE OR URL>

This command generates a file named flowtype.js includes type definitions as default.

Options

Specify an output path

You can also specify an output path with -d option.

$swagger-to-flowtype <YOUR SWAGGER FILE PATH OR URL> -d <OUTPUT FILE PATH>

Supporting Maybe type

If you pass a --check-required option, swagger-to-flowtype will check required field on your swagger file, then output flow definitions with Maybe type.

"NewPet"{
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string"
    },
    "tag": {
      "type": "string"
    }
  }
}

will be

export type NewPet = {
  namestring,
  tag?: string
}

Transform property key to lower camel case

--lower-camel-case option transforms each property keys to lower camel case.

"Cat"{
  "type": "object",
  "properties": {
    "long_long_key": {
      "type": "string"
    }
  }
}

will be

export type Cat = { longLongKey?: string };

Example

swagger file like following

...
 
definitions:
  Order:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      petId:
        type: "integer"
        format: "int64"
      quantity:
        type: "integer"
        format: "int32"
      shipDate:
        type: "string"
        format: "date-time"
      status:
        type: "string"
        description: "Order Status"
        enum:
        - "placed"
        - "approved"
        - "delivered"
      complete:
        type: "boolean"
        default: false
    xml:
      name: "Order"
  Category:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      name:
        type: "string"
    xml:
      name: "Category"
...
 

Output will be like below

// @flow
export type Order = {
  idnumber,
  petIdnumber,
  quantitynumber,
  shipDatestring,
  statusstring,
  completeboolean
};
export type Category = { idnumber, namestring };
 

Requirements

Node 4+ is required

Tests

npm test

Keywords

Install

npm i swagger-to-flowtype

DownloadsWeekly Downloads

5,312

Version

0.3.0

License

MIT

Unpacked Size

239 kB

Total Files

20

Last publish

Collaborators

  • avatar