OpenAPI JSON Schema配置XML序列化生成嵌套标签如何修正为单层结构
解决方案
你只需要在原有Schema的number属性配置中新增xml.text: true即可实现预期的单层XML输出,调整后的完整Schema如下:
schema: required: true title: number xml: name: number properties: number: type: string xml: text: true
配置说明
xml.text: true是OpenAPI/Swagger内置的XML渲染规则,指定该字段的值直接作为父节点的文本内容,不会单独生成嵌套标签- 根节点的
xml.name: number明确指定根节点标签名,避免默认规则生成的标签名异常
调整后生成的JSON格式保持不变,仍为{"number": "string"},XML会自动渲染为你预期的单层结构:
<number>string</number>
内容的提问来源于stack exchange,提问作者Vishwanath Washimkar
相关产品推荐
相关产品推荐

