-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Clarifying about floating point types extra values #2617
Comments
Cant a "number" be NaN or Infinity? |
It seems not cause I'm having a problem with that kind of json object: {
"id": 1,
"date": "2019-12-16T20:31:48.68",
"policyStartDate": "2020-01-21T00:00:00",
"externalContractNumber": "",
"userName": "skipped user name",
"price": 0.0,
"companyId": 2,
"policyLink": "",
"partnerCampaignMedium": "campaign",
"policyBlankLink": null,
"source": "skipped",
"subId": "skipped",
"registrationRoute": "route",
"subAgentRoute": "skipped",
"isAccepted": true,
"withProlongation": true,
"profit": 0.0,
"profitPercent": "NaN",
"hash": "skippedipped",
} Look at this property:
This is object's (property) C# code:
And this is error I'm getting when trying to validate it:
This is the json schema of this object: "profitPercent": {
"type": "number"
}, This is how I generate schema's:
And this is how I validate them: var validateResult = new NJsonSchema.Validation.JsonSchemaValidator().Validate(result, schema);
validateResult.Count.ShouldBe(0, string.Join('\n', validateResult)); By the way - it seems neither NSwag or OAS spec supports nullable C# values. I mean I expect that value's schema to be like this: "someValue": {
"type": "number, null"
}, |
With JSON Schema the "type" can also be an array, e.g. In Swagger 2.0 there is no way to specify nullability - there is only required (which is often misused to also specify nullability). In OpenAPI 3.0 a new property "nullable" on a property has been introduced:
|
Ok, and what about "NaN" or "Inifinity" values? I'm not even mentioning C# methods checking if its positive or negative infinity |
Any idea what the correct way is to serialize NaN and Infinity with JSON? Maybe using "NaN" or "Inifinity" is correct but Newtonsoft.Json cannot handle it (with default settings)? |
How we could make possible to declare custom type with some mixed allowable values, like "number" type range of values along with "NaN" and "pInfinity" / "nInfinity" ? |
There's another problem with float and double and its about this types scopes - they can be Infinity or NaN, but generated json schema points them as "number" only.
I think its could be a problem when casting json types onto C# Dto objects.
Originally posted by @orihomie in #1122 (comment)
I need to know if there's any solution for that problem without specifying type of such value like this:
This way there's no clarity if I got specific type strings like "NaN" / "Infinity" or any trash that shouldnt be there.
I've read old issues on OAS repo which were pointing this problem, but they, like this one, gave me no clarity on how I should I behave myself with such types.
The text was updated successfully, but these errors were encountered: