public final class URITranslatorConfigurationBuilder extends Object implements com.github.fge.Thawed<URITranslatorConfiguration>
URITranslatorConfiguration
Example:
final URITranslatorConfiguration cfg = URITranslatorConfiguration.newBuilder() .setNamespace("http://my.site/myschemas/") .addPathRedirect("http://my.site/myschemas/", "resource:/com/foo/myschemas") .addSchemaRedirect("http://some.other.site/schema.json", "resource:/com/foo/externalsite/schema.json") .freeze();
When feeding this configuration into a LoadingConfiguration
(using LoadingConfigurationBuilder.setURITranslatorConfiguration(URITranslatorConfiguration)
),
the following will take place for URI schema1.json#/definitions/def1
:
http://my.site/myschemas/schema1.json#/definitions/def1
;SchemaLoader
will then be resource:/com/foo/myschemas/schema1.json#/definitions/def1
.If URI http://some.other.site/schema.json#bar
is encountered,
a schema redirect triggers and will yield URI resource:/com/foo/externalsite/schema.json#bar
.
Modifier and Type | Method and Description |
---|---|
URITranslatorConfigurationBuilder |
addPathRedirect(String from,
String to)
Convenience method for adding a path URI redirection
|
URITranslatorConfigurationBuilder |
addPathRedirect(URI from,
URI to)
Add a path redirection
|
URITranslatorConfigurationBuilder |
addSchemaRedirect(String from,
String to)
Convenience method for schema redirections
|
URITranslatorConfigurationBuilder |
addSchemaRedirect(URI from,
URI to)
Add a schema redirection
|
URITranslatorConfiguration |
freeze()
Obtain a frozen configuration from this builder
|
URITranslatorConfigurationBuilder |
setNamespace(String uri)
Set the namespace for this configuration (convenience method)
|
URITranslatorConfigurationBuilder |
setNamespace(URI uri)
Set the namespace for this configuration
|
public URITranslatorConfigurationBuilder setNamespace(URI uri)
All schema loading via URIs (using SchemaLoader.get(URI)
or
when encountering a JSON Reference in a schema) will be resolved against
the provided namespace.
uri
- the URINullPointerException
- URI is nullIllegalArgumentException
- URI is not absolute, or is not a path
URI (ie, does not end with /
)public URITranslatorConfigurationBuilder setNamespace(String uri)
This calls setNamespace(URI)
after creating the URI using
URI.create(String)
.
uri
- the URINullPointerException
- argument is nullIllegalArgumentException
- URI.create(String)
failedsetNamespace(URI)
public URITranslatorConfigurationBuilder addSchemaRedirect(URI from, URI to)
Schema redirection occurs after namespace resolution and after path redirection.
from
- the URI to redirect fromto
- the URI to redirect toNullPointerException
- one, or both, argument(s) is/are nullIllegalArgumentException
- one, or both, URI(s) are not absolute
JSON References; or a redirection already exists for URI from
; or
from
and to
are the same URI after normalization.public URITranslatorConfigurationBuilder addSchemaRedirect(String from, String to)
This calls addSchemaRedirect(URI, URI)
after converting its
string arguments to URIs using URI.create(String)
.
from
- the URI to redirect fromto
- the URI to redirect toNullPointerException
- one, or both, argument(s) is/are nullIllegalArgumentException
- URI.create(String)
failed for
one or both argument(s)public URITranslatorConfigurationBuilder addPathRedirect(URI from, URI to)
What is called a "path URI" here is a URI which is absolute,
hierarchical, has no fragment part and whose path component ends with a
/
.
from
- the "path URI" to redirectto
- the target "path URI"NullPointerException
- one, or both, argument(s) is/are nullIllegalArgumentException
- one, or both, argument(s) is/are not
valid path URIs; or a path redirection already exists for from
;
or from
and to
are the same URI after normalization.public URITranslatorConfigurationBuilder addPathRedirect(String from, String to)
This calls addPathRedirect(URI, URI)
after performing URI.create(String)
on both arguments.
from
- the "path URI" to redirectto
- the target "path URI"NullPointerException
- one, or both, argument(s) is/are nullIllegalArgumentException
- URI.create(String)
failedaddPathRedirect(URI, URI)
public URITranslatorConfiguration freeze()
freeze
in interface com.github.fge.Thawed<URITranslatorConfiguration>
URITranslatorConfiguration
Copyright © 2016. All rights reserved.