cancel
Showing results for 
Search instead for 
Did you mean: 

Handling XML namespace in Swagger file

Highlighted
New Contributor

Handling XML namespace in Swagger file

I am creating swagger YAML file for my XML APIs. Existing APIs consists of multiple xml namespaces in request body (sample below). I am able to take all the API to swagger YAML except definition of namespaces as part of root element.

Any inputs on how to map multiple xml namespaces would be really helfpul.

 

...

Connection: keep-alive

Content-Length: 633

<Prov xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.com/provisioning/services">
<Header>    <rID/>    <ver/></Header> </Prov>

3 REPLIES 3
Highlighted
Moderator

Re: Handling XML namespace in Swagger file

Hi @neerajdahiya,

 

Please see this article: https://swagger.io/docs/specification/data-models/representing-xml/



Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
New Contributor

Re: Handling XML namespace in Swagger file

@Nastya_Khovrina: Thanks for the info. I should've more explicit in my issue, actually I am facing issue while defining multiple xml namesapce. While trying to do so, I am getting error 'duplicated mapping key'. The definition looks like:

 

xml:
namespace: 'http://www.abc.com/xyz/services/subscriber'
xml:
prefix: 'xsi'
namespace: 'http://www.w3.org/2001/XMLSchema-instance'

 
Highlighted
Moderator

Re: Handling XML namespace in Swagger file

Hi @neerajdahiya,

 

OpenAPI Specification does not support multiple XML namespaces within a single element. As a workaround, you can define additional namespaces as regular attributes (that is, schema properties with xml.attribute=true).

openapi: 3.0.0

components:
  schemas:
    Prov:
      type: object
      xml:
        namespace: http://www.example.com/provisioning/services
      properties:
        "xmlns:xsi":   # <----------
          type: string
          enum:
- "http://www.w3.org/2001/XMLSchema-instance" xml: attribute: true Header: ...

There's an existing enhancement request to add support for alternative schema formats, such as XSL Schema (XSD), which would enable your scenario.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements