Forum Discussion

blackwj's avatar
blackwj
New Contributor
6 years ago
Solved

Swagger Definition object default value

I'm building a swagger json definitiion for the below xml payload to use within the Swagger UI. Once complete I'll convert it to yaml and import the definition into Swagger UI. I'm having an issue figuring out how to display a default value 'Enter value here' for element 'key'. Where would one place this default value in the below json?

 

<addressElement>
    <key type="RECORD_ID" item="3">Enter value here</key>
</addressElement>

For the above xml, I have the below json definition. How can I add the value 'Enter value here' in the json to be shown as it is in the above xml?

 

"definitions": {
 "addressElement": {
   "type": "object",
   "title": "Address Element",
   "properties": {
     "key": {
       "type": "object",
       "properties": {
         "type":{
           "type": "string",
           "example": "RECORD_ID",
           "xml":{
             "attribute": true
           }
         },
         "item":{
           "type": "integer",
           "format": "int64",
           "example": "3",
           "xml":{
             "attribute": true
           }
         }
       }
     },
   },
   "xml": {
     "name": "addressElement"
   }
 }
} 

 

  • Hi blackwj,

     

    I'm afraid the OpenAPI Specification currently has no way to represent XML elements with attributes such as

    <elem attr="value">Some text</elem>

     

    Currently, attributes can only be defined for objects such as

    <obj attr="value">
      <elem>Some text</elem>
    </obj>

    but not for simple <elem>text</elem> elements.

     

    There's an open issue about this limitation in the OpenAPI Specification repository:

    How to represent XML elements with attributes

     

    OpenAPI Specification maintainers are considering an option to use alternative data modeling schemas (for example, XSD Schema), so your use case might be supported in a future version of OpenAPI.

2 Replies