question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`bundle` duplicates referenced components

See original GitHub issue

Describe the bug

Using the bundle command duplicates components in the outputed file.

To Reproduce

  1. Using these files:

openapi.yaml

openapi: 3.0.0
info:
  version: 0.0.0
  title: Test API
  description: This is a test!

servers:
  - url: http://localhost.com/api/v1

tags:
  - name: users
    description: Users operations

paths:
  /users:
    $ref: "./resources/users.yaml"
  /users/{userId}:
    $ref: "./resources/user.yaml"

components:
  parameters:
    userId:
      $ref: "./parameters/path/userId.yaml"

    limit:
      $ref: "./parameters/query/limit.yaml"


  schemas:
    User:
      $ref: "./schemas/User.yaml"
    Users:
      $ref: "./schemas/Users.yaml"

    Error:
      $ref: "./schemas/Error.yaml"


  responses:
    UnexpectedError:
      $ref: "./responses/UnexpectedError.yaml"
    NullResponse:
      $ref: "./responses/NullResponse.yaml"

resources/users.yaml

get:
  summary: List users
  operationId: listUsers
  description: List all users
  tags:
    - users
  parameters:
    - $ref: "../parameters/query/limit.yaml"
    - $ref: "../parameters/query/skip.yaml"
  responses:
    '200':
      description: A page array of users
      content:
        application/json:
          schema:
            $ref: "../schemas/Users.yaml"
    default:
      $ref: "../responses/UnexpectedError.yaml"

post:
  summary: Create a user
  operationId: createUser
  description: Create a user
  tags:
    - users
  requestBody:
    description: User to add
    required: true
    content:
      application/json:
        schema:
          $ref: "../schemas/User.yaml"
  responses:
    '201':
      $ref: "../responses/NullResponse.yaml"
    default:
      $ref: "../responses/UnexpectedError.yaml"

resources/user.yaml

get:
  summary: Detail of a user
  operationId: getUserById
  description: Info for a specific user
  tags:
    - users
  parameters:
    - $ref: "../parameters/path/userId.yaml"
  responses:
    '200':
      description: The user associated with the given id
      content:
        application/json:
          schema:
            $ref: "../schemas/User.yaml"
    default:
      $ref: "../responses/UnexpectedError.yaml"

parameters/path/userId.yaml

name: userId
in: path
description: The id of the user to retrieve
required: true
schema:
  type: string
  format: uuid

parameters/query/limit.yaml

name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema: 
  type: integer
  format: int32
  minimum: 1
  maximum: 100
  default: 100

schemas/User.yaml

type: object
required:
  - name
properties:
  id:
    type: string
    format: uuid
  name:
    type: string

schemas/Users.yaml

type: array
items:
  $ref: "./User.yaml"

schemas/Error.yaml

type: object
required:
  - code
  - message
properties:
  code:
    type: integer
    format: int32
  message:
    type: string
  1. Running
openapi bundle openapi.yaml --ext yaml --output docs/openapi.yaml

Produces a lot of warnings like this one : Two schemas are referenced with the same name but different content. . Renamed limit to limit-2.

  1. Results in:
openapi: 3.0.0
info:
  version: 0.0.0
  title: Kico API
  description: Endoscopic video annotation tool.
servers:
  - url: http://localhost.com/api/v1
tags:
  - name: users
    description: Users operations
  - name: patients
    description: Patients operations
paths:
  /users:
    get:
      summary: List users
      operationId: listUsers
      description: List all users
      tags:
        - users
      parameters:
        - $ref: '#/components/parameters/limit-2'
        - $ref: '#/components/parameters/skip'
      responses:
        '200':
          description: A page array of users
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Users-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
    post:
      summary: Create a user
      operationId: createUser
      description: Create a user
      tags:
        - users
      requestBody:
        description: User to add
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User-2'
      responses:
        '201':
          $ref: '#/components/responses/NullResponse-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
  /users/{userId}:
    get:
      summary: Detail of a user
      operationId: getUserById
      description: Info for a specific user
      tags:
        - users
      parameters:
        - $ref: '#/components/parameters/userId-2'
      responses:
        '200':
          description: The user associated with the given id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
  /patients:
    get:
      summary: List patients
      operationId: listPatients
      description: List all patients
      tags:
        - patients
      parameters:
        - $ref: '#/components/parameters/limit-2'
      responses:
        '200':
          description: A page array of patients
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Patients-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
    post:
      summary: Create a patient
      operationId: createPatient
      description: Create a patient
      tags:
        - patients
      requestBody:
        description: Patient to add
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Patient-2'
      responses:
        '201':
          $ref: '#/components/responses/NullResponse-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
  /patients/{patientIpp}:
    get:
      summary: Detail of a patient
      operationId: getPatientByIpp
      description: Info for a specific patient
      tags:
        - patients
      parameters:
        - $ref: '#/components/parameters/patientIpp-2'
      responses:
        '200':
          description: The patient associated with the given ipp
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Patient-2'
        default:
          $ref: '#/components/responses/UnexpectedError-2'
