How can I parameterize the url for POST using Swagger?
I would like to define the following path using Swagger :
/api/libraries/1234/books
And a POST
book in the library of books of the library, the identifier of which 1234
.
In the example I saw here: https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-with-external-docs.json
It shows that you can specify, for example:, libraries/{id}/books
but you must define it as a separate path object.
For example, comparison with libraries
for purposes GET
; which will bring you a list of libraries.
Is there a way to define an object sub path
(for example: under
libraries
define a sub path
of id
), and below it a sub path
of books
; and perhaps more sub path
employees
?
source to share
The short answer is no.
Nesting paths are not supported by the swagger 2.0 specification; you must define the paths yourself ( https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathItemObject ).
Then you can group the list of resources using tags .
The reason for having atomic paths is because the swagger is very much in line with the REST specs. REST resources are associated with independent atomic operations (as opposed to SOAP / RPC).
source to share
Not sure if I understood your question correctly, but if you want to specify path variables for as an example /api/libraries/1234/books/5678/employees/9999
, the path should look like this:
/api/libraries/{library_id}/books/{book_id}/employees/{employe_id}
in which {library_id}
, {book_id}
and {employee_id}
are path variables.
source to share