Skip to content

Commit

Permalink
Merge pull request #3031 from danielsharvey/feature/example-support
Browse files Browse the repository at this point in the history
feat: Add schema support for "example" annotations
  • Loading branch information
kamilmysliwiec authored Sep 17, 2024
2 parents 00a6b80 + bd75d0a commit 391abb3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
10 changes: 10 additions & 0 deletions e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
"title": "Page",
"format": "int32",
"default": 0,
"example": 123,
"type": "number"
}
},
Expand All @@ -302,6 +303,10 @@
"in": "query",
"schema": {
"nullable": true,
"example": [
"sort1",
"sort2"
],
"type": "array",
"items": {
"type": "string"
Expand Down Expand Up @@ -490,6 +495,7 @@
"title": "Page",
"format": "int32",
"default": 0,
"example": 123,
"type": "number"
}
},
Expand All @@ -499,6 +505,10 @@
"required": true,
"schema": {
"nullable": true,
"example": [
"sort1",
"sort2"
],
"type": "array",
"items": {
"type": "string"
Expand Down
6 changes: 4 additions & 2 deletions e2e/src/cats/dto/pagination-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export class PaginationQuery {
exclusiveMaximum: true,
exclusiveMinimum: true,
format: 'int32',
default: 0
default: 0,
example: 123
})
page: number;

@ApiProperty({
name: '_sortBy',
nullable: true
nullable: true,
example: ['sort1', 'sort2']
})
sortBy: string[];

Expand Down
3 changes: 2 additions & 1 deletion lib/services/swagger-types-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export class SwaggerTypesMapper {
'format',
'pattern',
'nullable',
'default'
'default',
'example'
];
}
}
6 changes: 4 additions & 2 deletions test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export class PaginationQuery {
exclusiveMaximum: true,
exclusiveMinimum: true,
format: 'int32',
default: 0
default: 0,
example: 123
})
page: number;

@ApiProperty({
name: '_sortBy',
nullable: true
nullable: true,
example: ['sort1', 'sort2']
})
sortBy: string[];

Expand Down

0 comments on commit 391abb3

Please sign in to comment.