How to specify the default XML element text in OpenAPI (Swagger)?

元气小坏坏 提交于 2020-01-04 03:33:25

问题


I'm building an OpenAPI (Swagger) 2.0 definition for the following XML payload to use within the Swagger UI:

<addressElement>
    <key type="RECORD_ID" item="3">Enter value here</key>
</addressElement>

I'm having an issue figuring out how to display the default value 'Enter value here' for the element key. Where would one place this default value in an OpenAPI definition? My definition looks like this:

    "definitions": {
     "addressElement": {
      "type": "object",
      "title": "Address Element",
      "properties": {
        "key": {
          "type": "object",
          "properties": {
          "type":{
            "type": "string",
            "example": "RECORD_ID",
            "xml":{
              "attribute": true
            }
          },
          "item":{
            "type": "integer",
            "format": "int64",
            "example": "3",
            "xml":{
              "attribute": true
            }
          }
        }
      },
    },
    "xml": {
      "name": "addressElement"
    }
  }
 }

回答1:


This is currently not possible because OpenAPI does not have a way to represent XML elements with attributes such as

<key type="RECORD_ID" item="3">Enter value here</key>

Attributes can only be defined for objects

<obj attr="value">
  <elem>Some text</elem>
</obj>

but not for simple <elem>text</elem> elements.

There's an open issue about this limitation here:
How to represent XML elements with attributes

That said, OpenAPI Specification maintainers are considering an option to use alternative data modeling schemas (such as XSD Schema), so your use case might be supported in a future version of OpenAPI.



来源:https://stackoverflow.com/questions/54164941/how-to-specify-the-default-xml-element-text-in-openapi-swagger

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