question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I tell Swagger to include extended or specific models?

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
kamilmysliwieccommented, Dec 3, 2019

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: [.......]
});
2reactions
elSuperRitoncommented, May 10, 2019

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Models (Schemas) - Swagger
OpenAPI 3.0 data types are based on an extended subset JSON Schema Specification ... To learn how to model various data types, see...
Read more >
Inheritance and Polymorphism - Swagger
OAS 3 This guide is for OpenAPI 3.0. Inheritance and Polymorphism. Model Composition. In your API, you may have model schemas that share...
Read more >
Configuration - Swagger Documentation
The default expansion depth for models (set to -1 completely hide the models). Number=1 . The default expansion depth for the model on...
Read more >
Using $ref - Swagger
Check this list for example values of a JSON reference in specific cases: Local Reference – $ref: '#/definitions/myElement' # means go to the...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Models are defined using the Schema Object, which is an extended subset of JSON Schema Specification Wright Draft 00. Primitives have an optional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found