在 OpenAPI 中,如何定义具有属性和内容的 XML 元素? [英] In OpenAPI, how to define an XML element with attributes AND content?

查看:54
本文介绍了在 OpenAPI 中,如何定义具有属性和内容的 XML 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 OpenAPI 2.0 (Swagger 2.0) 描述 RESTful 接口的 XML 响应负载.但是,我很难在 OpenAPI 数据模型中描述特定的 XML 标记.

I would like to describe the XML response payload of a RESTful interface with OpenAPI 2.0 (Swagger 2.0). However, I struggle describing a particular XML tag in the OpenAPI data model.

我无法让 Swagger UI 以这种形式创建适当的示例 XML 标记,在 XML 开始标记和结束标记之间具有 属性:

I can't get Swagger UI to create an appropriate example XML tag in this form, with an attribute and content between the opening and closing XML tags:

<Person id="bar">foo</Person>

文档(此处) 仅描述了如何对带有子标签 (type: object) 或带有内容的标签 (type: string) 的标签进行建模,但不描述两者同时进行.

The documentation (here) only describes how to model a tag with sub tags (type: object) or a tag with content (type: string), but not both at the same time.

我试过了,Swagger 编辑器接受了这个,没有任何错误或警告:

I tried this, which the Swagger Editor accepts without any errors or warnings:

definitions:
  Person:
    type: string
    example: foo
    properties:
      id:
        type: string
        example: bar
        xml:
          attribute: true

但它会被 Swagger UI 呈现为以下示例:

but it will be rendered by Swagger UI to the following example:

<Person id="bar"></Person>

如您所见,没有foo"内容在那里.

As you can see, no "foo" content in there.

推荐答案

遗憾的是没有办法使用 OpenAPI 规范 2.0.

Unfortunately there's no way to represent that using the OpenAPI Specification 2.0.

正在此处跟踪此问题,并且可以在未来版本的规范.

This issue is being tracked here and could be addressed in future versions of the specification.

这篇关于在 OpenAPI 中,如何定义具有属性和内容的 XML 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