I am looking for a solution to resolve the incompatibility for handling null values for data types between Swagger (OpenAPI) data types and JSON Schema.
Our swagger file includes all our schema definitions, and I would like to use JSON.Net Schema for the schema validation step in our API tests.
A valid swagger property definition:
"description": {
"type": "string",
"nullable": true
}
will fail JSON schema validation for null values (Invalid type. Expected String but got Null
).
If I replace the nullable property definition with:
"description": {
"type": ["string", "null"]
}
validation will be successful for null values, but this breaks the swagger syntax.
Structural error at components.schemas.CalendarFunctionsDto.properties.description_EN.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
I couldn't find an OpenAPI schema to JSON schema converter for .NET. I'm trying to figure out if there is an easy solution available using JSON.Net Schema to solve this problem. Some of our types are more complex than the example above. I am looking for a solution that works for all "nullable" types.
I would ideally like to keep valid swagger (OpenAPI 3.0) JSON syntax for the input, programmatically perform some spells in C# for all nullable properties (convert the schema, or adjust the validation, or any other creative solution), and then validate the schema using JSON.Net Schema.