-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
How to specify $ref base url? #20
Comments
I've just realized that I can pass a url to the schema to resolve, in which case the $refs are resolved correctly, but yet this is not what I want. I pull the schema using AngularJs |
Here is an example of schema passed to refParser:
|
Sorry I didn't get a chance to respond yesterday, but it looks like you've discovered what I was going to say anyway. The trick is to pass the URL that you want (in your case |
Same problem here. I get this error /** this file is located under /node/api/models/openapi-model.json and refs
* are located under refs of the same directory. e.g. /node/api/models/refs/parameters/json
* app.js is located under node folder /node/app.js, which uses json-schema-ref-parser to load
* the json file as this jsonRefs.dereference('./api/models/openapi-model.json')
**/
{
"resources": {
"collection": {
"description": "A collection of Accounts.",
"parameters": [
{
"$ref": "./refs/parameters.json#/common/collection"
},
{
"in": "query",
"name": "customer",
"description": "Only include customers (stage 6 in SFDC)",
"required": false,
"type": "boolean"
}
]
}
}
} The only way to workaround this issue is to move my refs directory to the current working directory or essentially, the root directory of my Node.js app, which I'm trying to avoid as it breaks a component-based structure. I'm also trying to avoid http protocol to fetch those files. It'd be great if as part of the options, there was a way to specify a relative base. BTW - Love the project! |
@dzuluaga - See my reply above. You can specify the base URL as a parameter. |
Awesome @BigstickCarpet. It was a bit cryptic ;). But finally worked. Issue #13 gave me the clues. Here's my version of the above. return $RefParser.dereference('./api/models/', './api/models/openapi-model.json', {})
.then(function(dmResolved) {
debug('data model resolved', dmResolved);
return dmResolved;
}) |
I serve a frontend locally with node at
localhost:8000
. I pull the json schema from an API.The backend returning the json schema seats at
localhost:8888
(http:https://127.0.0.1:8888/api/controllers/schema
).The schema has arrays of
$ref
fields in form of relative urls :var schema = [{$ref:"/api/controllers/123"},{...}]
.json-schema-ref-parser resolves references relatively to the frontend url rather than the backend url.
$RefParser.resolve(schema);
throws the following errors:request.js:114 GET http:https://localhost:8000/api/controllers/123 404 (Not Found)
index.js:67 Uncaught (in promise) Error: Error downloading http:https://localhost:8000/api/controllers/123
.How can I pass
localhost:8888
to resolve as base url?The text was updated successfully, but these errors were encountered: