-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Description
The handling of the nullable flag in swagger-typescript seems to be incorrect or misleading. Currently, when a property in the Swagger/OpenAPI JSON does not define a nullable field, the generator assumes nullable: true.
This leads to incorrect TypeScript typings, especially in the context of:
POST requests where some properties are required but nullable is not explicitly set.
GET requests where some properties are truly nullable or optional.
According to the OpenAPI specification, the nullable flag must be explicitly declared as true for a field to accept null values.
Expected Behavior
If nullable is not defined in the Swagger JSON, it should not be assumed to be true by default.
Instead, the generator should:
-
Respect nullable: true | false only when it is defined.
-
Allow configuration for what to assume when it is not defined.
Suggested Solution
Introduce a new configuration option: defaultNullable in the package config file.
Example usage:
In swagger.config.json file:
{
url: 'https://www.example.com',
dir: './services',
reactHooks: true,
defaultNullable: false, // or true if the user prefers
};
This way, users can control the fallback behavior while still fully supporting the OpenAPI spec.