-
Notifications
You must be signed in to change notification settings - Fork 52
Resolution of jsonschema $ref's #481
Comments
I see the Project class of jsyaml2lowlevel has some methods that look like they do what I want - keeping track of resolution scope as it relates to the location of the raml document and referring documents. For example, the resolve() method of the Project class: https://github.com/raml-org/raml-js-parser-2/blob/master/src/raml1/jsyaml/jsyaml2lowLevel.ts#L761 I see also the unit method of Project class calls startDownloadingReferencesAsync from https://github.com/raml-org/raml-js-parser-2/blob/master/src/util/schemaAsync.ts If I have a BodyLike object with a schema, https://raml-org.github.io/raml-js-parser-2/interfaces/_src_raml1_artifacts_raml08parserapi_.bodylike.html, how can I resolve the $ref's in this schema? |
I am looking to implement this behavior in https://github.com/cybertk/abao , so that it parses references the same as the api-workbench, specifically $ref's that are relative paths to the local filesystem. Abao is an important part of the raml ecosystem and having it parse $ref's the same as the api-workbench would be a big step forward, especially since the PR to abao for this will also upgrade abao to using raml-1-parser, paving the way for RAML 1.0 support in the tool. Any help here very much appreciated |
I would also love for this feature to be implemented, it's very complicated to parse JSON schema's based on the parser output since I don't know their original location and as such cannot resolve relative $ref's. Is there anything I can do to help development of this feature? |
My question would be around how the parser should handle references by default. Should it resolve it immediately or give you some options to do that? How should that look like and from your perspective and how would you envision to use it? |
Obviously, it isn't the job of a parser to do such kind of things. So I'd really like to understand the use case for resolving the $refs inside the parser vs retrieving the schema and use any dereference module available for JSON schemas. |
Currently, when I ask for types or schema's I get a name, displayName and "type" containing the actual JSON schema:
As you can see, the actual schema contains a $ref entry, but I have no idea where the 'definitions.json' file is located, since I don't know from where this was included. Because of this I am unable to dereference it myself. A more complex example: in my spec.raml file, I have the following (snipped):
payment/CreatePaymentRequest.json The output from the parser is as follows:
As you can see, the output from the parser contains $refs to both I would like it if the parser did one of the following:
For me, it would obviously be less work if the parser already dereferenced the schema for me, I understand if that would be out of scope, but providing me with the path would be helpful. |
@sichvoge The use case for involving the RAML parser in $ref resolution is so that when a jsonschema is loaded with "!include" the directory of the "!include" path is used as the initial resolution scope. It would be a convenience to prevent the caller from inspecting the RAML AST, getting the directory, and passing it to the ref resolver. The ref resolver also needs to track the resolution scope and resolve nested $refs relative to the referring document, and not the initial scope of the !include directory. This is the behavior I see in the api-workbench, I haven't been able to nail down how exactly they're resolving $refs, I think it involves the functions in raml-js-parser-2 I linked to in my initial comment. https://github.com/mulesoft/api-workbench/issues/314 |
@ddenisenko can you add more clarifications here, and maybe an explicit example on how you dereference JSON refs? What's our opinion about the parser is dereferencing refs in JSON schemas vs providing enough information so you can put something on top of the parser output? I think @cascer1 got a very valid example. |
@ddenisenko can you create necessary issues for that please. we can them into one of our sprints at some point. |
Is there an indication of when I can expect the path to the schema (or fully dereferenced schema) in the parser? |
SchemaPath property is added for types that was loaded from JSON or XML schema files. Example part of parser output:
Also , "dereference(schemaPath, jsonReference)" function was added in /raml-js-parser-2/src/schema.ts. Example: schema.dereference("/my/favorite/schema.json", "../another/schema.json#/definitions/myType"); output is: "/my/another/schema.json#/definitions/myType" |
Does raml-js-parser-2 provide an interface for resolving jsonschema $ref's? Specifically I would like to resolve references against the local filesystem, relative to the path of the referring schema. I see this is implemented in the api-workbench and I see code in raml-js-parser-2 to deal with references, but I'm not sure which function I could call to resolve them.
The text was updated successfully, but these errors were encountered: