Redocly / Redocly/redoc

Aggregation of custom `x-whatever` Schema Keys not working across > 1 layers

Open
#2,707 0 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

To recreate the bug using the redocly CLI, create a dummy OpenAPI Spec dummy.json with the following content:

{
  "openapi": "3.1.0",
  "info": {
    "title": "REST API",
    "description": "API",
    "version": "v1",
    "license": {
      "name": "Private",
      "url": "https://example.org"
    }
  },
  "servers": [
    {
      "url": "https://example.org",
      "description": "Server"
    }
  ],
  "components": {
    "schemas": {
      "dummy_wrapper_true": {
        "x-second-value": true,
        "$ref": "#/components/schemas/_dummy_wrapper",
        "description": "True Wrapper"
      },
      "dummy_wrapper_false": {
        "x-second-value": false,
        "$ref": "#/components/schemas/_dummy_wrapper",
        "description": "False Wrapper"
      },
      "_dummy_wrapper": {
        "x-first-value": "first",
        "type": "string",
        "pattern": "^hello$"
      }
    }
  },
  "paths": {
    "/route": {
      "post": {
        "operationId": "post:route",
        "summary": "Post Route",
        "description": "Used to POST to route",
        "security": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "dummy_false": {
                    "$ref": "#/components/schemas/dummy_wrapper_false"
                  },
                  "dummy_true": {
                    "$ref": "#/components/schemas/dummy_wrapper_true"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "dummy_false",
                  "dummy_true"
                ]
              },
              "example": {
                "dummy_false": "hello",
                "dummy_true": "hello"
              }
            }
          },
          "required": true
        },
        "responses": {
          "401": {
            "description": "Failure",
            "content": {
              "application/json": {
                "schema": {
                  "type": "null"
                }
              }
            }
          },
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "null"
                }
              }
            }
          }
        }
      }
    }
  }
}

Running redocly lint dummy.json will tell you that everything's fine.

Then run redocly bundle dummy.json --dereferenced --output=dummy-dr.json and open your dummy-dr.json file. You will notice that the dummy_false and the dummy_true properties will only contain the x-first-value key in your requestBody, while they will contain both x-first-value and x-second-value in the dummy-dr.json file's #/components/schemas.

The dummy-dr.json file should also contain both the x-first-value and x-second-value keys in the requestBody's properties dummy_false and dummy_true.

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 by creating the issue's dummy.json and running redocly lint dummy.json, then redocly bundle dummy.json --dereferenced --output=dummy-dr.json. Compare the requestBody properties with the corresponding component schemas in dummy-dr.json; done means both x-first-value and x-second-value are preserved through the nested schema references.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.