cancel
Showing results for 
Search instead for 
Did you mean: 

How to documente this array

New Contributor

How to documente this array

Hi, 

 

I'm writing my API documentation to swagger.io and I have a problem. I don't know how to documente my array in yaml.

 

My array (it's JSON) :

 

{
	"quiz_id": "10",
	"api_ukey": "KYF210",
	"answers": { 
		"24": [35,37]
	}
}

Explication: 

 

The array "answers" have 2 level :

- Level 1:  key "24" : correspond to "question_id" 

- Level 2: [35,37] : correspond to a list of answers

 

I hope you understood me.

 

Thank you for your help.

 

++

2 REPLIES 2
Moderator

Re: How to documente this array

Hello,

 

The OpenAPI specification does not allow you to add constaints to arbitrarily defined keys. To describe 'answers' you can go with:

 

  answers:
    type: object
    additionalProperties:
      type: array
      items:
        type: integer

The definition about says that 'answers' is an object that can have any key, and the value of that key must be an array of integers.

New Contributor

Re: How to documente this array

Ok I see. 

 

I think it's not that.. I found an alternative like :

 

answers:
                type: object
                description: La clé "question_id" du tableau correspond à l'ID de la question.
                properties:
                  question_id: 
                    type: array
                    items: 
                      type: string
                      example: 15,20

Thank you.

New Here?
Join us and watch the welcome video:
SeptemberNews
Join our online event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win