-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Support for multiple $refs inside a single object #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Swagger spec, define '$ref' as follows: References used through entire spec and most importantly inside Schema object. Another problem is how you would handle merge conflicts? But I totally support your idea about allowing to split paths into separate files. paths:
/pets:
$ref: "/operations/pets.yaml" # Multiple paths
/stores:
$ref: "/operations/stores.yaml" # Multiple paths
/users:
$ref: "/operations/users.yaml" # Multiple paths And 'pets.yaml' will looks like this: post:
# ...
/findByStatus:
get:
# ... @glen-84 Is this proposal will solve your problem? P.S. It could also solve |
It's quite surprising to me that the existing standards don't support this. I don't suppose this is likely to change? As for merge conflicts, if I create two equal paths with the Swagger editor, it just uses the last one. It could be the same, or it could be a setting if you want it to throw an error. Nested paths might be an option, although it feels a bit weird having the nested paths at the same level as post/get etc. Could paths:
allOf:
- $ref: "/operations/pets.yaml"
- $ref: "/operations/stores.yaml"
- /users:
get:
# ... ... that may be completely incorrect or make no sense – I don't know very much about JSON schema. 😄 |
In any case it should be changes to
No, 'allOf' supported only inside |
Samples for swagger-js/OAI#417: Separated files, yaml only for now
+1 for adding |
+1 I am looking for any work around right now for allowing path urls and their subsequent path objects to be defined in multiple external files. Does anyone have any suggestions? |
@wannabesrevenge I'm currently using something like this: paths:
# Blogs
# -- Blogs
/blogs:
$ref: "operations/blogs/blogs.yaml#/Blogs"
/blogs/{id}:
$ref: "operations/blogs/blogs.yaml#/Blog"
# -- Blog Posts
/blogs/{id}/posts:
$ref: "operations/blogs/blog-posts.yaml#/BlogPosts"
/blogs/posts/{id}:
$ref: "operations/blogs/blog-posts.yaml#/BlogPost"
/blogs/posts/{id}/comments:
$ref: "operations/blogs/blog-posts.yaml#/BlogPostComments" I don't think it's possible to move the actual paths to separate files. |
That's a shame. I'm hoping that "merge" in JSON schema v5 (i think it's v5) will help. I settled for doing this the same way as you. In one way it's nice because its explicit, but it is definitely not completely DRY in principle. Now if we add a route to one microservice api, we must also add the route to the master api. |
+1 for supporting recursive structure for paths |
+1 need this |
+1 |
👍 for this appraoch:
It's simple and easy to understand. @IvanGoncharov: I could think of a couple ways to resolve conflicts. Apologies if I'm missing something large here, but it seems like you could do something like this:
|
@LandonSchropp I agree. Would pleasantly mimic familiar
|
Folks, I'm afraid you are pitching to the wrong people. OpenAPI uses $ref as it is defined by JSON Schema. If you want $ref 's behavior to be changed, you need to convince the JSON Schema folks to change it. The alternative is to define a completely new re-use mechanism so there is no confusion between reuse within JSON Schemas and reuse elsewhere. |
FWIW, JSON References (and JSON Pointers) are actually not part of JSON Schema, but JSON Schema uses them. They were both originally written by the same people (iirc), but that doesn't mean the current JSON Schema folks actually maintain JSON Reference as well, but we'll see their response. |
@webron You are correct that there is a distinct spec for JSON Reference, but for some reason the wording describing $ref was duplicated in the JSON Schema spec https://tools.ietf.org/html/draft-wright-json-schema-00#section-7 which leaves us in an ambiguous state. Considering there are people actually working on the JSON Schema now, it might actually be the best place to get change to happen. |
@darrelmiller - right, only you're not looking at draft 4 which is our official reference for the spec, where JSON References explicitly point to JSON Reference. Of course, hopefully by the time official word on the next draft/version of JSON Schema is out, it will be clarified better than what you've shown. And who knows, maybe we'll drop JSON Schema and move to something... better. |
@webron there is nothing better, there are no known valid problems with JSON schema 😆 |
@glen-84 can you explain how your abovementioned solution works?
when i try to replicate it, it always inserts "Blogs" node below the /blogs
|
Are you using the The target file should be structured as follows: Blogs:
get:
summary: Get a list of blogs
tags:
- Blogs
responses:
etc. I'm using swagger-parser (v3.4.1) to dereference the file. |
Yes, I tried to replicate your example fully, just to see how it goes. |
Most likely, yes. I may have started using swagger-parser because of apigee-127/swagger-tools#227. |
After reading through the entire conversation it looks like we do not have any way to do something similar to this or any variation similar to the below
Please correct me if I am wrong. How are other folks serving a single yml file which serves multiple paths spread across children ymls? |
@rayarikar in my case I'm using the discriminator object; for merging values the one I'm using is components:
schemas:
First:
type: object
items:
first:
type: string
Second:
type: object
items:
second:
type: string
paths:
/:
post:
requestBody:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/First'
- $ref: '#/components/schemas/Second' |
You mean |
|
Would YAML’s own pointers solve your issue? I’m not sure how merging happens though but that could be a solution usable today |
Who are you asking to? BTW, I don't think that using a file format specific solution is a good idea here when OpenAPI spec allows other file formats (like json). |
This does it https://github.com/WindomZ/swagger-merger . Would love to see this type of support in the official tooling example: paths:
/path1:
$ref: https://someurl/openapi.yaml
/path2:
$ref: https://someurl2/openapi.json |
@chrisdostert The example you are showing is actually valid OpenAPI. This is a exceptional usage of $ref in the PathItemObject where However, this only allows referencing a single path at a time. There is no way to reference a document that contains a set of paths. |
@glen-84 I suggest building a file using command line toolkit that links multiple YAML files with $include tag. Look this https://github.com/javanile/yamlinc add-in project task using gulp or grunt. Any considerations @IvanGoncharov @kulkarniankita @wannabesrevenge @BabuGiri |
This is working fine for me
|
@waseem-khan-dev yes, that works fine in the Schema Object, but this was reported against the Path Object where @webron @MikeRalphson @whitlockjc this is another Path Object It will definitely not be further addressed in JSON Schema, because |
Why not use arrays?
Path Item Object With Path
...
paths:
- $ref: "/pets.yaml"
- $ref: "/users.yaml"
- path: /stores
post:
...
... |
It's 2021, and we still don't have a solution for this problem. |
Maybe this will be useful for you!
|
As stated by #417 (comment) this applies to |
Add short documentation on how to generate the desired files. Small fix to make operationId unique
3 months until 2024 and we still do not have it ... |
@asarra most attention now is on OAS 4 (a.k.a. "Moonwalk") which will address this sort of problem more thoroughly. |
Ty that's good to read |
Where can we read the current draft of OAS 4? I couldn't seem to find it myself. Edit: Found it. "moonwalk" was the missing keyword in my search. |
Closing as "moved to moonwalk" which was already the conclusion in the last few comments. |
It would be really useful to be able to do something like this:
Where each file includes multiple paths. For example (pets.yaml):
This would make it easier to organize a large API.
Edit:
It could also be an array, like this:
The text was updated successfully, but these errors were encountered: