OpenAPI 5

Submitted by Lizhe on Thu, 11/19/2020 - 05:58

 

上一个例子中使用的是 Parameters

这里尝试一下 request body

抛开 go-swagger不谈,直接使用 swagger 应该是下面的样子

20201119015854

 

 

openapi: 3.0.0

info:

  description: |

    This is a sample Petstore server.  You can find

    out more about Swagger at

    [http://swagger.io](http://swagger.io) or on

    [irc.freenode.net, #swagger](http://swagger.io/irc/).

  version: 1.0.0

  title: Swagger Petstore

paths:

  /login:

    post:

      tags:

        - pet

      summary: Add a new pet to the store

      operationId: addPet

      responses:

        '405':

          description: Invalid input

      requestBody:

        $ref: '#/components/requestBodies/Login'

components:

  schemas:

    LoginRequest:

      type: object

      required:

        - name

        - password

      properties:

        name:

          type: string

          example: myname

        password:

          type: string

          example: mypassword

  requestBodies:

    Login:

      content:

        application/json:

          schema:

            $ref: '#/components/schemas/LoginRequest'

        application/xml:

          schema:

            $ref: '#/components/schemas/LoginRequest'

      description: Pet object that needs to be added to the store

      required: true