Skip to content

Commit

Permalink
showcase issue 673
Browse files Browse the repository at this point in the history
  • Loading branch information
bweben committed Apr 17, 2023
1 parent dcc76e4 commit 6156abd
Show file tree
Hide file tree
Showing 3 changed files with 1,286 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/com/networknt/schema/Issue673Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.networknt.schema;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Issue673Test {
private static JsonSchema schema;

@BeforeAll
static void init() {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012);
String schemaPath = "/schema/issue673-openapi-schema.json";
InputStream schemaInputStream = Issue673Test.class.getResourceAsStream(schemaPath);
schema = factory.getSchema(schemaInputStream);
}

@Test
void testInvalidTimeRepresentations() throws IOException {
String validationPath = "/schema/issue673-validation.json";
Set<ValidationMessage> errors = schema.validate(new ObjectMapper().readTree(Issue673Test.class.getResourceAsStream(validationPath)));

System.out.println(errors.stream().map(ValidationMessage::getMessage).collect(Collectors.joining("\n")));

Assertions.assertTrue(errors.isEmpty());
}
}
23 changes: 23 additions & 0 deletions src/test/resources/schema/issue673-openapi-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$id": "https://spec.openapis.org/oas/3.1/schema-base/2022-10-07",
"$schema": "https://json-schema.org/draft/2020-12/schema",

"description": "The description of OpenAPI v3.1.x documents using the OpenAPI JSON Schema dialect, as defined by https://spec.openapis.org/oas/v3.1.0",

"$ref": "https://spec.openapis.org/oas/3.1/schema/2022-10-07",
"properties": {
"jsonSchemaDialect": { "$ref": "#/$defs/dialect" }
},

"$defs": {
"dialect": { "const": "https://spec.openapis.org/oas/3.1/dialect/base" },

"schema": {
"$dynamicAnchor": "meta",
"$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
"properties": {
"$schema": { "$ref": "#/$defs/dialect" }
}
}
}
}
Loading

0 comments on commit 6156abd

Please sign in to comment.