From bd75d0a9e4926f3a208ae2448aaf6eb97d11c7ee Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Sun, 4 Aug 2024 15:07:34 +0800 Subject: [PATCH] feat: Add schema support for "example" annotations --- e2e/api-spec.json | 10 ++++++++++ e2e/src/cats/dto/pagination-query.dto.ts | 6 ++++-- lib/services/swagger-types-mapper.ts | 3 ++- .../fixtures/project/cats/dto/pagination-query.dto.ts | 6 ++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/e2e/api-spec.json b/e2e/api-spec.json index a5d20add5..aba9cbc23 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -293,6 +293,7 @@ "title": "Page", "format": "int32", "default": 0, + "example": 123, "type": "number" } }, @@ -302,6 +303,10 @@ "in": "query", "schema": { "nullable": true, + "example": [ + "sort1", + "sort2" + ], "type": "array", "items": { "type": "string" @@ -490,6 +495,7 @@ "title": "Page", "format": "int32", "default": 0, + "example": 123, "type": "number" } }, @@ -499,6 +505,10 @@ "required": true, "schema": { "nullable": true, + "example": [ + "sort1", + "sort2" + ], "type": "array", "items": { "type": "string" diff --git a/e2e/src/cats/dto/pagination-query.dto.ts b/e2e/src/cats/dto/pagination-query.dto.ts index a837af958..91e3857ff 100644 --- a/e2e/src/cats/dto/pagination-query.dto.ts +++ b/e2e/src/cats/dto/pagination-query.dto.ts @@ -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[]; diff --git a/lib/services/swagger-types-mapper.ts b/lib/services/swagger-types-mapper.ts index 41abb12e2..7ea9e1d32 100644 --- a/lib/services/swagger-types-mapper.ts +++ b/lib/services/swagger-types-mapper.ts @@ -157,7 +157,8 @@ export class SwaggerTypesMapper { 'format', 'pattern', 'nullable', - 'default' + 'default', + 'example' ]; } } diff --git a/test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts b/test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts index 1572e8718..a6a179eee 100644 --- a/test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts +++ b/test/plugin/fixtures/project/cats/dto/pagination-query.dto.ts @@ -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[];