[BUG][typescript-angular] All properties generated with "?:" even when they are not optional
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
Description
All properties generated by the openapi-generator are defined with ?: e.g.
/**
* Gets or sets the angle of reflection.
*/
angle?: number;
expected:
/**
* Gets or sets the angle of reflection.
*/
angle: number;
openapi-generator version
4.3.1
OpenAPI declaration file content or url
https://gist.github.com/Dunkhan/604694e5ae47c1162f784f1d3f3a78b9
Generation Details
npx openapi-generator generate -i D:\Work\testApi.json -g typescript-angular -c ./generate.api.options.json -o dist/api
generate options:
{
"npmName": "my-api",
"ngVersion": "9.1.0",
"fileNaming": "kebab-case",
"apiModulePrefix": "myPrefix"
}
Steps to reproduce
Run the command Look in the file \dist\api\model\effect-angle-values.ts
Related issues/PRs
none found
Suggest a fix
I am fully aware I might be doing something wrong, missing a flag, or reporting an intended behaviour. Please help me out if this is the case by explaining how I can get the generator to generate without the ?
I tried the flag nullSafeAdditionalProps but I found that this simply added “| null” to all nullable properties. This is good and I intend to keep using it but it does not solve the problem.
The reason this is an issue is that it I wish to use strict type checking and the properties being potentially undefined means that I have to fill all my code with undefined checks. These properties should never be undefined.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:12 (2 by maintainers)
Top GitHub Comments
I ended up adding this scema:
For many of us “nullable” mostly equals to “optional”, because it’s really exotic scenario when we want to get parameter explicitly set to “null” value. On the other hand, even more exotic scenario is non-nullable optional properties. Why would you expect to get non-nullable property set?
Maybe there can be a generator option something like ''treatNonNullablePropertiesAsOptional"? which will generate non-nullable non-optional fields for non-nullable properties and nullable-and-optional fields for nullable properties?