Skip to content

Commit 4567048

Browse files
committed
throw when schema is not registered
1 parent 22dd182 commit 4567048

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2024 https://github.com/openapi-processor/openapi-parser
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.jsonschema.schema;
7+
8+
import java.net.URI;
9+
10+
public class NotRegisteredException extends RuntimeException {
11+
public NotRegisteredException(URI schemaUri) {
12+
super(String.format("Schema %s is not registered in the SchemaStore", schemaUri));
13+
}
14+
}

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/schema/SchemaStore.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ public JsonSchema getSchema (URI schemaUri, SchemaVersion version) {
181181

182182
Object document = documents.get (schemaUri);
183183
if (document == null) {
184-
// todo NotRegisteredException
185-
throw new RuntimeException ();
184+
throw new NotRegisteredException (schemaUri);
186185
}
187186

188187
// create schema

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/schema/SchemaStoreSpec.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@
55

66
package io.openapiprocessor.jsonschema.schema
77

8+
import io.kotest.assertions.throwables.shouldThrow
89
import io.kotest.core.spec.style.StringSpec
10+
import io.mockk.mockk
11+
import io.openapiprocessor.jsonschema.support.Uris
912

1013
class SchemaStoreSpec: StringSpec({
1114

15+
"throws when requesting a json schema from an un-registered uri" {
16+
val loader = mockk<DocumentLoader>()
17+
val store = SchemaStore(loader)
18+
19+
shouldThrow<NotRegisteredException> {
20+
store.getSchema(Uris.createUri("https://some.scheam.uri"))
21+
}
22+
}
1223

1324
})

0 commit comments

Comments
 (0)