Skip to content

Commit bdfc036

Browse files
committed
Updates from review
Signed-off-by: Paulo Lopes <[email protected]>
1 parent 890ce8b commit bdfc036

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

src/main/asciidoc/index.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ You can use Json Schemas to validate every json structure. This module provides:
99
* Implementation of https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01[draft 7]
1010
* Implementation of https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00[draft 4]
1111
* Dereferencing of `$ref` resolution and caching
12-
* Synchronous validation
1312
* DSL to build schemas programmatically
1413
1514
== Using Vert.x Json Schema
@@ -50,9 +49,9 @@ underlying type.
5049

5150
=== SchemaRepository
5251

53-
The {@link io.vertx.json.schema.SchemaRepository} is the component that holds {@link io.vertx.json.schema.JsonSchema}
54-
instances. It performs dereferencing of schemas to speed up validation. The repository is a simple key store, this means
55-
that it does not allow duplicate ids.
52+
The {@link io.vertx.json.schema.SchemaRepository} holds {@link io.vertx.json.schema.JsonSchema} instances. It performs
53+
dereferencing of schemas to speed up validation. The repository is a simple key store, this means that it does not allow
54+
duplicate ids.
5655

5756
The repository can then create {@link io.vertx.json.schema.Validator} instances aware of all sub schemas in the
5857
repository.

src/main/java/io/vertx/json/schema/Draft.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import io.vertx.codegen.annotations.VertxGen;
1414

1515
/**
16-
* Json-Schema draft.
16+
* Json-Schema drafts.
1717
*
1818
* The enum does not explicitly define all known drafts but a selection of the most widely used ones and supported
1919
* in the implementation.

src/main/java/io/vertx/json/schema/JsonSchema.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
*/
1111
package io.vertx.json.schema;
1212

13+
import io.vertx.codegen.annotations.Fluent;
1314
import io.vertx.codegen.annotations.VertxGen;
1415
import io.vertx.core.json.JsonObject;
1516
import io.vertx.json.schema.impl.BooleanSchema;
17+
import io.vertx.json.schema.impl.JsonObjectSchema;
1618

1719
import java.util.Set;
1820

@@ -26,7 +28,7 @@
2628
* <li>Boolean based</li>
2729
* </ul>
2830
*
29-
* This is a common interface to handle all kids of schemas.
31+
* This is a common interface to handle all kinds of schemas.
3032
*
3133
* @author Paulo Lopes
3234
*/
@@ -39,7 +41,7 @@ public interface JsonSchema {
3941
* @return a wrapper for the input object.
4042
*/
4143
static JsonSchema of(JsonObject json) {
42-
return new io.vertx.json.schema.impl.JsonSchema(json);
44+
return new JsonObjectSchema(json);
4345
}
4446

4547
/**
@@ -49,7 +51,7 @@ static JsonSchema of(JsonObject json) {
4951
* @return a wrapper for the input object.
5052
*/
5153
static JsonSchema of(String id, JsonObject json) {
52-
return new io.vertx.json.schema.impl.JsonSchema(
54+
return new JsonObjectSchema(
5355
json.copy()
5456
.put("id", id));
5557
}
@@ -72,7 +74,8 @@ static JsonSchema of(boolean bool) {
7274
* @param key a key
7375
* @param value a value
7476
*/
75-
void annotate(String key, String value);
77+
@Fluent
78+
JsonSchema annotate(String key, String value);
7679

7780
/**
7881
* Get a type casted value by key.

src/main/java/io/vertx/json/schema/impl/BooleanSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private BooleanSchema(boolean bool) {
1616
}
1717

1818
@Override
19-
public void annotate(String key, String value) {
19+
public JsonSchema annotate(String key, String value) {
2020
throw new UnsupportedOperationException("This schema doesn't support annotate(String, String)");
2121
}
2222

src/main/java/io/vertx/json/schema/impl/JsonSchema.java renamed to src/main/java/io/vertx/json/schema/impl/JsonObjectSchema.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package io.vertx.json.schema.impl;
22

33
import io.vertx.core.json.JsonObject;
4+
import io.vertx.json.schema.JsonSchema;
45

56
import java.util.HashSet;
67
import java.util.Set;
78

8-
public final class JsonSchema extends JsonObject implements io.vertx.json.schema.JsonSchema {
9+
public final class JsonObjectSchema extends JsonObject implements JsonSchema {
910

1011
private boolean annotated;
1112

12-
public JsonSchema(JsonObject json) {
13+
public JsonObjectSchema(JsonObject json) {
1314
super(json.getMap());
1415
}
1516

1617
@Override
17-
public void annotate(String key, String value) {
18+
public JsonSchema annotate(String key, String value) {
1819
switch (key) {
1920
case "__absolute_uri__":
2021
annotated = true;
@@ -31,6 +32,7 @@ public void annotate(String key, String value) {
3132
default:
3233
throw new IllegalArgumentException("Unsupported annotation: " + key);
3334
}
35+
return this;
3436
}
3537

3638
@Override

src/main/java/io/vertx/json/schema/impl/SchemaRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public Validator validator(io.vertx.json.schema.JsonSchema schema, JsonSchemaOpt
110110
}
111111

112112
static void dereference(Map<String, io.vertx.json.schema.JsonSchema> lookup, io.vertx.json.schema.JsonSchema schema, URL baseURI, String basePointer, boolean schemaRoot) {
113-
if (schema instanceof JsonSchema) {
113+
if (schema instanceof JsonObjectSchema) {
114114
// This addresses the Unknown Keyword requirements, non sub-schema's with $id are to ignore the
115115
// given $id as it could collide with existing resolved schemas
116116
final String id = schemaRoot ? schema.get("$id", schema.get("id")) : null;

src/main/java/io/vertx/json/schema/impl/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public static JsonSchema wrap(JsonObject object, String key) {
349349
}
350350

351351
if (value instanceof JsonObject) {
352-
JsonSchema schema = new io.vertx.json.schema.impl.JsonSchema((JsonObject) value);
352+
JsonSchema schema = new JsonObjectSchema((JsonObject) value);
353353
object.put(key, schema);
354354
return schema;
355355
}
@@ -376,7 +376,7 @@ public static JsonSchema wrap(JsonArray array, int index) {
376376
}
377377

378378
if (value instanceof JsonObject) {
379-
JsonSchema schema = new io.vertx.json.schema.impl.JsonSchema((JsonObject) value);
379+
JsonSchema schema = new JsonObjectSchema((JsonObject) value);
380380
array.set(index, schema);
381381
return schema;
382382
}

0 commit comments

Comments
 (0)