Skip to content

Commit 4e3aa19

Browse files
committed
feat: support for enums outside of component schemas
1 parent 863e0e0 commit 4e3aa19

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/process-schema.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ export function schemaToType(
188188
};
189189
}
190190

191+
if (schemaObject.type === 'string' && 'enum' in schemaObject) {
192+
return {
193+
name,
194+
hasQuestionToken,
195+
196+
type:
197+
schemaObject.enum.length === 1
198+
? JSON.stringify(schemaObject.enum[0])
199+
: Writers.unionType(
200+
// @ts-expect-error
201+
...schemaObject.enum.map((e) => JSON.stringify(e)),
202+
),
203+
};
204+
}
205+
191206
const type =
192207
schemaObject.type === 'string' && schemaObject.format?.includes('date')
193208
? 'Date'

0 commit comments

Comments
 (0)