swagger-api / swagger-api/swagger-parser
References to parameters and responses are not preserved
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
References to responses and parameters are replaced with the referenced object in the serialized output. It should be similar to definitions, which preserves references.
input.yaml
swagger: '2.0'
info:
title: test
version: "1.0.0"
description: test
host: api.test.com
paths:
'/buckets/{bucketKey}':
get:
description: test
parameters:
- $ref: '#/parameters/bucketKey'
responses:
'200':
description: success
schema:
type: array
items:
$ref: './buckets.yaml'
post:
description: test
parameters:
- $ref: '#/parameters/bucketKey'
responses:
'200':
$ref: '#/responses/objectKey'
'/buckets/{bucketKey}/object':
get:
description: test
parameters:
- $ref: '#/parameters/bucketKey'
responses:
'200':
$ref: '#/responses/objectKey'
parameters:
bucketKey:
name: bucketKey
in: path
description: Referenced parameter
required: true
type: string
responses:
objectKey:
description: Referenced response
schema:
type: object
properties:
paging:
$ref: '#/definitions/StatusResponse'
definitions:
StatusResponse:
description: Referenced definition
type: object
properties:
http_code:
type: integer
buckets.yaml
---
description: "Definition from external doc"
type: "object"
properties:
hello:
type: "string"
world:
type: "integer"
output.yaml
swagger: "2.0"
info:
description: "test"
version: "1.0.0"
title: "test"
host: "api.test.com"
paths:
/buckets/{bucketKey}:
get:
description: "test"
parameters:
- name: "bucketKey"
in: "path"
description: "Referenced parameter"
required: true
type: "string"
responses:
200:
description: "success"
schema:
type: "array"
items:
$ref: "#/definitions/buckets"
post:
description: "test"
parameters:
- name: "bucketKey"
in: "path"
description: "Referenced parameter"
required: true
type: "string"
responses:
200:
description: "Referenced response"
schema:
type: "object"
properties:
paging:
$ref: "#/definitions/StatusResponse"
/buckets/{bucketKey}/object:
get:
description: "test"
parameters:
- name: "bucketKey"
in: "path"
description: "Referenced parameter"
required: true
type: "string"
responses:
200:
description: "Referenced response"
schema:
type: "object"
properties:
paging:
$ref: "#/definitions/StatusResponse"
definitions:
StatusResponse:
type: "object"
properties:
http_code:
type: "integer"
description: "Referenced definition"
buckets:
type: "object"
properties:
hello:
type: "string"
world:
type: "integer"
description: "Definition from external doc"
parameters:
bucketKey:
name: "bucketKey"
in: "path"
description: "Referenced parameter"
required: true
type: "string"
responses:
objectKey:
description: "Referenced response"
schema:
type: "object"
properties:
paging:
$ref: "#/definitions/StatusResponse"
expected_output.yaml
swagger: "2.0"
info:
description: "test"
version: "1.0.0"
title: "test"
host: "api.test.com"
paths:
/buckets/{bucketKey}:
get:
description: "test"
parameters:
- $ref: '#/parameters/bucketKey'
responses:
200:
description: "success"
schema:
type: "array"
items:
$ref: "#/definitions/buckets"
post:
description: "test"
parameters:
- $ref: '#/parameters/bucketKey'
responses:
200:
$ref: '#/responses/objectKey'
/buckets/{bucketKey}/object:
get:
description: "test"
parameters:
- $ref: '#/parameters/bucketKey'
responses:
200:
$ref: '#/responses/objectKey'
definitions:
StatusResponse:
type: "object"
properties:
http_code:
type: "integer"
description: "Referenced definition"
buckets:
type: "object"
properties:
hello:
type: "string"
world:
type: "integer"
description: "Definition from external doc"
parameters:
bucketKey:
name: "bucketKey"
in: "path"
description: "Referenced parameter"
required: true
type: "string"
responses:
objectKey:
description: "Referenced response"
schema:
type: "object"
properties:
paging:
$ref: "#/definitions/StatusResponse"
As you can see, the parameter-reference bucketEye and response-reference objectKey are referenced by multiple operations. In the output, those references are replaced by the referenced object's content. It results in duplicated content within the document. Also those references under parameters and responses sections are no longer used after serialization.
For definitions, the references are kept. If the reference is external then it's resolved and copied into the document and the new internal reference is used from that point on. Parameters and responses should at least keep the internal references intact.
A user would want to 'resolve' the external references, but still want to keep the internal references preserved. Ideally preserving the internal references should be the default behaviour, so the document doesn't get bloated by copying the referenced object's content to each instance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the serialization and reference-resolution path used for the input.yaml example; the issue provides input.yaml, buckets.yaml, output.yaml, and expected_output.yaml as comparison cases. Reproduce the serialized output and verify that internal parameter and response references remain as $ref entries while external references are resolved as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100