Forum Discussion

libertyandco's avatar
libertyandco
New Contributor
5 years ago

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

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

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