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

Incompatibility of RFCs concerning URI formatting #455

Open
testower opened this issue Apr 21, 2022 · 2 comments
Open

Incompatibility of RFCs concerning URI formatting #455

testower opened this issue Apr 21, 2022 · 2 comments

Comments

@testower
Copy link

testower commented Apr 21, 2022

JSON schema string format uri uses https://tools.ietf.org/html/rfc3986 which allows an empty authority, but the java type java.net.URI uses the obsolete https://tools.ietf.org/html/rfc2396 which does not allow it. For example, android and ios discovery uris fails validation:

{
  "discoveryUri": "com.example.ios://"
}

Schema:

{
  "$schema": "http://json-schema.org/draft-2020-12/schema",
  "type": "object",
  "properties": {
    "uri": {
      "type": "string",
       "format": "uri"
    }
  }
}

Trying to validate this gives the following:

[com.example.ios://] is not a valid URI

I have asked a similar question here: joelittlejohn/jsonschema2pojo#1236 and the answer was that this is the best we can do given the state of the Java URI native class.

Would it be the same here? Is the solution to implement a custom format validator, or should this be fixed in the lib?

Naïve fix:

    @Override
    public Optional<String> validate(String subject) {
        try {
            new URI(subject);
            return Optional.empty();
        } catch (URISyntaxException e) {
            if (e.getReason().equalsIgnoreCase("expected authority")) {
                return Optional.empty();
            }
        }
        return Optional.of("Invalid URI");
    }
@erosb
Copy link
Contributor

erosb commented Apr 21, 2022

Hello, if you plan to raise a PR with a standard-compliant URI format validator then I don't mind merging it, but I don't plan to fix this issue on my own.

@testower
Copy link
Author

No problem, I understand. I think I will go with the naïve fix in an override for now 👍

testower added a commit to entur/gbfs-validator-java that referenced this issue Apr 21, 2022
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