Ports #
| Port | Direction | Kind | Required | Description |
|---|---|---|---|---|
in | input | records | yes | |
valid | output | records | yes | |
rejected | output | records | no | Invalid items wrapped as {item, errors}. |
Parameters #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
schema | object | none | yes | JSON Schema 2020-12 for one item. |
When to use it #
- Check every record against a JSON Schema before loading: valid records continue on
valid. - Keep the bad ones for review: connect
rejectedand each invalid record arrives there with the list of errors. - Fail fast instead: leave
rejectedunconnected and the first invalid record stops the run.
When to use something else
- It checks, it does not repair or convert: to turn strings into numbers use
std:cast.formatkeywords are annotations in v0.1 and never cause a rejection.
How it works #
Valid one way, invalid the other #
Every item is checked against the JSON Schema (dialect 2020-12) given in schema. A valid item is emitted unchanged on valid. What happens to an invalid one depends on whether you connected rejected:
rejectedconnected — the item arrives there wrapped together with the reasons, and the run goes on:json{"item": <original>, "errors": [{"path": <JSON Pointer>, "message": <text>}, ...]}rejectednot connected — the first invalid item fails the run. Invalid data is never dropped silently.
In the example above the schema requires an integer age of at least 0: {"age":3} continues on valid, while {"age":-1} and {"name":"x"} are rejected. The test checks their number and shape rather than the literal error texts.
Details that matter #
- A
schemathat is not itself a valid JSON Schema is a parameter error (E_PARAM), reported before the run. formatkeywords are annotations in v0.1 and never cause a rejection.- The pipe checks and routes; it does not change items. To convert types use
std:cast, which wraps its rejects in the same{item, errors}form.
A tested example #
Nothing here is invented: this is the test “routes valid and invalid items” from the pipe's own portable test file, which every conformant runner must pass.
{
"schema": {
"type": "object",
"required": [
"age"
],
"properties": {
"age": {
"type": "integer",
"minimum": 0
}
}
}
}{"age":3}
{"age":-1}
{"name":"x"}{"age":3}2 items. The test checks their number and shape, not their literal text.
The same step as a node of a pipeline.yaml:
nodes:
validate-schema:
pipe: std:validate-schema
inputs:
in: {from: inputs.in}
parameters:
schema: {type: "object", required: ["age"], properties: {age: {type: "integer", minimum: 0}}}Notes from the manifest #
The pipe's manifest, OPENFLANGE.md, carries these notes.
Part of the OpenFlange standard library (std, version 0.1).
Validates every item against schema. Valid items pass to valid
byte-for-byte. An invalid item is emitted on the optional output rejected
as
{"item": <the original item>, "errors": [{"path": "/age", "message": "minimum: got -1, want 0"}]}where path is a JSON Pointer into the item ("" for the item itself) and
message is informative text that is not portable — assert on the
structure. If
rejected is not connected, the first invalid item fails the run with
E_RUNTIME — record errors are routed as data or they stop the run; they are
never dropped silently.
The schema is compiled once before the run (an invalid schema is E_PARAM).
Numbers are validated from their literals, so large integers and decimals
are not rounded. External $refs (files, URLs) are refused: the schema must
be self-contained. format is an annotation, not an assertion.
Reference #
- Maturity
- Experimental
- Processing scope
record- Manifest version
0.1.0
- Normative definition: std:validate-schema in the standard library specification
- Manifest and tests: std/0.1/validate-schema in the specification repository