components:
  parameters:
    userId:
      name: userId
      in: path
      description: The id of the user to retrieve
      required: true
      schema:
        type: string
        format: uuid
    patientIpp:
      name: patientIpp
      in: path
      description: The ipp of the patient to retrieve
      required: true
      schema:
        type: string
    limit:
      name: limit
      in: query
      description: How many items to return at one time (max 100)
      required: false
      schema:
        type: integer
        format: int32
        minimum: 1
        maximum: 100
        default: 100
    limit-2:
      name: limit
      in: query
      description: How many items to return at one time (max 100)
      required: false
      schema:
        type: integer
        format: int32
        minimum: 1
        maximum: 100
        default: 100
    skip:
      name: skip
      in: query
      description: How many pages should be skipped
      required: false
      schema:
        type: integer
        format: int32
        minimum: 0
        default: 0
    userId-2:
      name: userId
      in: path
      description: The id of the user to retrieve
      required: true
      schema:
        type: string
        format: uuid
    patientIpp-2:
      name: patientIpp
      in: path
      description: The ipp of the patient to retrieve
      required: true
      schema:
        type: string
  schemas:
    User:
      type: object
      required:
        - name
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
    Users:
      type: array
      items:
        $ref: '#/components/schemas/User-2'
    Patient:
      type: object
      required:
        - ipp
      properties:
        ipp:
          type: string
    Patients:
      type: array
      items:
        $ref: '#/components/schemas/Patient-2'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
    Error-2:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
    User-2:
      type: object
      required:
        - name
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
    Users-2:
      type: array
      items:
        $ref: '#/components/schemas/User-2'
    Patient-2:
      type: object
      required:
        - ipp
      properties:
        ipp:
          type: string
    Patients-2:
      type: array
      items:
        $ref: '#/components/schemas/Patient-2'
  responses:
    UnexpectedError:
      description: Unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error-2'
    NullResponse:
      description: Null response
    UnexpectedError-2:
      description: Unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error-2'
    NullResponse-2:
      description: Null response

Expected behavior Remove duplicated content with -2. They are detected as different schemas but are the same.

Logs

[1] resources/users.yaml:8:7 at #/get/parameters/0

Two schemas are referenced with the same name but different content. Renamed limit to limit-2.

 6 |   - users
 7 | parameters:
 8 |   - $ref: "../parameters/query/limit.yaml"

OpenAPI definition If applicable, add an OpenAPI definition and .redocly.yaml configuration file that helps reproduce the problem. At a minimum, please state the specification version(s) you’re using (e.g. 2.0, 3.0, 3.1).

openapi-cli Version(s) What version of openapi-cli are you using?

1.0.0-beta.79

Node.js Version(s) What version of node.js are you using?

v16.13.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
adamaltmancommented, Jan 21, 2022

Here is a workaround:

openapi.yaml

openapi: 3.0.0
info:
  version: 0.0.0
  title: Test API
  description: This is a test!

servers:
  - url: http://localhost.com/api/v1

tags:
  - name: users
    description: Users operations

paths:
  /users:
    $ref: "./resources/users.yaml"
  /users/{userId}:
    $ref: "./resources/user.yaml"

Use the same files except the root openapi.yaml file I pasted above.

The issue is the components are defined but then aren’t used from the operations. Instead, the direct files are referenced (which is great – I prefer that approach). This causes two sets of components to result in your bundle.

If you use the file above, then I think you’ll find the components section looks appropriate in the bundle output.

1reaction
adamaltmancommented, Jan 31, 2022

Most tools don’t handle $ref’s correctly. The document is complete without the components. But if you prefer, you can write them in components but then you would reference the components like this:

type: array
items:
  $ref: "../openapi.yaml#/components/schemas/User"

I personally prefer the other approach I showed above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finding and fixing duplicates in webpack with Inspectpack
Dependencies, Bundles, and Duplicates. To begin to understand how duplicated dependencies hurt modern frontend bundles, we need to look at the ...
Read more >
import inserts duplicates · Issue #7 · webpack-contrib/less-loader
Importing something with @import (reference) means that you are not interested in the css output, but in variables, mixins or css-classes because you...
Read more >
Using React components bundled with Webpack causes ...
output.library: 'ComponentD',. Everything works fine except for A's bundle size. The bundle is too heavy because D is duplicated inside of A's ....
Read more >
The Addressables Analyze tool - Unity - Manual
Check Duplicate Bundle Dependencies ... This rule checks for potentially duplicated assets, by scanning all groups with BundledAssetGroupSchemas and projecting ...
Read more >
Duplicate name in bundle - Google Groups
MESSAGE [SCR] Found components with duplicated names inside their bundle! This component will not be processed: Component[. name = org.company.accounting.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found