Redocly / Redocly/redoc

Improper handling of type compatibility in allOf clauses for OpenAPI 3.1 Spec

Open
#2,748 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
TypeScript
Stars
25.9k
Forks
2.4k
Avg merge
13h 10m
Merged PRs (30d)
4

Description

Since OpenAPI 3.1, the type schema field can now be a list, for example:

"type": ["string", "null"]

Would mean that the schema can be a string or null.

Redoc verifies that when "overriding" a property with allOf, the type is identical (see here). But the check is done using ===, which does not work well for lists, hence I'm getting this error:

Incompatible types in allOf at "/properties/error/properties/code": "string,null" and "string,null"

Expected behavior
If both types in the parent and child schema are ["string", "null"], there shouldn't be an error.
The solution is probably to modify the comparison to be smarter than a simple ===.

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

Start in src/services/OpenAPIParser.ts around the type compatibility check at line 245, using the linked implementation as the entry point. Reproduce the OpenAPI 3.1 allOf case with matching string-and-null type lists and verify that identical parent and child types no longer produce an incompatibility error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.