如何在Swagger UI中将对象属性显示为单独的字段? [英] How to display object properties as separate fields in Swagger UI?

查看:1986
本文介绍了如何在Swagger UI中将对象属性显示为单独的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenAPI 3.0编写API文档.目前,我有:

 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
 

当我尝试使用Swagger UI时出现问题. 唯一出现的是以下内容: 我想要的是script对象可以针对每个具有的属性(例如subsite_id)逐字段填写.我想念什么?

解决方案

Swagger UI 3.x没有用于JSON对象的表单编辑器,因此所有JSON数据都需要以JSON格式输入:{ "prop": value, ... }

以下是您可以跟踪的相应功能请求:
https://github.com/swagger-api/swagger-ui/issues/2771

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?

解决方案

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

这篇关于如何在Swagger UI中将对象属性显示为单独的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