Swagger自动生成文档yaml格式?

时间:2018-02-23 02:57:16

标签: node.js swagger

有sequelize auto,您可以通过命令行为SequelizeJS生成生成模型。我想知道是否有一种方法可以使用命令行从我的数据库中自动生成.yaml fromat中的api swagger文档。谢谢 。你的帮助真的会被贬低。

swagger api documentaion,有没有办法自动生成它而不是从我的数据库中键入每个CRUD这是一个麻烦。感谢

swagger: "2.0"
info:
  version: 1.0.0
  title: myApp1.0
  description: my Application 1.0
basePath: /api/v1
tags:
  - name: Examples
    description: Simple example endpoints
  - name: Products
    description: Simple products endpoints
  - name: Countries
    description: Simple countries endpoints
  - name: Users
    description: Simple Users endpoints
  - name: Specification
    description: The swagger API specification

consumes:
  - application/x-www-form-urlencoded
  - application/json
produces:
  - application/json

definitions:
  ExampleBody:
    type: object
    title: example
    required:
      - name
    properties:
      name:
        type: string
        description: The example name
  ProductsBody:
    type: object
    title: products
    required:
      - name
    properties:
      name:
        type: string
        description: The products name
  CountriesBody:
    type: object
    title: countries
    required:
      - name
      - sortname
    properties:
      name:
        type: string
        description: The countries name
      sortname:
        type: string
        description: The countries sortname
  UsersBody:
    type: object
    title: users
    required:
      - user_id
      - firstname
      - lastname
      - about
      - username
      - email
      - password
      - last_login
      - status
    properties:
      name:
        type: string
        description: The users firstname
      sortname:
        type: string
        description: The users lastname

paths:
  /examples:
    get:
      tags:
        - Examples
      description: Fetch all examples
      responses:
        200:
          description: Returns all examples
    post:
      tags:
        - Examples
      description: Create a new example
      parameters:
        - name: example
          in: body
          description: number of items to skip
          required: true
          schema: 
            $ref: "#/definitions/ExampleBody"
      responses:
        200:
          description: Returns all examples

  /examples/{id}:
    get:
      tags:
        - Examples
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the entity to retrieve
          type: integer
      responses:
        200:
          description: Return the example with the specified id
        404:
          description: Example not 

  /products:
    get:
      tags:
        - Products
      description: Fetch all products
      parameters:
        - name: offset
          in: query
          required: true
          description: The offset of the pagination
          type: integer
        - name: limit
          in: query
          required: true
          description: The limit of the pagination
          type: integer
      responses:
        200:
          description: "successful operation"
      #security:
      #- api_key: []
    post:
      tags:
        - Products
      description: Create a new example
      parameters:
        - name: example
          in: body
          description: number of items to skip
          required: true
          schema: 
            $ref: "#/definitions/ProductsBody"
      responses:
        200:
          description: Returns all products
      security:
      - api_key: []

  /products/{id}:
    get:
      tags:
        - Products
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the entity to retrieve
          type: integer
      responses:
        200:
          description: Return the products with the specified id
        404:
          description: Products not
      security:
      - api_key: []

  /countries:
    get:
      tags:
        - Countries
      description: Fetch all countries
      parameters:
        - name: token
          in: header
          required: false
          description: The header token
          type: string
        - name: offset
          in: query
          required: false
          description: The offset of the pagination
          type: integer
        - name: limit
          in: query
          required: false
          description: The limit of the pagination
          type: integer
      responses:
        200:
          description: "successful operation"
      #security:
      #- api_key: []
    post:
      tags:
        - Countries
      description: Create a new Country
      parameters:
        - name: token
          in: header
          required: false
          description: The header token
          type: string
        - name: country
          in: body
          description: number of items to skip
          required: true
          schema: 
            $ref: "#/definitions/CountriesBody"
      responses:
        200:
          description: Create Country
  #    security:
  #    - api_key: []

  /users:
    get:
      tags:
        - Users
      description: Fetch all users
      parameters:
        - name: token
          in: header
          required: false
          description: The header token
          type: string
        - name: offset
          in: query
          required: false
          description: The offset of the pagination
          type: integer
        - name: limit
          in: query
          required: false
          description: The limit of the pagination
          type: integer
      responses:
        200:
          description: "successful operation"
    post:
      tags:
        - Users
      description: Create New User Accounts
      parameters:
        - name: Users
          in: body
          description: number of items to skip
          required: true
          schema: 
            $ref: "#/definitions/UsersBody"
      responses:
        200:
          description: Create User Accounts
      security:
      - api_key: []

  /users/{id}:
    delete:
      tags:
        - Users
      parameters:
        - user_id: id
          in: path
          required: true
          description: The id of the entity to be deleted
          type: integer
      responses:
        200:
          description: Returns a successful delete
        404:
          description: Error
      security:

  /spec:
    get:
      tags:
        - Specification
      responses:
        200:
          description: Return the API specification
securityDefinitions:
  #petstore_auth:
  #  type: "oauth2"
  #  authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
  #  flow: "implicit"
  #  scopes:
  #    write:pets: "modify pets in your account"
  #    read:pets: "read your pets"
  api_key:
    type: "apiKey"
    name: "api_key"
    in: "header"

0 个答案:

没有答案