|
20 | 20 |
|
21 | 21 | import com.fasterxml.jackson.databind.JsonNode; |
22 | 22 | import com.fasterxml.jackson.databind.ObjectMapper; |
23 | | -import com.networknt.schema.JsonSchema; |
24 | | -import com.networknt.schema.JsonSchemaFactory; |
25 | | -import com.networknt.schema.SchemaValidatorsConfig; |
26 | | -import com.networknt.schema.SpecVersionDetector; |
27 | | -import com.networknt.schema.resource.MapSchemaMapper; |
| 23 | +import com.networknt.schema.SchemaRegistry; |
| 24 | +import com.networknt.schema.SchemaRegistryConfig; |
| 25 | +import com.networknt.schema.serialization.DefaultNodeReader; |
28 | 26 | import org.cyclonedx.generators.json.BomJsonGenerator; |
29 | 27 | import org.cyclonedx.generators.xml.BomXmlGenerator; |
30 | 28 | import org.xml.sax.SAXException; |
@@ -82,36 +80,28 @@ public abstract class CycloneDxSchema |
82 | 80 | * @throws IOException when errors are encountered |
83 | 81 | * @since 6.0.0 |
84 | 82 | */ |
85 | | - public JsonSchema getJsonSchema(Version schemaVersion, final ObjectMapper mapper) |
| 83 | + public com.networknt.schema.Schema getJsonSchema(Version schemaVersion, final ObjectMapper mapper) |
86 | 84 | throws IOException |
87 | 85 | { |
88 | 86 | final InputStream spdxInstream = getJsonSchemaAsStream(schemaVersion); |
89 | | - final SchemaValidatorsConfig config = new SchemaValidatorsConfig(); |
90 | | - config.setPreloadJsonSchema(false); |
| 87 | + final SchemaRegistryConfig config = SchemaRegistryConfig.builder().preloadSchema(false).build(); |
91 | 88 |
|
92 | 89 | final Map<String, String> offlineMappings = new HashMap<>(); |
93 | | - offlineMappings.put("http://cyclonedx.org/schema/spdx.schema.json", |
94 | | - getClass().getClassLoader().getResource("spdx.schema.json").toExternalForm()); |
95 | | - offlineMappings.put("http://cyclonedx.org/schema/jsf-0.82.schema.json", |
96 | | - getClass().getClassLoader().getResource("jsf-0.82.schema.json").toExternalForm()); |
97 | | - offlineMappings.put("http://cyclonedx.org/schema/bom-1.2.schema.json", |
98 | | - getClass().getClassLoader().getResource("bom-1.2-strict.schema.json").toExternalForm()); |
99 | | - offlineMappings.put("http://cyclonedx.org/schema/bom-1.3.schema.json", |
100 | | - getClass().getClassLoader().getResource("bom-1.3-strict.schema.json").toExternalForm()); |
101 | | - offlineMappings.put("http://cyclonedx.org/schema/bom-1.4.schema.json", |
102 | | - getClass().getClassLoader().getResource("bom-1.4.schema.json").toExternalForm()); |
103 | | - offlineMappings.put("http://cyclonedx.org/schema/bom-1.5.schema.json", |
104 | | - getClass().getClassLoader().getResource("bom-1.5.schema.json").toExternalForm()); |
105 | | - offlineMappings.put("http://cyclonedx.org/schema/bom-1.6.schema.json", |
106 | | - getClass().getClassLoader().getResource("bom-1.6.schema.json").toExternalForm()); |
| 90 | + offlineMappings.put("http://cyclonedx.org/schema/spdx.schema.json", "classpath:spdx.schema.json"); |
| 91 | + offlineMappings.put("http://cyclonedx.org/schema/jsf-0.82.schema.json", "classpath:jsf-0.82.schema.json"); |
| 92 | + offlineMappings.put("http://cyclonedx.org/schema/bom-1.2.schema.json", "classpath:bom-1.2-strict.schema.json"); |
| 93 | + offlineMappings.put("http://cyclonedx.org/schema/bom-1.3.schema.json", "classpath:bom-1.3-strict.schema.json"); |
| 94 | + offlineMappings.put("http://cyclonedx.org/schema/bom-1.4.schema.json", "classpath:bom-1.4.schema.json"); |
| 95 | + offlineMappings.put("http://cyclonedx.org/schema/bom-1.5.schema.json", "classpath:bom-1.5.schema.json"); |
| 96 | + offlineMappings.put("http://cyclonedx.org/schema/bom-1.6.schema.json", "classpath:bom-1.6.schema.json"); |
107 | 97 |
|
108 | 98 | JsonNode schemaNode = mapper.readTree(spdxInstream); |
109 | | - final MapSchemaMapper offlineSchemaMapper = new MapSchemaMapper(offlineMappings); |
110 | | - JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersionDetector.detect(schemaNode))) |
111 | | - .jsonMapper(mapper) |
112 | | - .schemaMappers(s -> s.add(offlineSchemaMapper)) |
113 | | - .build(); |
114 | | - return factory.getSchema(schemaNode, config); |
| 99 | + SchemaRegistry registry = SchemaRegistry.builder() |
| 100 | + .nodeReader(DefaultNodeReader.builder().jsonMapper(mapper).build()) |
| 101 | + .schemaIdResolvers(b -> b.mappings(offlineMappings)) |
| 102 | + .schemaRegistryConfig(config) |
| 103 | + .build(); |
| 104 | + return registry.getSchema(schemaNode); |
115 | 105 | } |
116 | 106 |
|
117 | 107 | private InputStream getJsonSchemaAsStream(final Version schemaVersion) { |
|
0 commit comments