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

Provide a test spec that reproduces the problem described in #1087 #1088

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/test/java/com/networknt/schema/Issue1087Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.io.InputStream;

class Issue1087Test {
protected JsonSchema getJsonSchemaFromStreamContent(InputStream schemaContent) throws Exception {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012);
YAMLMapper mapper = new YAMLMapper();
JsonNode node = mapper.readTree(schemaContent);
return factory.getSchema(node, SchemaValidatorsConfig.builder().discriminatorKeywordEnabled(true).build());
}

protected JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception {
ObjectMapper mapper = new ObjectMapper();
return mapper.readTree(content);
}

@Test
void shouldHandleReferencesToYaml() throws Exception {
String schemaPath = "/schema/issue1087.yml";
String dataPath = "/data/issue1087.json";
InputStream schemaInputStream = getClass().getResourceAsStream(schemaPath);
JsonSchema schema = getJsonSchemaFromStreamContent(schemaInputStream);
InputStream dataInputStream = getClass().getResourceAsStream(dataPath);
JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
MatcherAssert.assertThat(schema.validate(node), Matchers.empty());
}
}
3 changes: 3 additions & 0 deletions src/test/resources/data/issue1087.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"kind": "A"
}
2 changes: 1 addition & 1 deletion src/test/resources/data/issue668.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"sub1": {},
"sub2": {},
"sub3": {}
}
}
24 changes: 24 additions & 0 deletions src/test/resources/schema/issue1087.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$id: resource:/schema/issue1087
$defs:
TypeA:
type: object
required:
- kind
properties:
kind:
type: string
TypeB:
type: object
required:
- kind
properties:
kind:
type: string
oneOf:
- $ref: "#/$defs/TypeA"
- $ref: "#/$defs/TypeB"
discriminator:
propertyName: kind
mapping:
A: "#/$defs/TypeA"
B: "#/$defs/TypeB"