swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.94k stars 2.26k forks source link

Import definitions from another API using Online Swagger Editor #1531

Closed dantebarba closed 7 years ago

dantebarba commented 7 years ago

I can't manage to import Swagger definitions from another (same API version) swagger project on the Swagger Online editor. For example, I have a PetStore API and a GroceryStore API. Both have some definitions in common such as Cashier. How can I reference this common definition from GroceryStore to PetStore. Im using Swagger 2.0, is it possible. Thanks.

webron commented 7 years ago

You can have references to external files, but those would only work if those files are hosted. You can't edit multiple files with the editor.

shockey commented 7 years ago

Here are some docs that cover how to make remote references in Swagger/OpenAPI: https://swagger.io/docs/specification/using-ref/

dantebarba commented 7 years ago

@webron I'm currently using the online editor and there is no way to reference external files. I'm switching to the local editor, and I will push my project on github so I can reference yaml files directly.

dantebarba commented 7 years ago

I managed to reference from the online editor using absolute path for example: $ref: "https://raw.githubusercontent.com/....../commons.json#/definitions/Error"

Using the online editor I can't clone my github project and use relative paths to resolve the definitions. How can I use the editor (online or offline) and step into the project root folder?.

Is there any way to have something like this: $ref: "commons/commons.json#/definitions/Error" and the editor being able to resolve it.

Something like a global variable to establish "project_home_url" or "project_root_url".


When I try to push the swagger definition which has references to external files I get the following error from swagger: The 'GitHub Sync' plugin failed with the following error: Unable to save definition

This doesn't happen with definitions that don't have references to external files.

webron commented 7 years ago

@dantebarba are you using the online editor at http://editor.swagger.io or do you use swaggerhub.com?

dantebarba commented 7 years ago

Swaggerhub. I contacted support and they recommended to use domains. I added my common definitions in my domain, I reference them, try to push to github, but fails. Support said that they will look into, looks like a bug on the integration.

webron commented 7 years ago

Okay, in that case, please continue using the SwaggerHub's support for any further issues with it. They use modified versions of the open source version and are better equipped to provide you with the answers you'd need.