Skip to content

A null default is incorrectly deserialized as JsonValue of kind string with value of "null" from YAML and there is no way to distinguish between an undefined default value and a null default value. #2510

@jkporter

Description

@jkporter

Describe the bug
When deserializing default value from a YAML document and that value is null it is converted to a JsonValue of kind string with the value of "null" making it ambiguous. In actuality it should result in a null JsonNode. Furthermore, there is no way to distinguish between an unset default value and a default value of null since JsonNode cannot represent a JSON null value beyond being null itself.

OpenApi File To Reproduce
https://api.ynab.com/papi/open_api_spec.yaml

Expected behavior
Default would return null instead of a JsonValue of kind string when deserializing from YAML and an additional property should be added such as DefaultIsNull. Alternatively, the type for the Default property should perhaps be changed to JsonElement with correct type deserialization.

Screenshots/Code Snippets
Currently have this workaround which tries to guess whether Default should be considered a null value or a string of "null".

var valueKind = property.Default.GetValueKind();
if (valueKind is JsonValueKind.String
    && property.Default.GetValue<string>() == "null"
    && property.Type is not null
    && (!property.Type.Value.HasFlag(JsonSchemaType.String) || property.Type.Value.HasFlag(JsonSchemaType.Null)))
    valueKind = JsonValueKind.Null;

Metadata

Metadata

Assignees

Labels

type:breaking-changeAn issue that will result in dependent client projects failing.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions