We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The use of oneOf in a schema results in schema validation never failing despite json docs not matching schema. Here's a simplified example:
oneOf
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "OneOf Example", "type": "object", "properties": { "address": { "type": "string", "oneOf": [ { "format": "email" }, { "format": "hostname" } ] } }, "additionalProperties": false }
The shouldDetectValidJsonWithOneOfEmail and shouldDetectValidJsonWithOneOfHost test pass, but the shouldDetectInvalidJson test doesn't fail.
shouldDetectValidJsonWithOneOfEmail
shouldDetectValidJsonWithOneOfHost
shouldDetectInvalidJson
class OneOfSchemaValidationTest { ObjectMapper objectMapper = new ObjectMapper(); MedeiaJacksonApi api = new MedeiaJacksonApi(); SchemaValidator SCHEMA_VALIDATOR = loadSchema(); @Test void shouldDetectValidJsonWithOneOfEmail() throws IOException { String resource = "{ \"address\": \"test@test.com\" }"; JsonParser unvalidatedParser = objectMapper.getFactory().createParser(resource); JsonParser validatedParser = api.decorateJsonParser(SCHEMA_VALIDATOR, unvalidatedParser); OneOfExample oneOfExample = objectMapper.readValue(validatedParser, OneOfExample.class); assertEquals("test@test.com", oneOfExample.getAddress()); } @Test void shouldDetectValidJsonWithOneOfHost() throws IOException { String resource = "{ \"address\": \"127.0.0.1\" }"; JsonParser unvalidatedParser = objectMapper.getFactory().createParser(resource); JsonParser validatedParser = api.decorateJsonParser(SCHEMA_VALIDATOR, unvalidatedParser); OneOfExample oneOfExample = objectMapper.readValue(validatedParser, OneOfExample.class); assertEquals("127.0.0.1", oneOfExample.getAddress()); } @Test void shouldDetectInvalidJson() throws IOException { String resource = "{ \"address\": \"*******\" }"; JsonParser unvalidatedParser = objectMapper.getFactory().createParser(resource); JsonParser validatedParser = api.decorateJsonParser(SCHEMA_VALIDATOR, unvalidatedParser); assertThrows(ValidationFailedException.class, () -> objectMapper.readValue(validatedParser, OneOfExample.class)); } private SchemaValidator loadSchema() { SchemaSource source = new UrlSchemaSource( getClass().getResource("/patient/SimpleOneOfExample.schema.json")); return api.loadSchema(source); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The use of
oneOf
in a schema results in schema validation never failing despite json docs not matching schema. Here's a simplified example:Schema
Junit 5 Test
The
shouldDetectValidJsonWithOneOfEmail
andshouldDetectValidJsonWithOneOfHost
test pass, but theshouldDetectInvalidJson
test doesn't fail.The text was updated successfully, but these errors were encountered: