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

Fields with format "uri" and pattern specifying a schema result in type java.net.URL #918

Conversation

jrehwaldt
Copy link
Contributor

@jrehwaldt jrehwaldt commented Sep 17, 2018

A field spec'ed as follows {"type": "string", "format": "uri", "pattern": "https?://..." } derives the type java.net.URL.

Fixes gh-910, depends on gh-917 and is a breaking change (API and resulting generation).

This is required in order to implement context-aware rules, e.g. such as joelittlejohngh-910.
@jrehwaldt jrehwaldt force-pushed the derive-url-from-uri-and-pattern branch from 72c4944 to 6d6a376 Compare September 17, 2018 10:29
… type java.net.URL

A field is spec'ed as follows {"type": "string", "format": "uri", "pattern": "https?://..." }
derives the type is java.net.URL.
@joelittlejohn
Copy link
Owner

I don't think I can merge this one I'm afraid, though thank you for sharing the code for others to see.

You have your own definition of a URL here that is not exhaustive. URLs do not need to match https?://. Java supports http, https, ftp, file, and jar but additional stream handlers can be specified. Which of these should lead to URL being used? I understand that you are trying to restrict the allowable values further than java.net.URI, but this isn't generalisable into jsonschema2pojo in the way that you have defined it here IMO.

You can of course solve this by using javaType.

@jrehwaldt
Copy link
Contributor Author

Fair enough. That's why I opened an issue about this exact situation a week ago.

I understand the list is not exhaustive, but it doesn't invalidate the implementation. If at all, it makes it incomplete.

Actually, I didn't expect it to be merged, but figured it would make sense to propose to change the Rule API before you release 1.0.0, because as it stands context-aware rules are not possible. Maybe I have luck with this one...

@jrehwaldt
Copy link
Contributor Author

What about a schema-neutral implementation checking for something like this ...://...?

The pattern is not perfect, but relatively exhaustive considering the restrictions
on URL schema names. Complex nested patterns will *not* result in URL type, e.g.:
* `(uri://|foo://|bar://).+`
* `(uri(abc)?)://.+`
@jrehwaldt jrehwaldt changed the title Fields with format "uri" and pattern starting with "https?://" result in type java.net.URL Fields with format "uri" and pattern specifying a schema result in type java.net.URL Sep 17, 2018
@jrehwaldt
Copy link
Contributor Author

I generalized it . Feel free to close if undesired nonetheless.

@joelittlejohn
Copy link
Owner

I'm going to close this in favour of #923.

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

Successfully merging this pull request may close these issues.

2 participants