Closed jharmn closed 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?
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;
}
@jasonh-n-austin Did you have a chance to test my patch?
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 :)
@jasonh-n-austin Thanks. P.S. Build was broken before your changes, I just fixed it on weekends.
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.
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.convert()
to accept a second optional param,options
.options.refsToDefinitions: true
will runfixRef
on all references (default: true). Backward compatible with current interface.options.refsToDefinitions: false
leaves$ref
s as-is.