From 58ec36a1ed42308234bce0b1a1312f49af738318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rein=C3=B3n=20Garc=C3=ADa?= <67071425+dreinon@users.noreply.github.com> Date: Sun, 1 Jun 2025 17:36:22 +0200 Subject: [PATCH] fix: adapt Schema to REST API specifications --- src/types/common.ts | 77 +++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/src/types/common.ts b/src/types/common.ts index 897b5004..97b4b4d2 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -16,51 +16,68 @@ */ /** This file contains interfaces that are usable in the types folder. */ - /** * The list of OpenAPI data types * as defined by https://swagger.io/docs/specification/data-models/data-types/ */ export enum SchemaType { - /** String type. */ - STRING = 'STRING', - /** Number type. */ - NUMBER = 'NUMBER', - /** Integer type. */ - INTEGER = 'INTEGER', - /** Boolean type. */ - BOOLEAN = 'BOOLEAN', - /** Array type. */ - ARRAY = 'ARRAY', - /** Object type. */ - OBJECT = 'OBJECT', + /** String type. */ + STRING = "STRING", + /** Number type. */ + NUMBER = "NUMBER", + /** Integer type. */ + INTEGER = "INTEGER", + /** Boolean type. */ + BOOLEAN = "BOOLEAN", + /** Array type. */ + ARRAY = "ARRAY", + /** Object type. */ + OBJECT = "OBJECT" } +// Helper type to map SchemaType to its corresponding value type +type SchemaValueByType = + T extends SchemaType.STRING ? string : + T extends SchemaType.NUMBER ? number : + T extends SchemaType.INTEGER ? number : + T extends SchemaType.BOOLEAN ? boolean : + T extends SchemaType.ARRAY ? unknown[] : + T extends SchemaType.OBJECT ? Record : + unknown; + /** * Schema is used to define the format of input/output data. * Represents a select subset of an OpenAPI 3.0 schema object. * More fields may be added in the future as needed. */ -export interface Schema { - /** - * Optional. The type of the property. {@link - * SchemaType}. - */ - type?: SchemaType; - /** Optional. The format of the property. */ +export type Schema = { + type?: T; format?: string; - /** Optional. The description of the property. */ + title?: string; description?: string; - /** Optional. Whether the property is nullable. */ nullable?: boolean; - /** Optional. The items of the property. {@link Schema} */ + default?: SchemaValueByType; // ahora depende del tipo + example?: SchemaValueByType; // tambiƩn depende del tipo items?: Schema; - /** Optional. The enum of the property. */ + minItems?: string; + maxItems?: string; enum?: string[]; - /** Optional. Map of {@link Schema}. */ - properties?: {[k: string]: Schema}; - /** Optional. Array of required property. */ + properties?: { + [key: string]: Schema; + }; + propertyOrdering?: string[]; required?: string[]; - /** Optional. The example of the property. */ - example?: unknown; -} + minProperties?: string; + maxProperties?: string; + minimum?: number; + maximum?: number; + minLength?: string; + maxLength?: string; + pattern?: string; + anyOf?: Schema[]; + additionalProperties?: boolean | Schema; + ref?: string; + defs?: { + [key: string]: Schema; + }; +};