Skip to content

fix: merge object properties as a union in allOf intersection - #55

Open
villaverde82 wants to merge 1 commit into
mainfrom
fix/allof-object-properties
Open

villaverde82 wants to merge 1 commit into
mainfrom
fix/allof-object-properties

Conversation

@villaverde82

@villaverde82 villaverde82 commented Sep 30, 2026 •

Copy link
Copy Markdown

restcheck_schema:intersection/2, when merging two object schemas (e.g. in an allOf), keeps only the properties present in both schemas, but takes the union of their required lists. Any property declared in just one of them is dropped while still being required, so restcheck_triq:object/2 can't find it in properties and crashes with badkey.

Example:

Pet:
type: object
properties:
name: {type: string}
age: {type: integer}
required: [name, age]

Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
age: {type: integer, minimum: 0}
bark: {type: boolean}
required: [bark]

Current result: properties = {age: {type: integer, minimum: 0}}, required = [name, age, bark] -> {badkey, <<"name">>}

Since allOf requires an instance to satisfy both schemas, the fix takes the union of the properties. Properties present in only one schema (name, bark) are kept as they are. Properties present in both (age) still have their schemas intersected, so they must satisfy both (maps:merge_with with intersection/1).

Expected result: properties = {name: {type: string}, age: {type: integer, minimum: 0}, bark: {type: boolean}}, required = [name, age, bark]

@villaverde82
villaverde82 force-pushed the fix/allof-object-properties branch from 6b28627 to e40952a Compare September 30, 2026 11:09

This branch has not been deployed

No deployments
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