Skip to content

Commit 54eadfe

Browse files
committed
🔧 fix: inconsistent ref string behavior
1 parent eb790a2 commit 54eadfe

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/utils.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export const mapProperties = (
5151
})
5252
}
5353

54+
const makeRefString = ($ref: string) => !$ref.startsWith('#/components/schemas/')
55+
? `#/components/schemas/${$ref}`
56+
: $ref
57+
5458
const mapTypesResponse = (
5559
types: string[],
5660
schema:
@@ -81,26 +85,14 @@ const mapTypesResponse = (
8185
schema[Kind] === 'Ref'
8286
? {
8387
...schema,
84-
$ref: `#/components/schemas/${schema.$ref}`
88+
$ref: makeRefString(schema.$ref)
8589
}
8690
: replaceSchemaType(
8791
{ ...(schema as any) },
8892
{
8993
from: t.Ref(''),
9094
// @ts-expect-error
91-
to: ({ $ref, ...options }) => {
92-
if (
93-
!$ref.startsWith(
94-
'#/components/schemas/'
95-
)
96-
)
97-
return t.Ref(
98-
`#/components/schemas/${$ref}`,
99-
options
100-
)
101-
102-
return t.Ref($ref, options)
103-
}
95+
to: ({ $ref, ...options }) => t.Ref(makeRefString($ref), options),
10496
}
10597
)
10698
}

0 commit comments

Comments
 (0)