-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI: Range attribute causes FormatException #57390
Comments
Looks like these two lines of code need updating to pass through at least aspnetcore/src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs Lines 94 to 95 in 48a0721
|
Couldn't this special case double and int to avoid ToString()/Parse completely? The RangeAttribute constructors only support double, int and string. string would also fail currently, not sure if it can even be mapped to OpenAPI. |
@mus65 Thanks for filing this issue! Unfortunately, we're having to deal with a constraint in the underlying So, for the string case, the best approach would probably be to use a schema transformer to define an extension property on the spec to encode minimum and maximum-values for non-numeric types (like dates). I suspect that I think the best thing to do here would be to catch the exception that is thrown here and provide a clearer message about the constraints of the minimum/maximum type. I'll mark this as something to doc for .NET 9 and try to fix the exception for .NET 10. |
Just passing to say that I'm having the same problem. The following code (generated by NSWAG) causes the problem: [System.Text.Json.Serialization.JsonPropertyName("the_value")]
[System.ComponentModel.DataAnnotations.Range(0D, double.MaxValue)]
public double The_value { get; set; } = default!; When commenting the [System.Text.Json.Serialization.JsonPropertyName("the_value")]
//[System.ComponentModel.DataAnnotations.Range(0D, double.MaxValue)]
public double The_value { get; set; } = default!; .NET Version: 9.0.100-rc.1.24452.12 |
Is there a way to ignore certain data annotations when generating OpenApiSchema? In my case below code is causing similar exception.
|
Unfortunately, not at the moment. I'm hoping to get a fix for this out in .NET 10 Preview 1 and the first servicing release of .NET 9. In the long-term, it doesn't appear that JSON Schema supports modeling ranges for non-integer values as part of its default validation vocabulary. There were proposals of a |
Is there an existing issue for this?
Describe the bug
Adding the following attribute to a property of type long causes a FormatException when generating the OpenAPI document:
Affected code:
aspnetcore/src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs
Line 95 in 48a0721
Exception:
Expected Behavior
No exception.
Steps To Reproduce
Add
[Range(0, 9223372036854775807)]
to a long property.Exceptions (if any)
.NET Version
9.0.100-preview.7.24407.12
Anything else?
No response
The text was updated successfully, but these errors were encountered: