cancel
Showing results for 
Search instead for 
Did you mean: 

Swagger Definition object default value

New Contributor

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"
   }
 }
} 

 

2 REPLIES 2
Moderator

Re: Swagger Definition object default value

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.


Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
Community Hero

Re: Swagger Definition object default value

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors