Skip to content

fix(no-required-schema-properties-undefined): resolve false positives for bare-required schemas in allOf-composed types#2836

Open
jeremyfiel wants to merge 1 commit into
Redocly:mainfrom
jeremyfiel:refactor/no-required-schema-properties-undefined-rule
Open

fix(no-required-schema-properties-undefined): resolve false positives for bare-required schemas in allOf-composed types#2836
jeremyfiel wants to merge 1 commit into
Redocly:mainfrom
jeremyfiel:refactor/no-required-schema-properties-undefined-rule

Conversation

@jeremyfiel
Copy link
Copy Markdown
Contributor

@jeremyfiel jeremyfiel commented May 22, 2026

Problem

The no-required-schema-properties-undefined rule incorrectly reported errors for two valid JSON Schema draft-04 patterns:

  1. Bare-required property sub-schema override — a property sub-schema that uses required as a pure presence constraint with no local properties, relying on the property's type definition resolved through a parent allOf.$ref:

    properties:
      personName:
        required: [givenName, familyName]   # no properties block
    allOf:
      - $ref: '#/components/schemas/PersonBase'  # defines personName's type
  2. oneOf constraint fragmentsoneOf branches that each contain only a required keyword:

    properties:
      communication:
        oneOf:
          - required: [landlines]
          - required: [mobiles]
    allOf:
      - $ref: '#/components/schemas/PersonBase'  # defines communication type

Both are valid per the JSON Schema specification, where required and properties are fully independent keywords.

Solution

Added a hasPropertyInParentContext helper to the rule's enter closure. When the first two checks (local properties and compositionRoot) both fail to find a required property, the helper walks up the parents stack to locate the ancestor schema that contains the current schema as a named property value. It then resolves that ancestor's allOf/anyOf/oneOf siblings and checks whether the property key is defined in any of them — the same hasProperty traversal used elsewhere in the rule.

This approach intentionally preserves misspelling detection: a misspelled key (e.g., giveName vs givenName) still fails the parent-context check and is reported as an error.

Tests

Added 3 new test cases (23 total, all passing):

  • should not report bare required when property is defined in parent allOf sibling
  • should not report bare required in oneOf branches when property is defined in parent allOf sibling
  • should report misspelled required property even when parent allOf sibling defines the property

relates to #2320 #2060 #2061

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Adjusts linting logic for required validation across composed schemas (allOf/oneOf/anyOf), which may change reported errors for some specs; test coverage reduces risk but behavior changes can impact user CI results.

Overview
Fixes false positives in no-required-schema-properties-undefined by allowing bare required constraints on property sub-schemas when the property’s type is defined in a parent composition sibling (including oneOf branches used as constraint fragments).

Updates the reported error message text from “not defined” to “undefined”, adds regression tests for the new edge cases (and misspelling detection), and documents the supported JSON Schema patterns.

Reviewed by Cursor Bugbot for commit 929f198. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: 929f198

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch
@redocly/respect-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jeremyfiel jeremyfiel force-pushed the refactor/no-required-schema-properties-undefined-rule branch from 8856aa1 to 929f198 Compare May 22, 2026 18:42
@jeremyfiel jeremyfiel changed the title refactor(rules): two use cases not handled by current implementation fix(no-required-schema-properties-undefined): resolve false positives for bare-required schemas in allOf-composed types May 22, 2026
@jeremyfiel jeremyfiel marked this pull request as ready for review May 22, 2026 18:48
@jeremyfiel jeremyfiel requested review from a team as code owners May 22, 2026 18:48
@jeremyfiel
Copy link
Copy Markdown
Contributor Author

cc @baywet @Drowze would appreciate your feedback if you are using these constructs.

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