Skip to content

Commit 4627cff

Browse files
committed
refactor
1 parent bae3ca0 commit 4627cff

File tree

2 files changed

+63
-53
lines changed

2 files changed

+63
-53
lines changed

src/main/java/com/networknt/schema/SchemaRegistry.java

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.FileNotFoundException;
3737
import java.io.IOException;
3838
import java.io.InputStream;
39-
import java.net.URI;
4039
import java.util.List;
4140
import java.util.Map;
4241
import java.util.concurrent.ConcurrentHashMap;
@@ -651,6 +650,69 @@ public Schema getSchema(final SchemaLocation schemaUri) {
651650
return schema;
652651
}
653652

653+
/**
654+
* Gets the schema.
655+
*
656+
* @param schemaUri the base absolute IRI
657+
* @param jsonNode the node
658+
* @return the schema
659+
*/
660+
public Schema getSchema(final SchemaLocation schemaUri, final JsonNode jsonNode) {
661+
return newSchema(schemaUri, jsonNode);
662+
}
663+
664+
/**
665+
* Gets the schema.
666+
*
667+
* @param schemaUri the base absolute IRI
668+
* @param schema the input schema data
669+
* @param inputFormat input format
670+
* @return the schema
671+
*/
672+
public Schema getSchema(final SchemaLocation schemaUri, final String schema, InputFormat inputFormat) {
673+
try {
674+
final JsonNode schemaNode = readTree(schema, inputFormat);
675+
return newSchema(schemaUri, schemaNode);
676+
} catch (IOException ioe) {
677+
logger.error("Failed to load json schema!", ioe);
678+
throw new SchemaException(ioe);
679+
}
680+
}
681+
682+
/**
683+
* Gets the schema.
684+
*
685+
* @param schemaUri the base absolute IRI
686+
* @param schemaStream the input schema data
687+
* @param inputFormat input format
688+
* @return the schema
689+
*/
690+
public Schema getSchema(final SchemaLocation schemaUri, final InputStream schemaStream, InputFormat inputFormat) {
691+
try {
692+
final JsonNode schemaNode = readTree(schemaStream, inputFormat);
693+
return newSchema(schemaUri, schemaNode);
694+
} catch (IOException ioe) {
695+
logger.error("Failed to load json schema!", ioe);
696+
throw new SchemaException(ioe);
697+
}
698+
}
699+
700+
/**
701+
* Gets the schema.
702+
* <p>
703+
* Using this is not recommended as there is potentially no base IRI for
704+
* resolving references to the absolute IRI.
705+
* <p>
706+
* Prefer {@link #getSchema(SchemaLocation, JsonNode)} instead to ensure the
707+
* base IRI if no id is present.
708+
*
709+
* @param jsonNode the node
710+
* @return the schema
711+
*/
712+
public Schema getSchema(final JsonNode jsonNode) {
713+
return newSchema(null, jsonNode);
714+
}
715+
654716
/**
655717
* Loads the schema.
656718
*
@@ -720,56 +782,6 @@ protected Schema getMappedSchema(final SchemaLocation schemaUri) {
720782
}
721783
}
722784

723-
/**
724-
* Gets the schema.
725-
*
726-
* @param schemaUri the absolute IRI of the schema which can map to the
727-
* retrieval IRI.
728-
* @return the schema
729-
*/
730-
public Schema getSchema(final URI schemaUri) {
731-
return getSchema(SchemaLocation.of(schemaUri.toString()));
732-
}
733-
734-
/**
735-
* Gets the schema.
736-
*
737-
* @param schemaUri the absolute IRI of the schema which can map to the
738-
* retrieval IRI.
739-
* @param jsonNode the node
740-
* @return the schema
741-
*/
742-
public Schema getSchema(final URI schemaUri, final JsonNode jsonNode) {
743-
return newSchema(SchemaLocation.of(schemaUri.toString()), jsonNode);
744-
}
745-
746-
/**
747-
* Gets the schema.
748-
*
749-
* @param schemaUri the base absolute IRI
750-
* @param jsonNode the node
751-
* @return the schema
752-
*/
753-
public Schema getSchema(final SchemaLocation schemaUri, final JsonNode jsonNode) {
754-
return newSchema(schemaUri, jsonNode);
755-
}
756-
757-
/**
758-
* Gets the schema.
759-
* <p>
760-
* Using this is not recommended as there is potentially no base IRI for
761-
* resolving references to the absolute IRI.
762-
* <p>
763-
* Prefer {@link #getSchema(SchemaLocation, JsonNode)} instead to ensure the
764-
* base IRI if no id is present.
765-
*
766-
* @param jsonNode the node
767-
* @return the schema
768-
*/
769-
public Schema getSchema(final JsonNode jsonNode) {
770-
return newSchema(null, jsonNode);
771-
}
772-
773785
/**
774786
* Gets the schema registry config.
775787
*

src/test/java/com/networknt/schema/QuickStartTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertNotNull;
6-
import static org.junit.jupiter.api.Assertions.assertTrue;
76

87
import java.io.IOException;
98
import java.util.Collections;
@@ -19,7 +18,6 @@
1918
import com.networknt.schema.dialect.Dialects;
2019
import com.networknt.schema.output.OutputUnit;
2120
import com.networknt.schema.regex.JoniRegularExpressionFactory;
22-
import com.networknt.schema.resource.SchemaIdResolver;
2321
import com.networknt.schema.serialization.JsonMapperFactory;
2422
import com.networknt.schema.utils.JsonNodes;
2523

0 commit comments

Comments
 (0)