You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 16:00:02