How to describe this POST JSON request body in OpenAPI (Swagger)?

前端 未结 2 1243
小鲜肉
小鲜肉 2020-12-05 02:15

I have a POST request that uses the following JSON request body. How can I describe this request body using OpenAPI (Swagger)?



        
2条回答
  •  悲哀的现实
    2020-12-05 02:22

    I made it work with:

        post:
          consumes:
            - application/json
          produces:
            - application/json
            - text/xml
            - text/html
          parameters:
            - name: body
              in: body
              required: true
              schema:
                # Body schema with atomic property examples
                type: object
                properties:
                  testapi:
                    type: object
                    properties:
                      messageId:
                        type: string
                        example: kkkk8
                      messageDateTime:
                        type: string
                        example: '2014-08-17T14:07:30+0530'
                  testapiBody:
                    type: object
                    properties:
                      cameraServiceRq:
                        type: object
                        properties:
                          osType:
                            type: string
                            example: android
                          deviceType:
                            type: string
                            example: samsung555
                # Alternatively, we can use a schema-level example
                example:
                  testapi:
                    testapiContext:
                      messageId: kkkk8
                      messageDateTime: '2014-08-17T14:07:30+0530'
                    testapiBody:
                      cameraServiceRq:
                        osType: android
                        deviceType: samsung555
    

提交回复
热议问题