ApiModelProperty always sets required:true when custom type provided
See original GitHub issueWhen you define something like this:
@ApiModelProperty({required: false, type: MyCustomModel})
myProperty: MyCustomModel;
the swagger will always result this property as required: true it’s only for custom models, works ok for all other types
I did quick debugging and it’s simple to fix problem is in line 101 inside api-parameters.explorer.ts file https://github.com/nestjs/swagger/blob/master/lib/explorers/api-parameters.explorer.ts#L101
return { name: key, $ref };
should be:
return { ...metadata, name: key, $ref };
hope you can include this quick fix on next update
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
java - Swagger not scanning ApiModel and ApiModelProperty ...
I found the solution. It turned out to be a class loading issue. I had an ear library that I was using to...
Read more >Setting Example and Description with Swagger - Baeldung
The @ApiModelProperty annotation defines the properties of the fields. We used this annotation on each field to set its notes (description), ...
Read more >io.swagger.annotations.ApiModelProperty Java Examples
ALWAYS ) public Boolean isBoolItem() { return boolItem; }. Example #2 ... @return uuid **/ @ApiModelProperty(required = true, value = "Object UUID.
Read more >Spring Rest API with Swagger – Creating documentation
Tutorial on how to create API documentation using Swagger in Spring application.
Read more >ApiModelProperty (swagger-annotations 1.5.0 API)
Limits the acceptable values for this parameter. There are three ways to describe the allowable values: To set a list of values, provide...
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
You should use
@ApiModelPropertyOptional()
Thanks for looking into the issue. Unfortunately the fix doesn’t work properly and Custom Object Models are still always shown as “Required” (marked with a red star) in the SwaggerUI. I checked the commits on master and apparently you changed the code to the suggestion which was provided - so maybe this suggestion isnt correct?
All three attributes are still shown as “required”.