Question: does swagger spec support root nodes
See original GitHub issueHey there,
I am writing documentation for rails application. And I am struggling with root nodes in responses.
Here is the example to describe what I mean by that.
GET /orders/
# get all orders
{
"orders": [
{
"id": 28,
"customer_name": "Peter"
},
{
"id": 29,
"customer_name": "Tomas"
}
]
}
I came up with the workaround and so far I was creating artificial model Orders, that reference real model Order.
paths:
/orders:
get:
summary: Get all orders
description: Get All orders
responses:
'200':
description: An array of orders inside root node
schema:
type: object
$ref: '#/definitions/Orders'
definitions:
Orders:
type: object
required:
- orders
properties:
orders:
type: array
items:
$ref: '#/definitions/Order'
Order:
type: object
properties:
id:
type: integer
description: Unique identifier representing a specific order
customer_name:
type: string
description: The customer that the order is for
But I guess there has to be better way to do it. Because this is not the only endpoint (for instance /order/:id
has root node ‘order’ etc.). So I will have to have a lot of artificial models. So my question is.
How am I supposed to write specs for responses that contains root node?
Thank you for any ideas.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
OpenAPI Specification - Version 3.0.3 - Swagger
It is RECOMMENDED that the root OpenAPI document be named: openapi.json or openapi.yaml . Data Types. Primitive data types in the OAS are...
Read more >Include root element in Swagger JSON sample - Stack Overflow
I was facing the same issue with openApi swagger. I've fixed it by adding a OpenApiCustomiser :
Read more >Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
Swagger UI provides a display framework that reads an OpenAPI specification document and generates an interactive documentation website.
Read more >OpenAPI (Swagger) | NestJS - A progressive Node.js framework
The OpenAPI specification is a language-agnostic definition format used to describe RESTful APIs. Nest provides a dedicated module which allows generating ...
Read more >Accessing the Swagger Visualization Portal
Access the Swagger Visualization Portal on the API Catalog page. ... avoid a "Failed to load specification" error, rename the default root node...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This seems to fit in with #519. The ability to define a “collection” wrapper, which can be reused for various resources avoids creating bespoke ‘wrappers’ for each collection in a CRUD resource pattern.
That said, this example design is somewhat flawed from taking advantage from that type of approach…if
orders
wereitems
, this would be a reusable collection format.Really not sure what the question is, apologies. You are going to always want to describe your
Order
object. If it’s stuffed inside another object, you have two choices:Orders
holder, which has an array of typeorder
order
attribute points to theOrder
array: