2

We got an existing webservice that we attempt to document using Swagger. It often seems to return objects using:

schema:
    type: array
    items:
       $ref: '#/definitions/Tweets'

In this model the id of the tweet is in the Tweets definition. My returned output is formatted like this:

{  
   "127":{  
      "name":"Foo"
   },
   "110":{  
      "name":"Bar"
   }
}

Where the id is the key of the object. How do i do this is in Swagger?

1 Answer 1

2

You should use additionalProperties (Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#model-with-mapdictionary-properties)

Here is an example:

type: object
additionalProperties:
  $ref: '#/definitions/Tweets'

where Tweets has a property name

Sign up to request clarification or add additional context in comments.

1 Comment

Just for clarification, the additionalProperties attribute basically means, there are additional properties in this object, not defined in properties and they have the defined schema....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.