代码之家  ›  专栏  ›  技术社区  ›  Loren Cahlander

我很难在OpenAPI 3中为响应指定XML示例

  •  0
  • Loren Cahlander  · 技术社区  · 7 年前

    我有一个OpenAPI 3的JSON文件,包含以下内容:

                "trait_hasProjectResponse_200": {
                    "description": "",
                    "content": {
                        "application/xml": {
                            "example": {
                                "value" : "<project><foo>1</foo><bar>2</bar></project>"
                            }
                        }
                    }
                },
    

    enter image description here

    0 回复  |  直到 7 年前
        1
  •  1
  •   Helen    7 年前

    拆下 value 钥匙从 example 价值 examples

    "example": "<project><foo>1</foo><bar>2</bar></project>"
    


    或者,可以定义 schema 对于响应,Swagger UI将根据 架构 . 在您的示例中,模式是 project foo [1, 2] 福 数组:

      "components": {
        "responses": {
          "trait_hasProjectResponse_200": {
            "description": "",
            "content": {
              "application/xml": {
                "schema": {
                  "$ref": "#/components/schemas/project"
                }
              }
            }
          }
        },
        "schemas": {
          "project": {
            "type": "object",
            "properties": {
              "foo": {
                "type": "array",
                "items": {
                  "type": "integer"
                },
                "xml": {
                  "wrapped": false
                },
                "example": [1, 2]
              }
            }
          }
        }
      }
    

    这将为您提供:

    XML response example generated by Swagger UI based on the response schema