-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The TypeScript compiler option exactOptionalPropertyTypes prevents an object property from being assigned an undefined value unless this is specifically indicated in the property type declaration. For example, in an interface declared like:
export interface Example {
attr1?: string | null;
}it is legal to omit attr1 from an object, but illegal to set its value to undefined. The interface must instead be declared like:
export interface Example {
attr1?: string | null | undefined;
}The generator currently declares optional attributes without including the undefined value, which generates errors when this flag is set in the TypeScript compiler.
openapi-generator version
7.16.0
Probably no regression
OpenAPI declaration file content or url
This occurs on any API definition with optional properties. See below for reproduction steps.
Generation Details
Steps to reproduce
- modify samples/client/petstore/typescript-axios/builds/with-complex-headers/tsconfig.json and add
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,to the compilerOptions
- run ./bin/ts-typecheck-all.sh
Related issues/PRs
Suggest a fix
Update templates to produce | undefined type values