Redocly / Redocly/redocly-cli

Respect doesn't resolve complex constraint pattern

Open
#2,639 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

$ref JSON Schema Respect Type: Bug
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Describe the bug
AJV validation error when using a discriminator with a schema property that uses allOf + not pattern instead of explicit enum values. The discriminator expects the mapped schema's discriminator property to have const or enum, but the AlternativeInstrument schema uses a more complex constraint pattern.

‼️ Error: Ajv error: discriminator: "properties/method" must have "const" or "enum"

To Reproduce

  1. Given the openapi.yaml file with the AlternativeInstrument schema that uses allOf + not:
AlternativeInstrument:
  properties:
    method:
      allOf:
        - $ref: '#/components/schemas/AlternativePaymentMethods'
        - not:
            enum:
              - payment-card
              - paypal
              - ach
  1. And the openapi.arazzo.yaml workflow file
  2. Run: redocly respect openapi.arazzo.yaml
  3. See the error: Ajv error: discriminator: "properties/method" must have "const" or "enum"

Expected behavior
The schema should br validated successfully.

Logs

Workflow name: test-cash-payment
 
  stepId - create-cash-instrument 
  ✗ schema check 
     Ajv error: discriminator: "properties/method" must have "const" or "enum"

OpenAPI description

Redocly version(s)
2.20.4

Node.js version(s)
v24

OS, environment
macOs

Additional context
If we use directly enum without allOf + not pattern everything works as expected.
⚠️ We found, that the issue comes from different $ref resolving between respect and lint commands. Because respect $ref is dereferenced, but lint is not.
Lint registers schemas via addSchema/loadSchemaSync with inlineRefs: false.
Respect receives a fully dereferenced schema (refs already resolved inline).

complex-schema-repro.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with openapi.yaml, openapi.arazzo.yaml, and redocly respect openapi.arazzo.yaml. Compare how respect resolves the referenced schemas with how lint registers them using inlineRefs: false, then verify that the allOf-plus-not discriminator schema validates successfully without the Ajv const-or-enum error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, cli, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.