From 54eadfe074833669ed10ded14f294b904f34a0e6 Mon Sep 17 00:00:00 2001 From: recanman <29310982+recanman@users.noreply.github.com> Date: Tue, 5 Aug 2025 00:01:37 -0700 Subject: [PATCH] :wrench: fix: inconsistent ref string behavior --- src/utils.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 19f5170..6088351 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -51,6 +51,10 @@ export const mapProperties = ( }) } +const makeRefString = ($ref: string) => !$ref.startsWith('#/components/schemas/') + ? `#/components/schemas/${$ref}` + : $ref + const mapTypesResponse = ( types: string[], schema: @@ -81,26 +85,14 @@ const mapTypesResponse = ( schema[Kind] === 'Ref' ? { ...schema, - $ref: `#/components/schemas/${schema.$ref}` + $ref: makeRefString(schema.$ref) } : replaceSchemaType( { ...(schema as any) }, { from: t.Ref(''), // @ts-expect-error - to: ({ $ref, ...options }) => { - if ( - !$ref.startsWith( - '#/components/schemas/' - ) - ) - return t.Ref( - `#/components/schemas/${$ref}`, - options - ) - - return t.Ref($ref, options) - } + to: ({ $ref, ...options }) => t.Ref(makeRefString($ref), options), } ) }