[ ] 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.
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?
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.
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?
I have an abstract class and send in subclasses to a method that takes a variety of subclasses.
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:
+1
any progress on this maybe?
One way to work around this would be to use the OpenAPI specification >= v3.0.
There are the keywords oneOf, anyOf, allOf (see https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/).
The subclasses could be listed with oneOf.
But I Think currently nestjs/swagger only supports OpenAPI Specification v2 (fka Swagger).
I also have the exact same motivation as described, would love to see this implemented. This issue seems related to #43.
I believe this is now handled in the next version using ApiExtraModels()?
Correct @loban.
This is available in 4.0.0 https://docs.nestjs.com/recipes/swagger#extra-models
Instead of using @ApiExtraModels, you can also pass extraModels array as a part of SwaggerDocumentOptions
SwaggerModule.createDocument(app, config, {
extraModels: [.......]
});
Most helpful comment
Correct @loban.
This is available in 4.0.0 https://docs.nestjs.com/recipes/swagger#extra-models
Instead of using
@ApiExtraModels, you can also passextraModelsarray as a part ofSwaggerDocumentOptions