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

$ref points to id instead of file name #212

Closed
AlexTo opened this issue Aug 27, 2018 · 2 comments
Closed

$ref points to id instead of file name #212

AlexTo opened this issue Aug 27, 2018 · 2 comments

Comments

@AlexTo
Copy link

AlexTo commented Aug 27, 2018

Hi I need to validate my json with TinCan schema, the schema files can be found here TinCan Schema

when I validate my statement, I call schemaLoader.schemaJson(statementSchema), statementSchema comes from statement.json as folllows

`{    
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "#statement",
    "type": "object",
    "allOf": [{"$ref": "#statement_base"}],
    ....
}`

And this is statement_base.json

`{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "#statement_base",
    "type": "object",
    "required": ["actor", "verb", "object"],
    ....
}`

As you can see, statement.json references statement_base.json by id (#statement_base) not file name (statement_base.json)

Currently, my work around is to manually update all the $ref from #someid to someid.json and use resolutionScope and it seems to work.

But is it possible to resolve references without manually updating the $ref in all the files? Because each time TinCan releases a new version, I will need to go update them all again.

Previously, I used another library in Scala and what I could do was to "preloadSchema" like this

loader.preloadSchema(statementSchema) .preloadSchema(statementBaseSchema) .preloadSchema(activitySchema) ....

By doing so, the "loader" stores all the schemas with their id so that reference by id will just work, can I do something similar with this library?

Thanks a lot

@erosb
Copy link
Contributor

erosb commented Aug 31, 2018

Hello @AlexTo , do you know about any json schema implementation which can do it for you?
This request doesn't seem to be related to any sections of the json schema spec, and actually your problem can probably be worked around by generating one schema json including all the dependency schemas.

@AlexTo
Copy link
Author

AlexTo commented Sep 1, 2018

Hi @erosb this library does what I need https://github.com/eclipsesource/play-json-schema-validator

So for e.g. I can preload a schema like this

       `loader.preloadSchema("#ref1_id", jsonObj1LoadedFromFile)
              .preloadSchema("#ref2_id", jsonObj2LoadedFromFile)`

And later on, If I call loader.validate(myschema, jsonObj) where myschema references $ref: #ref1_id and $ref: #ref2_id then it will work because the loader has preloaded the references with their ids.

However, due to business decision, we are switching from Play Framework to Spring so I need to find some Java libraries instead. At the moment, my work around is to manually update all #ref1_id etc... to ref1_id.json and use resolutionScope and it works fine.

I was just wondering if this library can do the same but for now I will just go with the work around.

@erosb erosb closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants