Search code examples
swaggercdata

How to define <![CDATA[ ]]> attribute in swagger 2.0


I am working with Swagger to define my api definition. I have a comments that I need to define using swagger.


Solution

  • CDATA is not part of XML logical structure, it's just a way to indicate text containing special characters - in order to prevent such text from being interpreted as XML markup.

    Simply define CDATA's parent element as type: string, that's all. There's no need to indicate CDATA markers in any way. It's up to the server and clients to send an XML element's text as CDATA when necessary.

    For example

    <root>
      <elem><![CDATA[ ... ]]></elem>
    </root>
    

    is defined as:

    swagger: "2.0"
    ...
    
    definitions:
      root:
        type: object
        properties:
          elem:
            type: string