[Multiple languages] properties are generated as nullable/optional, despite required/nullable usage in OAS schema
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](https://github.com/microsoft/kiota/issues/3846#issuecomment-1844249797). 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:true` switch - 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). <details> <summary>Example component schema</summary> ```json "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
Posted by bkoelman on Dec 14, 2023, 11:04 AM
Tags
Related issues
- Custom games stuck on "finding server" for all european servers
- Feature request: add ACP (Agent Client Protocol) stdio JSON-RPC mode
- Forza Horizon 6 (2483190)
- Turn off integrated browser for default
- Weekly updates are too frequent
- [BUG] Max 20x plan: 100% usage after 2 hours of light work (5 commits, no agents)
Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments
github (Sysadmin)
Custom games stuck on "finding server" for all european servers
Feature request: add ACP (Agent Client Protocol) stdio JSON-RPC mode
Forza Horizon 6 (2483190)
Turn off integrated browser for default
Weekly updates are too frequent
[BUG] Max 20x plan: 100% usage after 2 hours of light work (5 commits, no agents)
Add gemini-3.1-pro-preview
[TF2] Feature request: Bring Back Quickplay
[Multiple languages] properties are generated as nullable/optional, despite required/nullable usage in OAS schema
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](https://github.com/microsoft/kiota/issues/3846#issuecomment-1844249797). 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:true` switch - 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). <details> <summary>Example component schema</summary> ```json "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
Comments (0)
No comments yet. Start the discussion.