Redocly / Redocly/redocly-cli

Duplicated entry in schema if casing of NamedSchema differ from filename

Open
#929 5 comments 0 reactions 1 assignee View on GitHub

@kanoru3101 is already working on this.

Since Sep 3, 2026.

p3 Type: Bug
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Describe the bug

When creating a schema to validate an API request (Let's call it ApiRequest), if the casing for the NamedSchema is capitalize whereas the filename itself is not, it will result in a duplicate when running it through redocly bundle

To Reproduce
Steps to reproduce the behavior:

  1. .redocly.yaml
extends: 
  - recommended

plugins: 
  -  src/schemata/plugins/extend-id-and-schema.js

apis:
  main@v0:
    root: src/schemata/openapi.yaml
    labels:
      - production
    rules:
      no-unused-components: warn

      # custom rule to ensure $id and $schema is passed
      # this is only enabled in external endpoints
      assert/required-id-and-schema:
        where:
          - subject: 
              type: Operation
              property: operationId
            assertions: 
              pattern: ^((?!(smoke|health)).)*$
          - subject:
              type: Response
              filterInParentKeys:
                - '200'
            assertions: 
              defined: true
        subject: 
          type: Schema
        assertions:
          defined: true
          required: 
            - $id
            - $schema
        message: Must have $id and $schema in Schema properties
        severity: error
  1. openapi.yaml
openapi: 3.0.3
info:
  # info are hidden

servers:
  # servers are hidden

paths:
  # paths are hidden

components:
  schemas:
    ApiRequest:
      $ref: ./components/requests/apiRequest.yaml

and my apiRequest.yaml

$schema: http://json-schema.org/draft-07/schema
$id: ApiRequest
type: object
description: Request schema for /api/* endpoints

required:
  - jobId
  - hirerId
  - hirerOriginZone

properties:
  jobId:
    type: string
    description: Represent id of job ad
    example: 51563417

  hirerId:
    type: string
    description: Represent id of job ad's hirer
    example: 28829855

  hirerOriginZone:
    type: string
    description: Represent origin zone of hirer's location.
    example: anz-1
  1. Run this command
redocly bundle ./src/schemata/openapi.yaml -o ./src/schemata/openapi-generated --ext=json --format=json  --dereferenced --lint --skip-rule=spec
  1. Output
{
  "openapi": "3.0.3",
  # stripped out info
  # stripped out paths
  "components": {
    "schemas": {
      "ApiRequest": {
        "$schema": "http://json-schema.org/draft-07/schema",
        "$id": "ApiRequest",
        "type": "object",
        "description": "Request schema for /api/* endpoints",
        "required": [
          "jobId",
          "hirerId",
          "hirerOriginZone"
        ],
        "properties": {
          "jobId": {
            "type": "string",
            "description": "Represent id of job ad",
            "example": 51563417
          },
          "hirerId": {
            "type": "string",
            "description": "Represent id of job ad's hirer",
            "example": 28829855
          },
          "hirerOriginZone": {
            "type": "string",
            "description": "Represent origin zone of hirer's location.",
            "example": "anz-1"
          }
        }
      },
      "apiRequest": {
        "$schema": "http://json-schema.org/draft-07/schema",
        "$id": "ApiRequest",
        "type": "object",
        "description": "Request schema for /api/* endpoints",
        "required": [
          "jobId",
          "hirerId",
          "hirerOriginZone"
        ],
        "properties": {
          "jobId": {
            "type": "string",
            "description": "Represent id of job ad",
            "example": 51563417
          },
          "hirerId": {
            "type": "string",
            "description": "Represent id of job ad's hirer",
            "example": 28829855
          },
          "hirerOriginZone": {
            "type": "string",
            "description": "Represent origin zone of hirer's location.",
            "example": "anz-1"
          }
        }
      }
    }
  }
}

Expected behavior

{
  "openapi": "3.0.3",
  # strip out info
  # strip out paths
  "components": {
    "schemas": {
      "ApiRequest": {
        "$schema": "http://json-schema.org/draft-07/schema",
        "$id": "ApiRequest",
        "type": "object",
        "description": "Request schema for /api/* endpoints",
        "required": [
          "jobId",
          "hirerId",
          "hirerOriginZone"
        ],
        "properties": {
          "jobId": {
            "type": "string",
            "description": "Represent id of job ad",
            "example": 51563417
          },
          "hirerId": {
            "type": "string",
            "description": "Represent id of job ad's hirer",
            "example": 28829855
          },
          "hirerOriginZone": {
            "type": "string",
            "description": "Represent origin zone of hirer's location.",
            "example": "anz-1"
          }
        }
      }
    }
  }
}

Logs
Screen Shot 2022-11-10 at 4 02 02 pm

OpenAPI definition
OAS 3.0

Redocly Version(s)
1.0.0-beta.112

Node.js Version(s)
v16.17.0

Additional context
tldr; Expecting one output of ApiRequest (following casing of NamedSchema) instead of having 2 where there other is a lowercase (when the filename starts with a lowercase)

Weird behaviour but when I do $ref: '../components/requests/ApiRequest.yaml it does not throw an error in lint nor the vscode extension

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.