Skip to content

Commit 0a66d99

Browse files
committed
fix(schema_generator): add nullable type generation handling, fix ts strictNullChecks related model generation error
1 parent 5eb92e9 commit 0a66d99

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/create_freestyle_fetch/src/schema_generator.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ export class SchemaGenerator {
140140
return parts.join(' & ')
141141
}
142142

143+
// Handle nullable types (e.g. type: ['string', 'null'])
144+
if (Array.isArray(schema.type)) {
145+
const nonNullTypes = schema.type.filter((t) => t !== 'null')
146+
if (nonNullTypes.length === 1) {
147+
const innerSchema = {
148+
...schema,
149+
type: nonNullTypes[0],
150+
} as OpenAPIV3_1.SchemaObject
151+
return `${this.mapSchemaObjectToType(name, innerSchema)} | null`
152+
}
153+
return 'any'
154+
}
155+
143156
switch (schema.type) {
144157
case 'string':
145158
if (schema.enum)
@@ -173,7 +186,7 @@ export class SchemaGenerator {
173186
value
174187
)
175188
props.push(
176-
` '${key}'${isRequired ? '' : '?'}: ${typeStr};`
189+
` '${key}'${isRequired ? '' : '?'}: ${typeStr}${isRequired ? '' : ' | undefined'};`
177190
)
178191
}
179192
)

0 commit comments

Comments
 (0)