redocly-cli
redocly-cli copied to clipboard
Incorrect schema description dereferenced
Describe the bug Incorrect schema description dereferenced
To Reproduce Steps to reproduce the behavior:
I use de sample specification:
openapi: 3.1.0
info:
version: 1.0.0
title: Example.com
termsOfService: https://example.com/terms/
contact:
email: [email protected]
url: http://example.com/contact
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
description: |
This is an **example** API to demonstrate features of the OpenAPI
specification.
servers:
- url: https://example.com/api/v1
paths:
/users:
post:
summary: user
description: User.
operationId: createUser
responses:
'200':
description: OK
requestBody:
description: Updated user object
content:
application/json:
schema:
description: Names and Numbers (specific)
$ref: '#/components/schemas/NamesAndNumbers'
required: true
components:
schemas:
Name:
type: string
description: Generic Name.
Number:
type: integer
Names:
type: object
description: names description
properties:
oneName:
$ref: "#/components/schemas/Name"
description: One name (specific).
otherName:
$ref: "#/components/schemas/Name"
description: Other name (specific).
Numbers:
type: object
description: numbers description
properties:
oneNumber:
$ref: "#/components/schemas/Number"
description: One number (specific)
otherNumber:
$ref: "#/components/schemas/Number"
description: Other number (specific)
NamesAndNumbers:
type: object
description: names and numbers description
properties:
names:
$ref: "#/components/schemas/Names"
numbers:
$ref: "#/components/schemas/Numbers"
When I run this command:
redocly bundle --dereferenced --remove-unused-components test.yaml -o test2.yaml
The result is:
openapi: 3.1.0
info:
version: 1.0.0
title: Example.com
termsOfService: https://example.com/terms/
contact:
email: [email protected]
url: http://example.com/contact
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
description: |
This is an **example** API to demonstrate features of the OpenAPI
specification.
servers:
- url: https://example.com/api/v1
paths:
/users:
post:
summary: user
description: User.
operationId: createUser
responses:
'200':
description: OK
requestBody:
description: Updated user object
content:
application/json:
schema:
description: names and numbers description
type: object
properties:
names:
type: object
description: names description
properties:
oneName:
description: Generic Name.
type: string
otherName:
description: Generic Name.
type: string
numbers:
type: object
description: numbers description
properties:
oneNumber:
description: One number (specific)
type: integer
otherNumber:
description: Other number (specific)
type: integer
required: true

Expected behavior I expected specific descriptions, not generic.
openapi: 3.1.0
info:
version: 1.0.0
title: Example.com
termsOfService: https://example.com/terms/
contact:
email: [email protected]
url: http://example.com/contact
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
description: |
This is an **example** API to demonstrate features of the OpenAPI
specification.
servers:
- url: https://example.com/api/v1
paths:
/users:
post:
summary: user
description: User.
operationId: createUser
responses:
'200':
description: OK
requestBody:
description: Updated user object
content:
application/json:
schema:
description: Names and Numbers (specific)
type: object
properties:
names:
type: object
description: names description
properties:
oneName:
description: One name (specific).
type: string
otherName:
description: Other name (specific).
type: string
numbers:
type: object
description: numbers description
properties:
oneNumber:
description: One number (specific)
type: integer
otherNumber:
description: Other number (specific)
type: integer
required: true

Thanks @lucianojs for reporting the issue.
Meanwhile you can wrap $refs into allOf to bypass this behaviour:
...
otherName:
allOf:
- $ref: "#/components/schemas/Name"
description: Other name (specific).
...