ng-openapi-gen
ng-openapi-gen copied to clipboard
Nullable in schema produces Prop?: null | <T>
Following schema (from Swashbuckle.AspNetCore 5.6.3)
"OverallInherentRiskRating": {
"type": "string",
"nullable": true
},
produces this typing
OverallInherentRiskRating?: null | string;
which under strict flag is kind of difficult to fix as it becomes string | null | undefined.
Can it be treated as OverallInherentRiskRating?: string; ? At least with optional flag, I believe it's https://github.com/cyclosproject/ng-openapi-gen/blob/master/lib/property.ts#L25
I've tried to implement the generator as close as possible to the specification. And in that case, it is exactly what is being represented in the spec. You say it is hard to fix, but if you use:
const rating = {} as OverallInherentRiskRating;
if (rating.type) {
// Here, rating.type is neither null nor undefined
}
Wouldn't it solve it?
@luisfpg We do not use as in our code, it's not safe.
As I understand your idea here - property might be missing (as it's not required) eg undefined and might be null (as it has nullable = true).
Can this definition be merged into one undefined? Under flag.
It's not bug request, it's feature request.