Required value types should not be nullable if they are required
Required query parameter still convert to nullable type:
{
"name": "timeout",
"in": "query",
"required": true,
"type": "integer",
"format": "int32",
},
The generated C# code:
int? timeout,
caused by CodeNamer.NormalizeType function.
It would be great to see this fixed. Let me know if I can help.
@xingwu1 and @stankovski where did we land on this in our last conversation?
All parameters are validated during the runtime, so the issue here is about compile time validation. Since some data types in C# (such as strings or classes) can not be made non-nullable we will always end up with a mix of compile time and runtime validation. Our decision to have all parameters as nullable has simplified the code generation logic significatly, as such unless there is a strong case for adding non-nullable primitives back I would recommend against it.
@devigned please re-open if you want to persue this change
@devigned @stankovski Just to clarify, are we only talking about parameters here, or properties too? I would love for my customers to not have to worry about nullability of model properties in situations where it doesn't make sense.
As a matter of principle, we should make decisions based on what's best for the developer experience and not ease of implementation.
Totally agree @brjohnstmsft, actually compare to validation of assignment of required primitive type, I think the accurate of model properties type is more important.
@xingwu1 Exactly -- I don't actually need the generated code to validate model properties, since the REST API already does this.