Skip to content

Comments

Fix malformed schema traversal to report validation errors instead of…#467

Merged
p1c2u merged 1 commit intomasterfrom
fix/malformed-property-schema-error-reporting
Feb 24, 2026
Merged

Fix malformed schema traversal to report validation errors instead of…#467
p1c2u merged 1 commit intomasterfrom
fix/malformed-property-schema-error-reporting

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Feb 24, 2026

… internal exceptions

I reproduced this and implemented a fix on master branch locally.
Root cause:

  • SchemaValidator recursively traversed schema nodes assuming mapping-like behavior.
  • For malformed nodes like properties: {name: "string"}, that assumption could trigger internal exceptions (or produce poor UX depending on dependency versions), and in some cases even miss the error.
    What was changed:
  • In openapi_spec_validator/validation/keywords.py, SchemaValidator.call now validates each schema node with check_schema(...) before descending into keywords like allOf / properties.
  • If a node is malformed, we now yield OpenAPIValidationError and stop traversing that node.
  • This avoids internal AttributeError paths and consistently reports a proper validation error.
    Tests added:
  • tests/integration/validation/test_exceptions.py
    • Added regression for malformed property schema (name: "string") and assert it emits OpenAPIValidationError.
  • tests/integration/test_main.py
    • Added CLI regression using stdin for the same malformed input and assert output is Validation Error (and not OK).

Fixes #436

@p1c2u p1c2u force-pushed the fix/malformed-property-schema-error-reporting branch from 62f5544 to 1139902 Compare February 24, 2026 00:36
@p1c2u p1c2u force-pushed the fix/malformed-property-schema-error-reporting branch from 1139902 to e80a2bb Compare February 24, 2026 01:26
@p1c2u p1c2u merged commit 90a94ed into master Feb 24, 2026
22 checks passed
@p1c2u p1c2u deleted the fix/malformed-property-schema-error-reporting branch February 24, 2026 01:29
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.

Nondescript error message/internal exception on ill-formed property spec

1 participant