-
Notifications
You must be signed in to change notification settings - Fork 292
Description
Kiota ignores the usage of required/nullable in OAS schemas. C# properties are always generated as nullable. This results in unneeded noisy squiggles, as shown here.
NSwag does a better job, by performing the following translation (using the /GenerateNullableReferenceTypes:true switch):
- OAS non-required + nullable: C# nullable
- OAS required + nullable: C# nullable
- OAS non-required + non-nullable: C# non-nullable, unless combined with the
/GenerateOptionalPropertiesAsNullable:trueswitch - OAS required + non-nullable: C# non-nullable
Additionally, NSwag adds [Newtonsoft.Json.JsonProperty(Required = ..., , NullValueHandling = ...)] on the generated properties, which results in client-side serialization errors (thus avoiding a server roundtrip on invalid input).
Example component schema
"exampleComponent": {
"required": [
"requiredNonNullableReferenceType",
"requiredNullableReferenceType",
"requiredNullableValueType",
"requiredValueType"
],
"type": "object",
"properties": {
"nonNullableReferenceType": {
"type": "string"
},
"requiredNonNullableReferenceType": {
"type": "string"
},
"nullableReferenceType": {
"type": "string",
"nullable": true
},
"requiredNullableReferenceType": {
"type": "string",
"nullable": true
},
"valueType": {
"type": "integer",
"format": "int32"
},
"requiredValueType": {
"type": "integer",
"format": "int32"
},
"nullableValueType": {
"type": "integer",
"format": "int32",
"nullable": true
},
"requiredNullableValueType": {
"type": "integer",
"format": "int32",
"nullable": true
}
},
"additionalProperties": false
}The motivation for this behavior in Kiota is provided here and here. I find it unfortunate that correct server implementations have to suffer from this.
Please upvote this issue if you'd like Kiota to respect the required/nullable usage in your OAS.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status