openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

All properties are nullable, even though they are not defined as nullable in swagger file

Open itsoli91 opened this issue 1 year ago • 3 comments

Hi thank you for grate library. I have one problem, all properties are nullable, even though they are not defined as nullable in swagger file.


"LoginResponse": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "accessToken": {
            "type": "string"
          },
          "refreshToken": {
            "type": "string",
            "nullable": true
          },
          "expireIn": {
            "type": "integer",
            "format": "int32"
          },
          "user": {
            "$ref": "#/components/schemas/DetailedUserDto"
          }
        }
      },

export type LoginResponse = {
    accessToken?: string;
    refreshToken?: string | null;
    expireIn?: number;
    user?: DetailedUserDto;
};

Am I doing something wrong ?

itsoli91 avatar Dec 24 '23 01:12 itsoli91

I'd like to see an option to disable the optional aspect of properties for generated models.

conorlawton avatar Feb 08 '24 15:02 conorlawton

In this case, openapi-typescript-codegen is following the schemas correctly. With such an override, openapi document would be describing different objects than the generated client.

Relevant docs: https://json-schema.org/understanding-json-schema/reference/object#required https://swagger.io/docs/specification/data-models/data-types/#object

tajnymag avatar Mar 02 '24 12:03 tajnymag

Thanks for clarifying @tajnymag

mrlubos avatar Mar 06 '24 18:03 mrlubos