Skip to content

Commit

Permalink
docu(@nestjs/swagger) Describe @ApiSchema decorator
Browse files Browse the repository at this point in the history
Types and Parameters page has been enriched with information about @ApiSchema decorator.
The page has been renamed to Model schema in the menu.
  • Loading branch information
Stefan Radacovsky committed Nov 6, 2020
1 parent c3f6805 commit b8d782c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions content/openapi/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ All of the available OpenAPI decorators have an `Api` prefix to distinguish them
| `@ApiProperty()` | Model |
| `@ApiPropertyOptional()` | Model |
| `@ApiHideProperty()` | Model |
| `@ApiSchema()` | Model |
| `@ApiExtension()` | Method |
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,15 @@ pets: Pet[];
> info **Hint** The `getSchemaPath()` function is imported from `@nestjs/swagger`.

Both `Cat` and `Dog` must be defined as extra models using the `@ApiExtraModels()` decorator (at the class-level).

### Schema

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.

For example:
```typescript
@ApiSchema({ name: 'CreateCatRequest' })
class CreateCatDto {}
```

The above model will translate into schema with name `CreateCatRequest`.
4 changes: 2 additions & 2 deletions src/app/homepage/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export class MenuComponent implements OnInit {
children: [
{ title: 'Introduction', path: '/openapi/introduction' },
{
title: 'Types and Parameters',
path: '/openapi/types-and-parameters',
title: 'Model schema',
path: '/openapi/model-schema',
},
{ title: 'Operations', path: '/openapi/operations' },
{ title: 'Security', path: '/openapi/security' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
import { BasePageComponent } from '../../page/page.component';

@Component({
selector: 'app-openapi-types-parameters',
templateUrl: './types-and-parameters.component.html',
selector: 'app-openapi-model-schema',
templateUrl: './model-schema.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TypesAndParametersComponent extends BasePageComponent {}
export class ModelSchemaComponent extends BasePageComponent {}
14 changes: 10 additions & 4 deletions src/app/homepage/pages/openapi/openapi.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ import { OpenApiMigrationGuideComponent } from './migration-guide/migration-guid
import { OperationsComponent } from './operations/operations.component';
import { OpenApiOtherFeaturesComponent } from './other-features/other-features.component';
import { OpenApiSecurityComponent } from './security/security.component';
import { TypesAndParametersComponent } from './types-and-parameters/types-and-parameters.component';
import { ModelSchemaComponent } from './model-schema/model-schema.component';

const routes: Routes = [
{
path: 'introduction',
component: IntroductionComponent,
data: { title: 'OpenAPI (Swagger)' },
},
{
path: 'model-schema',
component: ModelSchemaComponent,
data: { title: 'Model Schema - OpenAPI' },
},
// Keep old route to not break existing bookmarks
{
path: 'types-and-parameters',
component: TypesAndParametersComponent,
data: { title: 'Types and Parameters - OpenAPI' },
component: ModelSchemaComponent,
data: { title: 'Model Schema - OpenAPI' },
},
{
path: 'operations',
Expand Down Expand Up @@ -63,7 +69,7 @@ const routes: Routes = [
@NgModule({
imports: [CommonModule, SharedModule, RouterModule.forChild(routes)],
declarations: [
TypesAndParametersComponent,
ModelSchemaComponent,
OpenApiMigrationGuideComponent,
OpenApiOtherFeaturesComponent,
OperationsComponent,
Expand Down

0 comments on commit b8d782c

Please sign in to comment.