Visitar URL original
fix: null reference exception for boolean component schemas by baywet · Pull Request #2839 · microsoft/OpenAPI.NET · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(schema): support boolean schemas in deserializer for OpenAPI 3.1/3.2
Implement special handling for JSON Schema 2020-12 boolean schemas:
- true: deserializes to empty schema (allows any value)
- false: deserializes to schema with not: {} (disallows any value)

This enables proper support for boolean schemas as defined in the OpenAPI 3.1
and 3.2 specifications, which adopt JSON Schema 2020-12.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
baywet and Copilot committed Apr 27, 2026
commit 05b44beb9783f5bab1d8988b3cb916d0278d42ce
17 changes: 17 additions & 0 deletions src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ internal static partial class OpenApiV31Deserializer

public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument)
{
// Handle boolean schemas (true/false) for JSON Schema 2020-12 compatibility
if (node is ValueNode valueNode)
{
var value = valueNode.GetScalarValue();
if (value != null && bool.TryParse(value, out var boolValue))
{
var boolSchema = new OpenApiSchema();
if (!boolValue)
{
// false schema: represents "not valid" -> convert to "not: {}"
boolSchema.Not = new OpenApiSchema();
}
// true schema: represents "always valid" -> return empty schema (default)
return boolSchema;
}
}

var mapNode = node.CheckMapNode(OpenApiConstants.Schema);

var pointer = mapNode.GetReferencePointer();
Expand Down
17 changes: 17 additions & 0 deletions src/Microsoft.OpenApi/Reader/V32/OpenApiSchemaDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ internal static partial class OpenApiV32Deserializer

public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocument)
{
// Handle boolean schemas (true/false) for JSON Schema 2020-12 compatibility
if (node is ValueNode valueNode)
{
var value = valueNode.GetScalarValue();
if (value != null && bool.TryParse(value, out var boolValue))
{
var boolSchema = new OpenApiSchema();
if (!boolValue)
{
// false schema: represents "not valid" -> convert to "not: {}"
boolSchema.Not = new OpenApiSchema();
}
// true schema: represents "always valid" -> return empty schema (default)
return boolSchema;
}
}

var mapNode = node.CheckMapNode(OpenApiConstants.Schema);

var pointer = mapNode.GetReferencePointer();
Expand Down