How can I tell Swagger to include extended or specific models?
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
This might be similar to https://github.com/nestjs/swagger/issues/223. I have a web method something like doWork( expression: AbstractExpression). Swagger includes AbstractExpression in Models. I have several subclasses which extend AbstractExpression, like PropertyExpression, StringExpression, etc, just subclasses. When I call my web method I’m wanting to receive a subclass expression like StringExpression.
The problem is that swagger is not including the extended subclasses in the list of Models because they are not directly referenced. How can I tell nestjs/swagger to explicitly include these extra models?
Expected behavior
I would like to be able to explicitly tag a model or tell swagger to include it. Maybe a class decorator for @ApiModel added to the class could tell swagger to include the model.
Minimal reproduction of the problem with instructions
web method doWork( expression: AbstractExpression)
// included because its referenced
export class AbstractExpression {
@ApiModelProperty({ description: 'An Abstract class never used direclty.'})
public expressionType: ExpressionType;
}
@ApiModel() // this could tell swagger to include it in Models
export class PropertyExpression extends AbstractExpression {
@ApiModelProperty({ description: 'A subclass dto to pass web method.'})
public property: string;
}
*** Swagger will not include PropertyExpression in models. How can I manually add it?
What is the motivation / use case for changing the behavior?
I have an abstract class and send in subclasses to a method that takes a variety of subclasses.
Environment
Nest version: X.Y.Z
"@nestjs/core": "6.0.5",
"@nestjs/swagger": "3.0.2",
For Tooling issues:
- Node version: XX
- Platform:
node 10, macos
Others:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top GitHub Comments
Correct @loban.
This is available in 4.0.0 https://docs.nestjs.com/recipes/swagger#extra-models
Instead of using
@ApiExtraModels
, you can also passextraModels
array as a part ofSwaggerDocumentOptions
+1