You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenApiJsonWriter produces non-standard JSON values when a schema has 'NaN' or 'Infinity' values #1519
Describe the bug OpenApiJsonWriter produces non-standard JSON values when an OpenAPI schema has NaN or +/-Infinity values.
JSON specification does not support unquoted NaN or Infinity values. While some JSON parsers (like JavaScript's JSON.parse) can handle these values, others (like Python's json module or .NET's System.Text.Json) cannot. This can lead to interoperability issues when different systems interact with the JSON output of 'OpenApiJsonWriter'.
OpenApi File To Reproduce
varschema=newOpenApiSchema{Enum=newList<Microsoft.OpenApi.Any.IOpenApiAny>{newOpenApiDouble(double.NaN),newOpenApiDouble(double.PositiveInfinity),newOpenApiDouble(double.NegativeInfinity)}};varschemaBuilder=newStringBuilder();varjsonWriter=newOpenApiJsonWriter(newStringWriter(schemaBuilder));schema.SerializeAsV3(jsonWriter);varjsonString=schemaBuilder.ToString();// <--- The resulting JSON string is not a valid JSON.varjsonElement=JsonSerializer.Deserialize<Dictionary<string,object>>(jsonString);// <--- Throws " 'N' is an invalid start of a value".
Expected behavior
The resulting NaN or Infinity values should have quotes around them to be considered valid JSON. Adding quotes around the values will ensure that the resulting JSON OpenAPI document is fully compliant with the JSON specification and can be correctly processed by any JSON parser.
Activity