Skip to content

False positive no-required-schema-properties-undefined when required used inside not #3104

Description

@DmitryAnansky

Describe the bug

no-required-schema-properties-undefined false positive: required inside not (absence assertions / mutual exclusion).

The rule flags required entries inside a not subschema as "Required property 'x' is not defined." But required under not is the standard JSON Schema idiom for asserting a property's absence (or mutual exclusion of properties) — there is intentionally nothing to declare in a sibling properties, and the properties may even be declared on the enclosing object schema. The rule's purpose (catching typos where required names an undeclared property) doesn't apply to these assertion-only subschemas.

To Reproduce
redocly.yaml

extends: []
rules:
  no-required-schema-properties-undefined: warn

openapi.yaml

openapi: 3.1.0
info:
  title: Repro
  version: 1.0.0
paths:
  /contacts:
    post:
      operationId: createContact
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Contact'
      responses:
        '201':
          description: Created.
components:
  schemas:
    Contact:
      type: object
      properties:
        email:
          type: string
        phone:
          type: string
      # email and phone are mutually exclusive
      not:
        required:
          - email
          - phone

Root cause: in no-required-schema-properties-undefined, findCompositionRoot walks up only through allOf/anyOf/oneOf parents (isCompositionChild), so any schema reached via not never resolves a composition root and its own (usually empty) properties is the only thing checked.

Actual behavior

#/components/schemas/Contact/not/required/0  Required property 'email' is not defined.
#/components/schemas/Contact/not/required/1  Required property 'phone' is not defined.

Expected behavior

No warnings. Either (a) required occurrences inside a not subschema (at any depth) are exempt, since they are presence/absence assertions rather than shape declarations, or (b) property resolution traverses the not boundary to the enclosing object schema the way it already traverses allOf/anyOf/oneOf.

Logs

OpenAPI description

Redocly version(s)

@redocly/cli 2.51.2

Node.js version(s)

OS, environment

Additional context

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions