Using API model property with an array of types does not display correctly
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Using API model property with an array of types does not display correctly
Expected behavior
An array of the object with the properties listed
Minimal reproduction of the problem with instructions
@TreeChildren()
@ApiModelProperty({
description: 'Array of Child Conversations.',
isArray: true,
type: [Conversation],
})
@Field(/* istanbul ignore next */ _ => [Conversation])
public children?: Conversation[];
What is the motivation / use case for changing the behavior?
Environment
Nest version: 7.1.5
For Tooling issues:
- Node version: 12.13.0
- Platform: Mac
Others:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to describe a model in Swagger for an array with simple ...
The array is composed of 'stackoverflow' items. Each item is an object, that has name property. This is the correct answer. The key...
Read more >How to model an array of different types of object
Hi,. I have a use case where I want to describe using Swagger 2.0 a callback API. This API will POST an array...
Read more >Types and Parameters - OpenAPI - Documentation | NestJS
When the property is an array, we must manually indicate the array type ... SwaggerModule may not be able to properly generate model...
Read more >Data Types - Swagger
OAS 3 This guide is for OpenAPI 3.0. Data Types. The data type of a schema is defined by the type keyword, for...
Read more >How to Use the Fetch API (Correctly) - CODE Magazine
If you have everything installed correctly, you should get an array of JSON product objects displayed in the browser. Leave the Web API...
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
For anyone who is trying to generate schema of array property in dto, here is the solution.
This will automatically generate
AnotherClass
Schema.I can’t get it to work, even with @iambpn’s suggested solution. Here’s my endpoint:
I’d like
CatInput
to be properly rendered in Swagger It contains an array of objects calledinfos
:I’m using the nest swagger plugin. Here’re some of the options I tried:
Swagger UI does not allows me to input multiple infos. Even the single one I provide is sent wrong, missing the name of the
infos
field.ApiProperty
decorator as suggested by @iambpnI get exactly the same result as before. I cannot provide multiple infos.
ApiProperty
Starts to look good. However, when I try to add an item:
Something is clearly wrong there, the swagger JSON is:
The specification is definitely wrong. Where does it take the
type: "a"
from?Am I missing something? @kamilmysliwiec, let me know if I should create a new issue for this, this one seemed very similar to mine.