Apidoc: Request body with array

Created on 11 Nov 2016  路  7Comments  路  Source: apidoc/apidoc

Hi!

How would I document this?

POST /batch-insert
[
  { "name": "Name 1" },
  { "name": "Name 2" }
]

I understand that @apiParam can be used to document request body, but @apiParam {String[]} name implied { "name": ["Name 1", "Name 2"] } I think.

enhancement

Most helpful comment

@kok-ng What you are describing is a different API. The documentation you defined would describe a request of:

{
    names: [{ "name": "Name 1" }, { "name": "Name 2" }] 
}

But what (I believe) @Znarkus was asking for, and what I'm looking for also, is how to document an API that expects:

 [{ "name": "Name 1" }, { "name": "Name 2" }]

P.S. This is particularly relevant if you're using the APIDoc feature where you have it generate forms for each endpoint. Currently it is impossible to get APIDoc to generate a form for an endpoint unless that endpoint takes named parameters (ie. takes an object, not an array).

All 7 comments

I feel your pain.
While a solution is not implemented I use an underscore:
* @apiParam {Object[]} _ array of objects with:

It keeps the api legible enough...

hey @dfreire what does the _ do?

Nothing. It is just a placeholder that is easy to read on the documentation output.

Hi,
If you use something like

 * @apiParam {Object[]} [names] A serie of names
 * @apiParam {Object} [names.name] A name

It outputs a quite clear and indented doc, however it's not sending it correctly with apiSampleUrl.

@kok-ng What you are describing is a different API. The documentation you defined would describe a request of:

{
    names: [{ "name": "Name 1" }, { "name": "Name 2" }] 
}

But what (I believe) @Znarkus was asking for, and what I'm looking for also, is how to document an API that expects:

 [{ "name": "Name 1" }, { "name": "Name 2" }]

P.S. This is particularly relevant if you're using the APIDoc feature where you have it generate forms for each endpoint. Currently it is impossible to get APIDoc to generate a form for an endpoint unless that endpoint takes named parameters (ie. takes an object, not an array).

Any update on this one?

@fedemengo No, but you're welcome to contribute! ;)

Recently a lot of work has been put in reducing the number of open PR/issues. This issue will be addressed eventually. Right now issues that are not bugs have a lower priority.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kingmayko picture kingmayko  路  3Comments

a-tonchev picture a-tonchev  路  4Comments

brandonhamilton picture brandonhamilton  路  4Comments

yunlucolin picture yunlucolin  路  6Comments

YannDoW picture YannDoW  路  4Comments