0.0.5 • Published 6 years ago

rest-openapi-generator v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

rest-openapi-generator

RESTful Open API Spec generator with resource definitions.

Currently only Swagger v2.0 is supported.

Install

$ npm install rest-openapi-generator

Usage

Configuration

First of all, create a configuration file by json or yaml.
By default the command refers to rogconfig.yaml on the application root, but you can optionally specify the file anywhere.

The configuration file has the following format.

rootDir: ./
output: ./openapi.yaml
openapi:
  info:
    title: Your REST API
    version: 0.0.0
  host: your.domain.com
  basePath: /api/v1
resources:
  - name: user
    schema: ./schemas/user.schema.json
  - name: calendar
    pathName: events
    directory: '/users/{userId}'
    schema:
      name: Event
      schema: http://json-schema.org/example/calendar.json
    tags:
      - event
    actions:
      list:
        tags:
          - event
        parameters:
          - name: userId
            in: path
            type: string
            required: true
          - name: location
            in: query
            type: string
            required: false
      create:
        tags:
          - event
        parameters:
          - name: userId
            in: path
            type: string
            required: true
      read:
        tags:
          - event
        parameters:
          - name: userId
            in: path
            type: string
            required: true
      update:
        tags:
          - event
        parameters:
          - name: userId
            in: path
            type: string
            required: true
      patch:
        tags:
          - event
        parameters:
          - name: userId
            in: path
            type: string
            required: true
      delete: false
  • rootDir
    • Root directory of the relative path inside the config file.
  • output
    • Destination directory and file name.
    • You can choose yaml or json.
  • openapi
    • Parameters that required for OpenAPI Specification.
    • When not entering, dummy values is inserted.
    • If necessary items are set, the values are also merged with the output.
  • resources
    • Setting of resource that you want to provide with REST API
    • Just by setting the name and the schema file, the REST API definition is generated.
    • You can also set the pathName and schema.name separately.
    • You can specify the directory to prepare the REST API with directory. Query parameters can also be used, but please add the parameter definition within each action.
    • You can add items available in Open API to each action of list, create, read, update, patch, delete.
    • If you do not want to create a specific action, set false.
    • If resource config contained tags, merge to each path tag parameter.

Command

Usage: rog [options]

  RESTful Open API Spec generator with resource definitions.

  Options:

    -V, --version         output the version number
    --c, --config <path>  Specify config file path. (default "./rogconfig.yaml")
    -h, --help            output usage information