From f3ac692c828c44557b6493676eec8d440d677562 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 19 Dec 2024 14:51:31 +0100 Subject: [PATCH] Fix default/required & additional properties in parameters --- src/utils.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 22cd771..148f277 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { normalize } from 'pathe' import type { HTTPMethod, LocalHook } from 'elysia' @@ -36,19 +34,33 @@ export const mapProperties = ( // object like schemas. return Object.entries(schema?.properties as Record ?? []).map(([key, value]) => { const { - type: valueType = undefined, description, + deprecated, + allowEmptyValue, + style, + explode, + allowReserved, + example, examples, - ...schemaKeywords + ...schemaVal } = value; + let required = schema!.required?.includes(key) ?? false; + if ("default" in schemaVal) required = false; + return { + name: key, + in: name, description, + required, + deprecated, + allowEmptyValue, + style, + explode, + allowReserved, + example, examples, - schema: { type: valueType, ...schemaKeywords }, - in: name, - name: key, - required: schema!.required?.includes(key) ?? false - } + schema: schemaVal, + } satisfies OpenAPIV3.ParameterObject; }) }