Open mus65 opened 3 weeks ago
Looks like these two lines of code need updating to pass through at least NumberStyles.AllowExponent
through:
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 OpenApiSchema
representation here. The OpenApiSchema.Minimum and OpenApiSchema.Maximum properties are decimal
types. Based on the JSON schema validation spec, they are intended to only validate numeric values (see this section in the spec).
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 long
might have similar constraints given limitations on the maximum integer size supported in JavaScript/JSON? My recollection here is the recommendation is to transmit long values as strings when they need to be transmitted over the wire.
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.
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: https://github.com/dotnet/aspnetcore/blob/48a07213d4d8df15c6dffccd161844842c196998/src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs#L95
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