Comments (13)
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.
from swagger-cli.
Copying from APIDevTools/swagger-parser#127 (comment)
The obvious -- if annoying -- workaround is to put components first, and reference everything there.
Example input
example.yml
openapi: "3.0.3"
components: # reference everything here
schemas:
a: { $ref: "./schema/a.yml" }
b: { $ref: "./schema/b.yml" }
info:
title: Example
version: 0.0.0
paths:
/a:
get:
responses:
"200":
content:
application/json:
schema: { $ref: "./schema/a.yml" }
description: Success
/b:
get:
responses:
"200":
content:
application/json:
schema: { $ref: "./schema/b.yml" }
description: Success
schema/a.yml
properties:
aName: { type: string }
b: { $ref: "./b.yml" }
schema/b.yml
properties:
bName: { type: string }
Example output
swagger-cli bundle example.yml
yields
openapi: 3.0.3
components:
schemas:
a:
properties:
aName:
type: string
b:
$ref: '#/components/schemas/b'
b:
properties:
bName:
type: string
info:
title: Example
version: 0.0.0
paths:
/a:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/a'
description: Success
/b:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/b'
description: Success
from swagger-cli.
Hello there,
I am waiting to have ref internal or to ignore hasardous generation:
#/paths/~1users~1address~1%7Bid%7D/get/responses/200/content/application~1json/schema/properties/data
During this time, I am coding some split string things to get what I want in my original file to get internal components to bundle a valid file.
Thank in advance
from swagger-cli.
Thanks @lorthirk. Using --dereference
fix my issues with circular ref. Having this feature would be really awesome !
from swagger-cli.
In our projects we only have a few shared schemas. A workaround we've been using because of this problem is to avoid code like this:
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"
and use code like this instead:
swagger: '2.0'
info:
version: 0.0.0
paths:
/test1:
get:
parameters:
- $ref: "#/parameters/param"
/test2:
get:
parameters:
- $ref: "#/parameters/param"
parameters:
param:
$ref: "./parameters.yaml#/parameters/param"
This gets bundled into:
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
which works with our code generators but takes some extra lines.
from swagger-cli.
A +1 on this, since I have a circular reference on my project and the code generation breaks if I don't use --dereference
, which I have to because of the circular ref.
from swagger-cli.
@stephanebachelier thanks for the tag.
I tried with the latest version (2.3.4) using the command
swagger-cli bundle schemas/specs/all.yaml -t yaml -o schemas/resolved/all.yaml
and I am still seeing the reference inlined and then referenced later with a $ref to the inlined occurrence. This results in refs such as:
- $ref: '#/paths/~1v1~1my~1path/get/parameters/0'
and this beauty
- $ref: '#/paths/~1v1~1my~1other-path/get/responses/200/content/application~1json/schema/allOf/1/properties/data/items/oneOf/0/properties/dataPoint/allOf/0'
from swagger-cli.
Would love to have this feature too!
from swagger-cli.
@lorthirk @aaldredge @mgrzechocinski @joffrey-bion it seems that it already exists as long as you manage to avoid circular references. I add forgotten to add some schemas before the paths sections. Adding them before the path sections remove the circular references are they are already defined in the bundled schema.
Now mystery of references are rewritten using schema references :
From $ref: ../../components/responses/index.yaml#/Unauthenticated
, the reference is changed to $ref: '#/components/responses/Unauthenticated'
in the bundled file.
And the Unauthenticated
is existing only in the #/components/responses
section.
from swagger-cli.
+1, very important feature. With --dereference
we unable to generate valid client specification.
There is no semantic names for schemas:
/random:
get:
summary: todo.
description: todo.
security:
- bearerAuth: []
responses:
'200':
description: Successful result.
content:
application/json:
schema:
type: object
required:
- categories
properties:
categories:
type: object
required:
- name
properties:
name:
type: string
from swagger-cli.
Would be great to have a solution for this!
Running into the same issue.
from swagger-cli.
+
from swagger-cli.
Looks related to APIDevTools/swagger-parser#127
from swagger-cli.
Related Issues (20)
- swagger-cli validation returns errors one by one
- invalid examples should not fail validation
- Dependabot warning for validator
- $ref bug resolving an existing folder HOT 1
- swagger-cli validate does not ensure unique operationIds
- Validate security keys against securitySchemes HOT 1
- Error: Token "Components" Does Not Exist HOT 6
- Combining multiple files can create circular references HOT 1
- Ref incorrect if path contains "{" or "}" HOT 1
- Bad error message on incorrect path provided
- Latest version of the CLI I'm getting the following error HOT 5
- bundle and validate commands are failing due to swagger-parser HOT 3
- Validation of composite keywords (anyOf, oneOf, allOf) HOT 1
- False positive: #/servers/0/variables/someParameter must NOT have unevaluated properties
- Undeclared parameters in server url should not validate
- Property examples are converted to the wrong date format
- The order of the directive changes between versions of the dependent package
- Combining multiple files into one keeps references to some api files HOT 1
- [BUG] String enum of '08' and '09 ' are wrong bundled HOT 1
- bundle removes quotes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swagger-cli.