cancel
Showing results for 
Search instead for 
Did you mean: 

How to documente this array

Highlighted
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
Highlighted
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.


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Highlighted
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:
Announcements
Top Kudoed Authors