Ideas Lab

Real problems people complain about online, pulled every morning and scored out of 100. Build, validate, or skip. How scoring works

Ideas
4,820
BUILD
702
Sources
8
Last sync
4h ago
210 ideas
Design & Creative

[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). Example component schema ```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 }, "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 } ```

GitHub2y agoToolDesign & Creative

65FL score
0Sign in to vote