APIs-guru / google-discovery-to-swagger

Script for converting Google Discovery format into OpenAPI (swagger) 3.0
MIT License
59 stars 17 forks source link

Adding option to skip fixRef #4

Closed jharmn closed 9 years ago

jharmn commented 9 years ago

There are many cases when external schema files are used, where using fixRef is inappropriate (and mangles $ref pointing to external schema files. Swagger 2 supports external refs (at least in the spec, if not mixed in lib support). See swagger-parser for a great example.

IvanGoncharov commented 9 years ago

@jasonh-n-austin Thank you for PR. I never expect anyone outside of Google to use this format, so I based my converter solely on Google specs. Can you make example spec with external refs and I will add it to test suite?

Can external refs be automatically detected? I don't like idea of global switch and if possible prefer to detect them. Can presence of / symbol be such criteria?

IvanGoncharov commented 9 years ago

I tested solution with slash detection and it doesn't brake compatibility with Google specs. @jasonh-n-austin Can you test following patch:

diff --git a/src/index.js b/src/index.js
index 076006d..6a263de 100644
--- a/src/index.js
+++ b/src/index.js
@@ -94,6 +94,8 @@ function processGlobalParameters(parameters, srGlobalRefParameters) {
 }

 function fixRef(ref) {
+  if (ref.indexOf('/') !== -1)
+    return ref;
   return '#/definitions/' + ref;
 }
IvanGoncharov commented 9 years ago

@jasonh-n-austin Did you have a chance to test my patch?

jharmn commented 9 years ago

Sorry didn't get the GH notifications on this. I'll take a look at it by the end of the week. I hadn't realized tests were breaking, I just pushed this up on my way out the door on an "open dev" day. Yes, shockingly there are a handful of things using GDD still. Trying to help move them forward :)

IvanGoncharov commented 9 years ago

@jasonh-n-austin Thanks. P.S. Build was broken before your changes, I just fixed it on weekends.

jharmn commented 9 years ago

Slash detection wouldn't help here. If the schema file is in the same directory, there's nothing leading. Example:

"request": {
  "$ref":"resource.json"
},

Thinking about it more: if we detect if $ref's value contains .json, that would probably do the trick. Closing this, will open another PR.