Skip to content

Commit fd92756

Browse files
committed
Issue #29 Add OpenRPC schema validation IT and resources
What - Add `OpenRPCSchemaValidationIT` dynamic integration test in `json-java21-schema`. - Add OpenRPC test resources under `src/test/resources/openrpc/` (minimal embedded schema + examples and negative cases). - Add short sign-posts in module README and AGENTS. - Add CI step to assert total test counts to prevent silent skips. How to verify - Run: `mvn -B -DskipITs=false -DskipTests=false verify` - Expected totals: tests=1807, failures=0, errors=0, skipped=577 - New tests: 1 IT class `OpenRPCSchemaValidationIT` (6 dynamic tests from example files)
1 parent 690284e commit fd92756

File tree

13 files changed

+254
-0
lines changed

13 files changed

+254
-0
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,26 @@ jobs:
2323
- name: Build and verify
2424
run: mvn -B -DskipITs=false -DskipTests=false verify
2525

26+
- name: Assert test count (no tests silently skipped)
27+
run: |
28+
python3 - <<'PY'
29+
import os, xml.etree.ElementTree as ET, sys
30+
totals={'tests':0,'failures':0,'errors':0,'skipped':0}
31+
for dirpath,_,files in os.walk('.'):
32+
if 'target' not in dirpath: continue
33+
if 'surefire-reports' not in dirpath and 'failsafe-reports' not in dirpath: continue
34+
for fn in files:
35+
if not fn.endswith('.xml'): continue
36+
p=os.path.join(dirpath,fn)
37+
try:
38+
r=ET.parse(p).getroot()
39+
for k in totals: totals[k]+=int(r.get(k,'0'))
40+
except Exception:
41+
pass
42+
exp_tests=1807
43+
exp_skipped=577
44+
if totals['tests']!=exp_tests or totals['skipped']!=exp_skipped:
45+
print(f"Unexpected test totals: {totals} != expected tests={exp_tests}, skipped={exp_skipped}")
46+
sys.exit(1)
47+
print(f"OK totals: {totals}")
48+
PY

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ PY
258258
### json-java21-schema
259259
- **Validator** for JSON Schema 2020-12 features
260260
- **Tests** include unit, integration, and annotation-based checks (see module guide)
261+
- **OpenRPC IT**: See `json-java21-schema/src/test/java/io/github/simbo1905/json/schema/OpenRPCSchemaValidationIT.java` and resources under `json-java21-schema/src/test/resources/openrpc/` (thanks to OpenRPC meta-schema and examples, Apache-2.0).
261262

262263
## Security Notes
263264
- **Stack exhaustion attacks**: Deep nesting can cause StackOverflowError

json-java21-schema/AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ The project uses `java.util.logging` with levels:
4848
- **Real-world schemas**: Complex nested validation scenarios
4949
- **Performance tests**: Large schema compilation
5050

51+
#### OpenRPC Validation (`OpenRPCSchemaValidationIT.java`)
52+
- **Location**: `json-java21-schema/src/test/java/io/github/simbo1905/json/schema/OpenRPCSchemaValidationIT.java`
53+
- **Resources**: `src/test/resources/openrpc/schema.json` and `openrpc/examples/*.json`
54+
- **Thanks**: OpenRPC meta-schema and examples (Apache-2.0). Sources: https://github.com/open-rpc/meta-schema and https://github.com/open-rpc/examples
55+
5156
#### Annotation Tests (`JsonSchemaAnnotationsTest.java`)
5257
- **Annotation processing**: Compile-time schema generation
5358
- **Custom constraints**: Business rule validation

