如何在OpenAPI(Swagger)中指定默认的XML元素文本? [英] How to specify the default XML element text in OpenAPI (Swagger)?
问题描述
我正在为以下XML有效负载构建一个OpenAPI(Swagger)2.0定义,以在Swagger UI中使用:
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>
在解决如何显示元素key
的默认值在此处输入值"时遇到问题.将此默认值放在OpenAPI定义中的什么位置?我的定义如下:
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"
}
}
}
推荐答案
当前这是不可能的,因为OpenAPI无法使用诸如这样的属性来表示XML元素
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>
只能为对象定义属性
<obj attr="value">
<elem>Some text</elem>
</obj>
,但不适用于简单的<elem>text</elem>
元素.
but not for simple <elem>text</elem>
elements.
这里有一个关于此限制的公开问题:
如何用属性表示XML元素
There's an open issue about this limitation here:
How to represent XML elements with attributes
也就是说,OpenAPI规范的维护者正在考虑使用替代数据建模架构(例如XSD架构),因此将来的OpenAPI版本可能会支持您的用例.
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.
这篇关于如何在OpenAPI(Swagger)中指定默认的XML元素文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!