Skip to content

Commit 4b417a6

Browse files
committed
jtd-esm-codegen: emit qualified schemaPaths per normative json-java21-jtd spec (RFC 8927 3.3 conformance); align accessor names to documented renames (ruling 15)
1 parent 872a40a commit 4b417a6

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎jtd-esm-codegen/JTD_CODEGEN_SPEC.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ syntax-based.
293293

294294
Target-language expression examples:
295295
- JavaScript (uint8): `typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 255`
296-
- Java (uint8): `v instanceof JsonNumber n && n.toDouble() == Math.floor(n.toDouble()) && n.toLong() >= 0 && n.toLong() <= 255`
296+
- Java (uint8): `v instanceof JsonNumber n && n.asDouble() == Math.floor(n.asDouble()) && n.asLong() >= 0 && n.asLong() <= 255`
297297

298298
## 5. Emission Rules
299299

@@ -389,7 +389,7 @@ check for the element schema.
389389
```javascript
390390
// "elements": {"type": "string"}
391391
if (!Array.isArray(v)) {
392-
e.push({instancePath: p, schemaPath: sp});
392+
e.push({instancePath: p, schemaPath: sp + "/elements"});
393393
} else {
394394
for (let i = 0; i < v.length; i++) {
395395
if (typeof v[i] !== "string")
@@ -415,7 +415,7 @@ Emit an object type guard, then:
415415
```javascript
416416
// Schema: {"properties":{"name":{"type":"string"}}, "optionalProperties":{"age":{"type":"uint8"}}}
417417
if (v === null || typeof v !== "object" || Array.isArray(v)) {
418-
e.push({instancePath: p, schemaPath: sp});
418+
e.push({instancePath: p, schemaPath: sp + "/properties"});
419419
} else {
420420
// Required properties
421421
if (!("name" in v)) e.push({instancePath: p, schemaPath: sp + "/properties/name"});
@@ -451,7 +451,7 @@ generated check for the value schema.
451451
```javascript
452452
// "values": {"type": "string"}
453453
if (v === null || typeof v !== "object" || Array.isArray(v)) {
454-
e.push({instancePath: p, schemaPath: sp});
454+
e.push({instancePath: p, schemaPath: sp + "/values"});
455455
} else {
456456
for (const k in v) {
457457
if (typeof v[k] !== "string")
@@ -468,9 +468,9 @@ variant validator.
468468
```javascript
469469
// "discriminator": "type", "mapping": {"a": {...}, "b": {...}}
470470
if (v === null || typeof v !== "object" || Array.isArray(v)) {
471-
e.push({instancePath: p, schemaPath: sp});
471+
e.push({instancePath: p, schemaPath: sp + "/discriminator"});
472472
} else if (!("type" in v)) {
473-
e.push({instancePath: p, schemaPath: sp});
473+
e.push({instancePath: p, schemaPath: sp + "/discriminator"});
474474
} else if (typeof v["type"] !== "string") {
475475
e.push({instancePath: p + "/type", schemaPath: sp + "/discriminator"});
476476
} else if (v["type"] === "a") {
@@ -708,7 +708,7 @@ Properties {
708708
export function validate(instance) {
709709
const e = [];
710710
if (instance === null || typeof instance !== "object" || Array.isArray(instance)) {
711-
e.push({instancePath: "", schemaPath: ""});
711+
e.push({instancePath: "", schemaPath: "/properties"});
712712
return e;
713713
}
714714

@@ -725,7 +725,7 @@ export function validate(instance) {
725725

726726
if (!("tags" in instance)) e.push({instancePath: "", schemaPath: "/properties/tags"});
727727
else if (!Array.isArray(instance["tags"]))
728-
e.push({instancePath: "/tags", schemaPath: "/properties/tags"});
728+
e.push({instancePath: "/tags", schemaPath: "/properties/tags/elements"});
729729
else {
730730
const arr = instance["tags"];
731731
for (let i = 0; i < arr.length; i++) {

0 commit comments

Comments
 (0)