json-java21-schema/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ mvn -pl json-java21-schema -am verify
3434
mvn -Djson.schema.strict=true -pl json-java21-schema -am verify
3535
```
3636

37+
OpenRPC validation
38+
39+
- Additional integration test validates OpenRPC documents using a minimal, self‑contained schema:
40+
- Test: `src/test/java/io/github/simbo1905/json/schema/OpenRPCSchemaValidationIT.java`
41+
- Resources: `src/test/resources/openrpc/` (schema and examples)
42+
- Thanks to OpenRPC meta-schema and examples (Apache-2.0): https://github.com/open-rpc/meta-schema and https://github.com/open-rpc/examples
43+
3744
## API Design
3845

3946
Single public interface with all schema types as inner records:
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package io.github.simbo1905.json.schema;
2+
3+
import jdk.sandbox.java.util.json.Json;
4+
import org.assertj.core.api.Assertions;
5+
import org.junit.jupiter.api.DynamicTest;
6+
import org.junit.jupiter.api.TestFactory;
7+
8+
import java.io.IOException;
9+
import java.net.URISyntaxException;
10+
import java.net.URL;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.util.List;
15+
import java.util.Objects;
16+
import java.util.stream.Stream;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
/**
21+
* Integration tests: validate OpenRPC documents using a minimal embedded meta-schema.
22+
*
23+
* Resources:
24+
* - Schema: src/test/resources/openrpc/schema.json
25+
* - Examples: src/test/resources/openrpc/examples/*.json
26+
* Files containing "-bad-" are intentionally invalid and must fail validation.
27+
*/
28+
public class OpenRPCSchemaValidationIT {
29+
30+
private static String readResource(String name) throws IOException {
31+
try {
32+
URL url = Objects.requireNonNull(OpenRPCSchemaValidationIT.class.getClassLoader().getResource(name), name);
33+
return Files.readString(Path.of(url.toURI()), StandardCharsets.UTF_8);
34+
} catch (URISyntaxException e) {
35+
throw new IOException(e);
36+
}
37+
}
38+
39+
@TestFactory
40+
Stream<DynamicTest> validateOpenRPCExamples() throws Exception {
41+
// Compile the minimal OpenRPC schema (self-contained, no remote $ref)
42+
String schemaJson = readResource("openrpc/schema.json");
43+
JsonSchema schema = JsonSchema.compile(Json.parse(schemaJson));
44+
45+
// Discover example files
46+
URL dirUrl = Objects.requireNonNull(getClass().getClassLoader().getResource("openrpc/examples"),
47+
"missing openrpc examples directory");
48+
Path dir = Path.of(dirUrl.toURI());
49+
50+
try (Stream<Path> files = Files.list(dir)) {
51+
List<Path> jsons = files
52+
.filter(p -> p.getFileName().toString().endsWith(".json"))
53+
.sorted()
54+
.toList();
55+
56+
assertThat(jsons).isNotEmpty();
57+
58+
return jsons.stream().map(path -> DynamicTest.dynamicTest(path.getFileName().toString(), () -> {
59+
String doc = Files.readString(path, StandardCharsets.UTF_8);
60+
boolean expectedValid = !path.getFileName().toString().contains("-bad-");
61+
boolean actualValid = schema.validate(Json.parse(doc)).valid();
62+
Assertions.assertThat(actualValid)
63+
.as("validation of %s", path.getFileName())
64+
.isEqualTo(expectedValid);
65+
}));
66+
}
67+
}
68+
}
69+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
OpenRPC test resources
2+
3+
Provenance and license
4+
- Source (meta‑schema): https://github.com/open-rpc/meta-schema (Apache-2.0)
5+
- Source (examples): https://github.com/open-rpc/examples (Apache-2.0)
6+
7+
These files are copied verbatim or lightly adapted for fair use in research and education to test the JSON Schema validator in this repository. See the original repositories for authoritative copies and full license terms.
8+
9+
Notes
10+
- The `schema.json` here is a minimal, self‑contained subset of the OpenRPC meta‑schema focused on validating overall document shape used by the included examples. It intentionally avoids external `$ref` to remain compatible with the current validator (which supports local `$ref`).
11+
- Example documents live under `examples/`. Files containing `-bad-` are intentionally invalid variants used for negative tests.
12+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"openrpc": "1.2.4",
3+
"methods": []
4+
}
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"openrpc": 1.2,
3+
"info": {
4+
"title": "",
5+
"version": "1.0.0"
6+
},
7+
"methods": []
8+
}
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"openrpc": "1.2.4",
3+
"info": {
4+
"title": ""
5+
},
6+
"methods": []
7+
}
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"openrpc": "1.2.4",
3+
"info": {
4+
"title": "",
5+
"version": "1.0.0"
6+
},
7+
"methods": {}
8+
}
9+

0 commit comments

Comments
 (0)