Skip to content
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

Add possibility to specify location when you pass object #13

Closed
IvanGoncharov opened this issue Feb 29, 2016 · 9 comments
Closed

Add possibility to specify location when you pass object #13

IvanGoncharov opened this issue Feb 29, 2016 · 9 comments

Comments

@IvanGoncharov
Copy link

If you pass object it's impossible to resolve external relative references.
It would be cool if I can add option where I can specify base path for relative refs.

@JamesMessinger
Copy link
Member

I like this idea. Will add it soon

@litek
Copy link

litek commented Apr 20, 2016

My current workaround is to just change working directory with process.chdir before resolving, then changing it back afterwards.

@alvassin
Copy link

+1. @BigstickCarpet Any progress on this?

@alvassin
Copy link

@litek workaround with changing working directory will not work if you deal with URLs (referenced issue).

@JamesMessinger
Copy link
Member

alright. I'll get this knocked out this weekend

JamesMessinger added a commit that referenced this issue Apr 25, 2016
JamesMessinger added a commit to APIDevTools/swagger-parser that referenced this issue Apr 25, 2016
@JamesMessinger
Copy link
Member

As of version 3.1.1, you can now pass a URL and an object to any method.

$RefParser.dereference("http://example.com/my-schema.json", mySchemaObject, {})

NOTE: As shown in the example above, you must also pass an options object (even an empty object will work), otherwise, the method signature looks like you're just passing a URL and options.

@alvassin
Copy link

alvassin commented Apr 25, 2016

@BigstickCarpet thanks a lot for feature, but there is a bug: paths begin to duplicate (i pass dereferenced.raml file here, because schema is defined inside it and its path is relative to raml):

schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "items": {
      "$ref": "schemas/item.json"
    }
  }
}

deferred = @q.defer()
require('json-schema-ref-parser').dereference(
    'test/raml-files/deferenced.raml', schema, {}
  )
  .then((dereferencedSchema) ->
    deferred.resolve(JSON.stringify(dereferencedSchema))
  )
  .catch((err) ->
    deferred.reject(err)
  )

I'll get following error:

Error: Error resolving $ref pointer "test/raml-files/test/raml-files/schemas/item.json".
"test/raml-files/test/raml-files/schemas/item.json" not found.

Path seems to be duplicated here.

@JamesMessinger
Copy link
Member

@alvassin - Good catch. I had forgotten to account for relative URLs. In all my tests, I was passing absolute URLs. Anyway, it's fixed now. Try the latest version

@alvassin
Copy link

@BigstickCarpet yeeeah! it works! thanks for super-fast fix, much appreciated 🍺

JamesMessinger added a commit that referenced this issue Apr 28, 2016
* master:
  "release v3.1.2"
  Added tests for Issue #13
  Object paths weren't being converted to absolute URLs #13 (comment)
  "release v3.1.1"
  Revert "Removed the external-facing YAML object. All methods will now allow a YAML string to be passed-in instead"
  "release v3.1.0"
  updated dependencies
  Fixed Issue #13 (#13)

Conflicts:
	lib/bundle.js
	lib/index.js
	lib/resolve-external.js
	package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants