Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

swagger - In OpenAPI, how to define an XML element with attributes AND content?

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.

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>

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.

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

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...