Skip to content

Treat merged schemas with no valid enum values as unsatisfiable - #1128

Open
shaurya703 wants to merge 1 commit into
oxidecomputer:mainfrom
shaurya703:fix/merge-empty-enum
Open

shaurya703 wants to merge 1 commit into
oxidecomputer:mainfrom
shaurya703:fix/merge-empty-enum

Conversation

@shaurya703

Copy link
Copy Markdown

Merging an enum with a type that none of its values has doesn't report the result as unsatisfiable. It leaves a schema with an empty list of enum values, and that either fails generation or adds an uninhabited variant.

This schema:

{
  "enum": ["north", "south"],
  "anyOf": [{ "type": "string" }, { "type": "null" }]
}

fails the whole run:

the newtype struct `EnumWithIncompatibleSubschemaVariant1` states allow list constraints with nothing in them

allOf: [{ "enum": ["a", "b"] }, { "type": "integer" }] fails the same way. allOf: [{ "enum": [1, 2] }, { "oneOf": [{ "type": "string" }, { "type": "integer" }] }] generates, but with a bogus Variant0 wrapping an empty enum.

merge_schema_object filters out enum values that don't validate against the merged schema, but it didn't check whether any were left. It now returns Err(()) in that case, as merge_so_enum_values already does when two enums don't intersect. Subschemas that admit none of the values are then dropped, so the schema above becomes a plain North/South enum. When nothing is left, the type is the usual empty enum.

I added a unit test in merge.rs and two cases in merged-schemas.json. Without the change, test_schemas fails with the error above. No other generated output changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant