Bundle: option to keep all refs but turn them into internal refs
See original GitHub issueThe bundle
command’s current behaviour breaks the code generation in my current project.
Currently, with no special option, the bundle
command inlines all $ref
s it finds on the first encounter, and then makes a reference to that local inline upon any subsequent encounter of the same reference.
For this example input:
main.yaml
swagger: '2.0'
info:
version: 0.0.0
paths:
/test1:
get:
parameters:
- $ref: "./parameters.yaml#/parameters/param"
/test2:
get:
parameters:
- $ref: "./parameters.yaml#/parameters/param"
parameters.yaml
parameters:
param:
in: query
name: myParam
description: some demo parameter
type: string
pattern: '^[a-zA-Z]+$'
required: true
The output I get from npx swagger-cli bundle main.yaml
is the following:
swagger: '2.0'
info:
version: 0.0.0
paths:
/test1:
get:
parameters:
- in: query
name: myParam
description: some demo parameter
type: string
pattern: '^[a-zA-Z]+$'
required: true
/test2:
get:
parameters:
- $ref: '#/paths/~1test1/get/parameters/0'
When things get complicated, it can yield references like this:
$ref: '#/paths/~1analytics-ui/post/parameters/3/schema/items/properties/data/properties/page/properties/attributes'
And during code generation, this may turn into class names as long as this path, which is far from ideal.
It would be nice to have an option (e.g. --no-dereference
) to preserve any reference, and simply bring the referenced declarations to the bundled file, but in a separate place within the file. This means that every reference will simply become a local declaration, but point to the same path.
Here is the output I would expect using this option on the same sample input that I provided:
bundle.yaml
swagger: '2.0'
info:
version: 0.0.0
paths:
/test1:
get:
parameters:
- $ref: "#/parameters/param"
/test2:
get:
parameters:
- $ref: "#/parameters/param"
parameters:
param:
in: query
name: myParam
description: some demo parameter
type: string
pattern: '^[a-zA-Z]+$'
required: true
Is there a way to achieve this currently?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:48
- Comments:13
Top GitHub Comments
I would also like to have this feature. Specifically for OpenAPI 3, It would be great to have an option where bundle takes the referenced components and combines them in a components section in a bundled file, updating the original $ref that pointed to
<file>#<componentPath>
to point to#<componentPath>
in the combined file.Copying from https://github.com/APIDevTools/swagger-parser/issues/127#issuecomment-922634697
The obvious – if annoying – workaround is to put components first, and reference everything there.
Example input
example.yml
schema/a.yml
schema/b.yml
Example output
yields