Description
I want to open that feature request to recap some features\PR I see in the project.
I would understand the behavior with required and nullable options and nullable value types in the models codegen.
Moving from Swagger I have a breaking change I want to understand.
In Swagger we have that all the value type fields of a model are nullable, here not.
I see in the migration guideline a few informations about nullables.
example
The specification:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
age:
type: integer
owner:
type: string
Here the Swagger version:
public class Pet
{
public long? Id {get; set; }
public string Name {get; set; }
public long? Age {get; set; }
public string Owner {get; set; }
}
In this version everything is nullable to better specify a default value when data is missing in serialization\deserialization. It's useful, but having required, validated fields managed always as nullable is not so much good.
Here the OpenApi version:
public class Pet
{
public long Id {get; set; }
public string Name {get; set; }
public long Age {get; set; }
public string Owner {get; set; }
}
In this version it's difficult to manage not required fields, when the default value is available or not? You cannot know it.
Here my expected version:
public class Pet
{
public long Id {get; set; }
public string Name {get; set; }
public long? Age {get; set; }
public string Owner {get; set; }
}
Here the not required value type Age is proposed as nullable, the required Id not.
Must I change the specification generating supporting definitions such x-nullable?
I understand the difference between required and nullable, they have different meanings, but in C# an optional value type seems right to be managed as nullable.
Here past issues involved:
- Fixed valuetype parameters and discriminator deserialization: fix made after the csharp-netcore branching
Here open issues involved: - x-csharp-value-type doesn't help to generate nullable type
- Not possible to generate nullable enum in an API model
- Add option for nullable reference types
Thank you all.
People involved: @Blackclaws @devhl-labs @DavidJeppesen-Seges