Skip to content

Commit b8d782c

Browse files
author
Stefan Radacovsky
committed
docu(@nestjs/swagger) Describe @ApiSchema decorator
Types and Parameters page has been enriched with information about @ApiSchema decorator. The page has been renamed to Model schema in the menu.
1 parent c3f6805 commit b8d782c

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

content/openapi/decorators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ All of the available OpenAPI decorators have an `Api` prefix to distinguish them
2222
| `@ApiProperty()` | Model |
2323
| `@ApiPropertyOptional()` | Model |
2424
| `@ApiHideProperty()` | Model |
25+
| `@ApiSchema()` | Model |
2526
| `@ApiExtension()` | Method |

content/openapi/types-and-parameters.md renamed to content/openapi/model-schema.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,15 @@ pets: Pet[];
288288
> info **Hint** The `getSchemaPath()` function is imported from `@nestjs/swagger`.
289289

290290
Both `Cat` and `Dog` must be defined as extra models using the `@ApiExtraModels()` decorator (at the class-level).
291+
292+
### Schema
293+
294+
As you might have noticed the name of the generated model schema matches the name of the model class e.g. `CreateCatDto` will generate `CreateCatDto` schema. If you want to change the generated schema name then use `@ApiSchema()` decorator.
295+
296+
For example:
297+
```typescript
298+
@ApiSchema({ name: 'CreateCatRequest' })
299+
class CreateCatDto {}
300+
```
301+
302+
The above model will translate into schema with name `CreateCatRequest`.

src/app/homepage/menu/menu.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ export class MenuComponent implements OnInit {
181181
children: [
182182
{ title: 'Introduction', path: '/openapi/introduction' },
183183
{
184-
title: 'Types and Parameters',
185-
path: '/openapi/types-and-parameters',
184+
title: 'Model schema',
185+
path: '/openapi/model-schema',
186186
},
187187
{ title: 'Operations', path: '/openapi/operations' },
188188
{ title: 'Security', path: '/openapi/security' },
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
22
import { BasePageComponent } from '../../page/page.component';
33

44
@Component({
5-
selector: 'app-openapi-types-parameters',
6-
templateUrl: './types-and-parameters.component.html',
5+
selector: 'app-openapi-model-schema',
6+
templateUrl: './model-schema.component.html',
77
changeDetection: ChangeDetectionStrategy.OnPush,
88
})
9-
export class TypesAndParametersComponent extends BasePageComponent {}
9+
export class ModelSchemaComponent extends BasePageComponent {}

src/app/homepage/pages/openapi/openapi.module.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ import { OpenApiMigrationGuideComponent } from './migration-guide/migration-guid
1010
import { OperationsComponent } from './operations/operations.component';
1111
import { OpenApiOtherFeaturesComponent } from './other-features/other-features.component';
1212
import { OpenApiSecurityComponent } from './security/security.component';
13-
import { TypesAndParametersComponent } from './types-and-parameters/types-and-parameters.component';
13+
import { ModelSchemaComponent } from './model-schema/model-schema.component';
1414

1515
const routes: Routes = [
1616
{
1717
path: 'introduction',
1818
component: IntroductionComponent,
1919
data: { title: 'OpenAPI (Swagger)' },
2020
},
21+
{
22+
path: 'model-schema',
23+
component: ModelSchemaComponent,
24+
data: { title: 'Model Schema - OpenAPI' },
25+
},
26+
// Keep old route to not break existing bookmarks
2127
{
2228
path: 'types-and-parameters',
23-
component: TypesAndParametersComponent,
24-
data: { title: 'Types and Parameters - OpenAPI' },
29+
component: ModelSchemaComponent,
30+
data: { title: 'Model Schema - OpenAPI' },
2531
},
2632
{
2733
path: 'operations',
@@ -63,7 +69,7 @@ const routes: Routes = [
6369
@NgModule({
6470
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
6571
declarations: [
66-
TypesAndParametersComponent,
72+
ModelSchemaComponent,
6773
OpenApiMigrationGuideComponent,
6874
OpenApiOtherFeaturesComponent,
6975
OperationsComponent,

0 commit comments

Comments
 (0)