From 1d3100e52a475b5c25bf66256f30d4cc732818b6 Mon Sep 17 00:00:00 2001 From: Oliver Zheng Date: Mon, 23 Dec 2024 15:59:40 -0800 Subject: [PATCH] feat: Add schema support for array items Add support for `type` and `items` as a schema key, ensuring they work properly when used in parameter types. --- e2e/api-spec.json | 25 +++++++++++++++++++------ lib/services/swagger-types-mapper.ts | 6 +++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 9ec245529..9d167c03a 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -677,7 +677,8 @@ "title": "Page", "format": "int32", "default": 0, - "example": 123 + "example": 123, + "type": "number" } }, { @@ -689,7 +690,11 @@ "example": [ "sort1", "sort2" - ] + ], + "type": "array", + "items": { + "type": "string" + } } }, { @@ -736,7 +741,10 @@ "in": "query", "required": true, "schema": { - "type": "array" + "type": "array", + "items": { + "$ref": "#/components/schemas/LettersEnum" + } } }, { @@ -744,7 +752,10 @@ "in": "query", "required": true, "schema": { - "type": "array" + "type": "array", + "items": { + "$ref": "#/components/schemas/Letter" + } } }, { @@ -752,7 +763,8 @@ "in": "query", "required": true, "schema": { - "format": "date-time" + "format": "date-time", + "type": "string" } }, { @@ -768,7 +780,8 @@ "type": "number" } }, - "additionalProperties": true + "additionalProperties": true, + "type": "object" } }, { diff --git a/lib/services/swagger-types-mapper.ts b/lib/services/swagger-types-mapper.ts index dfe280da0..7baa280f3 100644 --- a/lib/services/swagger-types-mapper.ts +++ b/lib/services/swagger-types-mapper.ts @@ -16,12 +16,10 @@ type KeysToRemove = export class SwaggerTypesMapper { private readonly keysToRemove: Array = [ - 'type', 'isArray', 'enum', 'enumName', 'enumSchema', - 'items', '$ref', ...this.getSchemaOptionsKeys() ]; @@ -146,7 +144,9 @@ export class SwaggerTypesMapper { 'default', 'example', 'oneOf', - 'anyOf' + 'anyOf', + 'type', + 'items' ]; }