ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

Nullable in schema produces Prop?: null | <T>

Open Lonli-Lokli opened this issue 4 years ago • 3 comments

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

Lonli-Lokli avatar Apr 14 '21 22:04 Lonli-Lokli

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 avatar Jun 14 '21 11:06 luisfpg

@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.

Lonli-Lokli avatar Jun 14 '21 13:06 Lonli-Lokli