You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
transform(schemaObject){// Treat optional AND nullable fields as just optional (possibly undefined)if(!schemaObject.required&&schemaObject.nullable){schemaObject.nullable=false;}},
with v6 I was getting the following:
foo?: components["schemas"]["Bar"];
but with v7 I'm now getting:
foo?: components["schemas"]["Bar"]|null;
Is this expected behavior? What can I do to make v7 work like v6 did here? The logic appears to still work for primitive type fields, but no longer for object refs.
Name
Version
openapi-typescript
7.0.2
Node.js
20.15.1
OS + version
Windows 11
Checklist
My OpenAPI schema passes the Redocly validator (npx @redocly/cli@latest lint)
transform(schemaObject){// Treat optional AND nullable fields as just optional (possibly undefined)if(!schemaObject.required&&schemaObject.nullable){schemaObject.nullable=false;}},
with v6 I was getting the following:
foo?: components["schemas"]["Bar"];
but with v7 I'm now getting:
foo?: components["schemas"]["Bar"]|null;
Is this expected behavior? What can I do to make v7 work like v6 did here? The logic appears to still work for primitive type fields, but no longer for object refs.
Name Version openapi-typescript7.0.2
Node.js 20.15.1
OS + version Windows 11 Checklist
My OpenAPI schema passes the Redocly validator (npx @redocly/cli@latest lint)
In V7, the transform operates after the type generation, so attempting to change schemaObject directly will not take effect. but, you can use the following method to modify the type, I think it's very flexible:
importtransformSchemaObjectfrom'openapi-typescript/dist/transform/schema-object.ts'functiontransform(schemaObject,options){// Treat optional AND nullable fields as just optional (possibly undefined)if(!schemaObject.required&&schemaObject.nullable){schemaObject.nullable=false;return{schema: transformSchemaObject(schemaObject,options),questionToken: true}}}
Thanks a lot! Would not have figured that out myself, don't see that function (nor the odd import) in the docs. Setting questionToken to true broke other things (foo?: string became foo?: string | undefined) but the following worked:
Description
Hello! When my OpenAPI v3.0 spec has something like this:
And my transform is this:
with v6 I was getting the following:
but with v7 I'm now getting:
Is this expected behavior? What can I do to make v7 work like v6 did here? The logic appears to still work for primitive type fields, but no longer for object refs.
openapi-typescript
7.0.2
20.15.1
Windows 11
Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: