Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ The schema validation that the build performs can’t be run locally directly, b
$ ./download-delta.schema.json.sh # (download JSON schema for delta protocol messages)
$ ./download-serialization.schema.json.sh # (download JSON schema for serialization format)
$ npm install @exodus/schemasafe
$ ./validate-all-jsons.js
$ ./validate-all-jsons.ts
```

The `validate-specific-message-json.js` script can be used to troubleshoot message JSONs that don’t validate.
The `validate-specific-message-json.ts` script can be used to troubleshoot message JSONs that don’t validate.

```shell
$ ./download-delta.schema.json.sh # (download full JSON schema for delta protocol messages)
$ ./validate-specific-message-json.js
$ ./validate-specific-message-json.ts
Usage: execute
node validate-specific-message-json.js <path to JSON with message> [message kind]
node validate-specific-message-json.ts <path to JSON with message> [message kind]
to validate that JSON as a message of the indicated kind — hopefully producing more understandable errors.
If the message kind is not given, we try to derive that from the file name, although that might fail.
In addition, a JSON schema that only pertains to that message kind is saved to a file with name "<message kind>.specific-schema.json".
$ ./validate-specific-message-json.js delta/event/ErrorEvent.delta.json
$ ./validate-specific-message-json.ts delta/event/ErrorEvent.delta.json
Derived message kind from path of JSON file as: ErrorEvent
JSON file with path "delta/event/ErrorEvent.delta.json" contains a valid message of kind ErrorEvent.
```
Expand All @@ -76,7 +76,7 @@ JSON file with path "delta/event/ErrorEvent.delta.json" contains a valid message

* [Deno](https://deno.com), currently (at least) version 2.7.7 — for the integration tests written in Deno-compliant TypeScript in [`src/`](src).
(Deno is used instead of Node.js because Deno can reliably execute TypeScript code natively.)
* [Node.js](https://nodejs.org/en/download) (including NPM), currently (at least) version 23.6.0 — for running `validate-all-jsons.js`.
* [Node.js](https://nodejs.org/en/download) (including NPM), currently (at least) version 23.6.0 — for running `validate-all-jsons.ts`.
* Java 11 (but really Java 8) - for the [`lionweb-java` repo](repos/lionweb-java).


Expand Down
12 changes: 6 additions & 6 deletions validate-all-jsons.js → validate-all-jsons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --no-warnings


// Copyright 2026 TRUMPF Laser SE and other contributors
Expand All @@ -23,24 +23,24 @@ const { validator} = require("@exodus/schemasafe")
const { readdirSync, readFileSync } = require("fs")
const { join } = require("path")

const readFileAsJson = (path) => JSON.parse(readFileSync(path).toString())
const readFileAsJson = (path: string) => JSON.parse(readFileSync(path).toString())

const lsFilesInPath = (fileNameEnding, path) =>
const lsFilesInPath = (fileNameEnding: string, path: string) =>
readdirSync(path, { recursive: true })
.filter((subPath) => subPath.endsWith(fileNameEnding))
.map((subPath) => join(path, subPath))

const lsFilesInPaths = (fileNameEnding, paths) =>
const lsFilesInPaths = (fileNameEnding: string, paths: string[]) =>
paths.flatMap((path) => lsFilesInPath(fileNameEnding, path))


const validateJsonInPaths = (schemaPath, fileNameEnding, paths) => {
const validateJsonInPaths = (schemaPath: string, fileNameEnding: string, paths: string[]) => {
const schema = readFileAsJson(schemaPath)
const validate = validator(schema, {
includeErrors: true,
allErrors: false,
// Note: cardinalby/schema-validator-action@v3 configures allErrors=true, but I want to avoid too much output per JSON file.
// Use validate-specific-message-json.js for more detailed output.
// Use validate-specific-message-json.ts for more detailed output.
weakFormats: true,
extraFormats: true
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --no-warnings


// Copyright 2026 TRUMPF Laser SE and other contributors
Expand Down Expand Up @@ -37,11 +37,13 @@ In addition, a JSON schema that only pertains to that message kind is saved to a
exit(64)
}

const postfixTryRemover = (postfix) =>
type StringTransformer = (str: string) => string

const postfixTryRemover= (postfix: string): StringTransformer =>
(str) =>
str.endsWith(postfix) ? str.substring(0, str.length - postfix.length) : str

const composeTransforms = (...transforms) =>
const composeTransforms = (...transforms: StringTransformer[]): StringTransformer =>
(str) =>
transforms.reduce((current, transform) => transform(current), str)

Expand All @@ -59,7 +61,8 @@ if (!optionalArg2) {
}


const readFileAsJson = (path) => JSON.parse(readFileSync(path).toString())
const readFileAsJson = (path: string) =>
JSON.parse(readFileSync(path).toString())


// compute JSON Schema specific to message kind:
Expand All @@ -73,8 +76,8 @@ if (messageSchema === undefined) {
exit(64)
}

const referredDefs = []
const gatherReferredDefsFrom = (thing) => {
const referredDefs: string[] = []
const gatherReferredDefsFrom = (thing: object) => {
if ("properties" in thing) {
Object.values(thing.properties).forEach(gatherReferredDefsFrom)
} else if (thing.type === "array") {
Expand Down
Loading