Forum Discussion

Juani's avatar
Juani
Occasional Visitor
2 years ago

XML Representing Attribute and Element

Hi

I'm in an urgent project and we are implementing an open api 3.0 solution in XML.

Want to try to define the following case (xml element and attribute):

 

<Header>
    <Direction index="4">Human Ressource</Fluss>
</Header>

 

This implementation does not lead to the desired result:

 

Header:
  type: object
  properties:
    Fluss:
      type: object
      properties:
        Index:
          type: string
          xml:
             attribute: true
             example: 99
        value:
            type: string
            xml:
                text:true

 

I'm getting allways errors during rendering in swagger.

Is there any solution for this problem and how does it look like?

thx for (soon) your support.

Juani

1 Reply

  • ReignCreed's avatar
    ReignCreed
    Occasional Visitor

     

    To resolve the issue you're facing with rendering in Swagger for your XML implementation of the OpenAPI 3.0 solution, you can make the following adjustments to your schema:

     

    Header: type: object properties: Fluss: type: object properties: "#text": type: string xml: wrapped: true Index: type: string xml: attribute: true example: "4"

    Explanation:

    • The <Header> element remains the same.
    • The <Fluss> element is represented by the Fluss property within the Header object. It is defined as an object type with a single property #text to represent the text value of the element.
    • The xml property under Fluss is set to wrapped: true, indicating that the Fluss element should be wrapped within the Header element.
    • The Index attribute is represented as a separate property outside of the Fluss object, directly under Header. It is defined as a string type and uses the xml property with attribute: true to indicate that it should be rendered as an attribute in the XML.

    With these adjustments, you should be able to render the desired XML structure in Swagger without encountering any errors.