Skip to content

Allow required properties with an empty additionalProperties schema - #245

Open
draarivpatel-ui wants to merge 1 commit into
horejsek:masterfrom
draarivpatel-ui:fix-empty-additional-properties
Open

draarivpatel-ui wants to merge 1 commit into
horejsek:masterfrom
draarivpatel-ui:fix-empty-additional-properties

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

The check that rejects required properties which cannot appear in an object uses the truthiness of additionalProperties:

if not self._definition.get('additionalProperties', True):

An empty schema {} is a valid schema that allows everything, but it is falsey, so this valid definition fails to compile:

schema = {
    "type": "object",
    "required": ["extra"],
    "additionalProperties": {},
}
fastjsonschema.compile(schema)({"extra": 1})
# JsonSchemaDefinitionException: data: items ['extra'] are required but not allowed

Only literal false disallows additional properties, so the check now compares against False. A schema such as {"type": "number"} already used a truthy dict and was unaffected.

Tests cover an empty schema and a non-empty schema with a required property. The empty-schema case fails with JsonSchemaDefinitionException before the change. Full suite: 1516 passed, 4 skipped.

The impossible-required check used the truthiness of additionalProperties, so an empty schema was treated like literal false and compilation failed. Check for literal false instead.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

2 participants