Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions jtd-esm-codegen/JTD_CODEGEN_SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ syntax-based.

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

## 5. Emission Rules

Expand Down Expand Up @@ -389,7 +389,7 @@ check for the element schema.
```javascript
// "elements": {"type": "string"}
if (!Array.isArray(v)) {
e.push({instancePath: p, schemaPath: sp});
e.push({instancePath: p, schemaPath: sp + "/elements"});
} else {
for (let i = 0; i < v.length; i++) {
if (typeof v[i] !== "string")
Expand All @@ -415,7 +415,7 @@ Emit an object type guard, then:
```javascript
// Schema: {"properties":{"name":{"type":"string"}}, "optionalProperties":{"age":{"type":"uint8"}}}
if (v === null || typeof v !== "object" || Array.isArray(v)) {
e.push({instancePath: p, schemaPath: sp});
e.push({instancePath: p, schemaPath: sp + "/properties"});
} else {
// Required properties
if (!("name" in v)) e.push({instancePath: p, schemaPath: sp + "/properties/name"});
Expand Down Expand Up @@ -451,7 +451,7 @@ generated check for the value schema.
```javascript
// "values": {"type": "string"}
if (v === null || typeof v !== "object" || Array.isArray(v)) {
e.push({instancePath: p, schemaPath: sp});
e.push({instancePath: p, schemaPath: sp + "/values"});
} else {
for (const k in v) {
if (typeof v[k] !== "string")
Expand All @@ -468,9 +468,9 @@ variant validator.
```javascript
// "discriminator": "type", "mapping": {"a": {...}, "b": {...}}
if (v === null || typeof v !== "object" || Array.isArray(v)) {
e.push({instancePath: p, schemaPath: sp});
e.push({instancePath: p, schemaPath: sp + "/discriminator"});
} else if (!("type" in v)) {
e.push({instancePath: p, schemaPath: sp});
e.push({instancePath: p, schemaPath: sp + "/discriminator"});
} else if (typeof v["type"] !== "string") {
e.push({instancePath: p + "/type", schemaPath: sp + "/discriminator"});
} else if (v["type"] === "a") {
Expand Down Expand Up @@ -708,7 +708,7 @@ Properties {
export function validate(instance) {
const e = [];
if (instance === null || typeof instance !== "object" || Array.isArray(instance)) {
e.push({instancePath: "", schemaPath: ""});
e.push({instancePath: "", schemaPath: "/properties"});
return e;
}

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

if (!("tags" in instance)) e.push({instancePath: "", schemaPath: "/properties/tags"});
else if (!Array.isArray(instance["tags"]))
e.push({instancePath: "/tags", schemaPath: "/properties/tags"});
e.push({instancePath: "/tags", schemaPath: "/properties/tags/elements"});
else {
const arr = instance["tags"];
for (let i = 0; i < arr.length; i++) {
Expand Down
Loading