c# validation nullable value
See original GitHub issueHi, We have a swagger spec with a value that is conditional/optional i.e. can be null with some validation constraints this is presented like so:
"totalThroughputMibps": {
"type": "number",
"x-nullable": true,
"description": "Total throughput of pool in Mibps",
"example": 164.221,
"readOnly": true,
"multipleOf": 0.001
}
This causes issues with c# generated SDK where the validation code does not allow null values.
public double? TotalThroughputMibps { get; private set; }
.
.
.
.
.
if (TotalThroughputMibps % 0.001 != 0)
{
throw new ValidationException(ValidationRules.MultipleOf, "TotalThroughputMibps", 0.001);
}
Is it possible to present this in the swagger so that the validation in the generated code handles null values correctly?
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
How to use Data Annotations to validate a nullable int
Show activity on this post. In an MVC 5 project, I have a model with a nullable int. For reasons that might not...
Read more >Required Attribute on nullable ValueTypes - MSDN - Microsoft
and when I pass this JSON value to the ApiController I get the following error: JSON Value: var jsData = { ID: null,...
Read more >C# Futures: Simplified Parameter Null Validation - InfoQ
It is redundant with the declaration that the parameter is non-nullable. Another issue is that value! would mean either “please check this for ......
Read more >C#: Different ways to Check for Null - Thomas Claudius Huber
The compiler explained to me that I am trying to do a null check against a non-nullable value type. By attempting this, I...
Read more >Built-in Validators — FluentValidation documentation
Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, e.g., 0 for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As to the original issue in this thread, I believe it’s fixed as part of https://github.com/Azure/autorest.csharp/issues/885.
Try adding
--use:@microsoft.azure/autorest.csharp@2.3.90
to your command line.@daviwil apologies for the late reply, yes indeed this does seem to fix the issue.