Hi All,
I have a scenario to add xml attribute in swagger schema.Below is the input request.
<book id="0"> <title>string</title> <author>string</author> </book>
I need to include ID in swagger schema.
Is there any way to specify an xml attribute in swagger?
Thanks,
Pratiksha Patil
Yes. The fine documentation shows how. Schema:
book: type: object properties: id: type: integer xml: attribute: true title: type: string author: type: string
document:
<book id="0"> <title>string</title> <author>string</author> </book>
This answer is so straightforward, right out of the book, that I'm thinking maybe you are asking something else. Maybe I have misunderstood. If so, let me know.
Hi Dino,
Thanks for your quick response.
Your understanding is correct.I tried with above solution but it seems this feature is currently not working.Please take a look at below link which says this is proposal for future versions of the OpenAPI Specification. They won't work today in any existing tools.
https://github.com/OAI/OpenAPI-Specification/issues/630
Thanks,
Pratiksha Patil
I tried with above solution but it seems this feature is currently not working.
I'm not sure what you tried. If you are using that kind of declaration in a tool that supports OpenAPI Spec v3.0.0, then you will find joy. Keep in mind that the current tools from Apigee do not yet support OpenAPI Spec 3.0, AFAIK. Also the online editor available on swagger.io does not appear to support OpenAPI Spec v3.0.0.
Please take a look at below link which says this is proposal for future versions of the OpenAPI Specification. They won't work today in any existing tools.
I checked that out, thanks. This comment seems off base. Or at least unclear.
Here's what I know.
This schema:
components: schemas: Person: type: object xml: namespace: http://example.com/schema/sample properties: id: type: integer format: int32 xml: attribute: true name: type: string xml: namespace: http://example.com/schema/sample required: - name - id
Allows this XML:
<Person xmlns="http://example.com/schema/sample" id="0"> <name>string</name> </Person>
I produced this with the latest swagger editor. I used the docker image. I did not use the online version, which I think is still the v2.x editor.