`bundle` duplicates referenced components
See original GitHub issueDescribe the bug
Using the bundle
command duplicates components in the outputed file.
To Reproduce
- 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
- 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.
- 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:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Here is a workaround:
openapi.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.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:
I personally prefer the other approach I showed above.