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

JSON Schema links #80

Closed
ghost opened this issue Feb 3, 2014 · 12 comments
Closed

JSON Schema links #80

ghost opened this issue Feb 3, 2014 · 12 comments

Comments

@ghost
Copy link

ghost commented Feb 3, 2014

Hello,

I'm using your library and i'm looking for how to deal with "links" keywords in my JSON Schema.
This links keyword is DRAFT V4 compliant, however a warning is thrown :

warning: the following keywords are unknown and will be ignored: [links]
level: "warning"
schema: {"loadingURI":"#","pointer":""}
domain: "syntax"
ignored: ["links"]

Please can anyone help?

@fge
Copy link
Collaborator

fge commented Feb 8, 2014

Hello,

Which version are you using?

@ghost
Copy link
Author

ghost commented Feb 20, 2014

Hello I'm currently using version 2.0.1

@fge
Copy link
Collaborator

fge commented Feb 20, 2014

Ah, that explains it.

Syntax support, by default in 2.0.x, only covers validation, not the hyperschema. Therefore syntax checking for links is not supported.

In 2.1.x, it is supported, although not completely: draft v3 is not supported, and draft v4 href is valid only as long as they are "true" URI templates, as the RFC defines them (see https://github.com/fge/uri-template).

It is possible to backport this to 2.0.x, but the cost is heavy; and in any case, link generation is not supported. How much do you care about links syntax validation?

@ghost
Copy link
Author

ghost commented Feb 20, 2014

Thanks for the explanation.
Is it possible to remove the warning message from the report?

@fge
Copy link
Collaborator

fge commented Feb 20, 2014

It is, but there is a preliminary condition to this: do you have a $schema declared into your schemas?

@ghost
Copy link
Author

ghost commented Feb 20, 2014

Yes I do my json schema is valid. I have declared it.
I want also remove the warning message for readOnly which is also included

@fge
Copy link
Collaborator

fge commented Feb 20, 2014

OK, that may be part of the problem here; what is $schema set to?

@ghost
Copy link
Author

ghost commented Feb 20, 2014

Here is the URL provided: http://json-schema.org/draft-04/hyper-schema#

@fge
Copy link
Collaborator

fge commented Feb 20, 2014

Hmm, OK, this can be viewed as a bug. In 2.0.x as well as in 2.1.x.

In both of these versions, when an unknown $schema is encountered, the default schema will be whatever is configured to be the default schema. In your case, that will be http://json-schema.org/draft-04/schema#, and the keywords defined by that schema. And there are no hyperschema validation keywords in there...

Working around this will require quite some amount of code. Here is how...

Step 1: define a new keyword for links:

final Keyword links = Keyword.newBuilder("links")
    .withSyntaxChecker(new SyntaxChecker()
    {
        @Override
        public void checkSyntax(final Collection<JsonPointer> pointers,
            final ProcessingReport report, final SchemaTree tree)
        {
        }
    }).freeze();

Step 2: build a new library based on draft v4, change the $schema of that library and add the new keyword:

// see above for "links"
final Library customLibrary = DraftV4Library.get().thaw()
    .addKeyword(links).freeze();

Step 3: create a new ValidationConfiguration, add this library to it:

final ValidationConfiguration cfg = ValidationConfiguration.newBuilder()
    .setDefaultLibrary("http://json-schema.org/draft-04/hyper-schema#", customLibrary)
    .build();

Step 4: build your JsonSchemaFactory using this library:

final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder()
    .setValidationConfiguration(cfg).build();

You can then use this factory to create your JsonSchemas and the warnings should no longer appear.

@fge
Copy link
Collaborator

fge commented Apr 8, 2014

Closing this one. Hyper schema syntax validation (only syntax validation) will be in 2.2.

@fge fge closed this as completed Apr 8, 2014
@Philzen
Copy link

Philzen commented Jul 24, 2014

Hi @fge,

really enjoy discovering the project but i'm slightly confused: I'm am getting exactly the error described when testing on http://json-schema-validator.herokuapp.com/

readme.md states version 2.2.5 is current - while the latest git tag is at 2.2.4 - and i'm struggling to any the version number under the demo link... so is this still an open bug in 2.2 or is the deployment just running an older version?

Loki-Afro added a commit to Loki-Afro/json-schema-validator that referenced this issue Aug 10, 2016
daveclayton pushed a commit that referenced this issue Oct 7, 2016
@muditsri
Copy link

muditsri commented Jan 13, 2018

I am using version: 2.3.8 but still getting warnings: warning: the following keywords are unknown and will be ignored: [elementName]

What i did: Had the XSD, which i converted into JsonSchema, and i believe this conversion is an issue.
Does anyone have idea on how to convert XSD to JsonSchema, so that its supported in version 2.3.8

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

3 participants