如何在OpenAPI(Swagger)中指定默认的XML元素文本?

编程入门 行业动态 更新时间:2024-10-15 16:23:35
本文介绍了如何在OpenAPI(Swagger)中指定默认的XML元素文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为以下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元素文本?

本文发布于:2023-05-23 15:06:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1326438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   文本   如何在   Swagger   OpenAPI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!