How to display object properties as separate fields in Swagger UI?

和自甴很熟 提交于 2019-12-11 07:05:51

问题


I am writing API documentation using OpenAPI 3.0. At the moment I have:

paths:
  /script/update:
    post:
      tags: 
      - "Script"
      summary: Update a script
      operationId: updateScript
      responses:
        '200':
          description: OK
        "404":
          description: Not Found
      requestBody:
        description: A script object in order to make the request
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                subsite_id:
                  type: string
                script:
                  type: object
                  properties:
                    script:
                      $ref: '#/components/schemas/ScriptType'
                    type:
                      type: string
                      enum:
                        - custom
                        - interface
                        - freshbot
                        - feeder
                        - getter
                        - smcf
                    status:
                      $ref: '#/components/schemas/ScriptStatus'
                    comment:
                      type: string
                      format: string
                    reason:
                      type: string
                      format: string

To problem comes when I try to use to Swagger UI. The only thing that appears is the following: What I want is that the script object can be filled out field by field for each of the properties it has, like the subsite_id. What am I missing?


回答1:


Swagger UI 3.x does not have a form editor for JSON objects, so all JSON data needs to be entered in the JSON format: { "prop": value, ... }

Here's the corresponding feature request you can track:
https://github.com/swagger-api/swagger-ui/issues/2771



来源:https://stackoverflow.com/questions/52385204/how-to-display-object-properties-as-separate-fields-in-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!