Skip to content

feat: add schemas/vspec-node.schema.json — machine-readable vspec node format#920

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:feat/vspec-node-schema
Open

feat: add schemas/vspec-node.schema.json — machine-readable vspec node format#920
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:feat/vspec-node-schema

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Summary

  • Adds schemas/vspec-node.schema.json — a JSON Schema 2020-12 document describing every field a vspec YAML node may carry.
  • Updates README.md with a one-paragraph note pointing to the schema.

Motivation

The vspec YAML node format is currently documented only by example and by the Python toolchain's parser. Third-party tooling authors must reverse-engineer the field set and silently drop unknown fields when the spec adds new ones. A JSON Schema document gives them a stable, versioned contract to validate against.

The additionalProperties: false constraint is the key part — it makes the schema normative rather than just descriptive. Any field added to the spec in the future without updating the schema becomes a visible, reviewable diff rather than a silent addition.

Schema coverage

Field Type Notes
type enum branch, sensor, actuator, attribute (required)
datatype string required for leaf nodes
description string
unit string should match spec/units.yaml
min / max any numeric range
default any type must match datatype
comment string informative only
deprecation string non-empty = deprecated
instances string or string[] instance expansion
allowed array enumerated allowed values
pattern string regex constraint on value

Test plan

  • jsonschema validates each of the sample vspec files against this schema
  • All fields actually used in spec/ are represented
  • additionalProperties: false catches unknown fields

The vspec YAML node format is currently documented only by example and by
the Python toolchain's parser.  Third-party tooling authors must reverse-
engineer the field set and silently drop unknown fields when the spec adds
new ones.

Add schemas/vspec-node.schema.json (JSON Schema 2020-12) describing the
structure of a single vspec node:

  required:   type (enum: branch|sensor|actuator|attribute)
  optional:   datatype, description, unit, min, max, default, comment,
              deprecation, instances, allowed, pattern
  constraint: additionalProperties: false

The additionalProperties: false constraint makes this schema normative
rather than just descriptive: any new field added to the spec without
updating the schema becomes a visible, reviewable diff.

Update README.md with a one-paragraph note so tooling authors can find it.

Signed-off-by: Matt Jones <matt@jellybaby.com>

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>

@sschleemilch sschleemilch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe vss-tools could (and should) generate it since we are using pydantic and is then the single source of truth aligned.

Basically VSSData.model_json_schema() and VSSDataDatatype.model_json_schema().
Sure, it also contains internal things and probably needs to be tuned a bit

"description": "Unit of measure. Should be a value from the VSS unit catalogue (spec/units.yaml)."
},
"min": {
"description": "Minimum valid value (numeric). Applies to leaf nodes only."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type number?

"description": "Minimum valid value (numeric). Applies to leaf nodes only."
},
"max": {
"description": "Maximum valid value (numeric). Applies to leaf nodes only."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number type

},
"allowed": {
"type": "array",
"description": "Enumerated allowed values for the signal. Items should match the datatype.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "Enumerated allowed values for the signal. Items should match the datatype.",
"description": "Enumerated allowed values for the signal. Items must match the datatype.",

"pattern": {
"type": "string",
"description": "Regular expression that the signal value must match."
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum is missing

@erikbosch

Copy link
Copy Markdown
Collaborator

Thanks for the PR.

Comment thread README.md

### Machine-readable node schema

`schemas/vspec-node.schema.json` is a [JSON Schema 2020-12](https://json-schema.org/draft/2020-12/schema) document that describes every field a vspec YAML node may carry. Third-party tooling authors can validate against it so that unknown or misspelled fields are caught at parse time, and any future field additions to the spec are automatically a visible, reviewable diff to the schema. The `additionalProperties: false` constraint is intentional — it makes the schema normative rather than just descriptive.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know how easy it would be to create a minimal example on how this could be used, that we potentially could execute as part of CI to verify that std catalog and the schema are in sync. I am thinking of something

  • vspec export yaml or vspec export json
  • And then some command that checks that it complies with schema
    Have you done any checks like that to verify that the schema works with the current std catalog?

@erikbosch

Copy link
Copy Markdown
Collaborator

MoM:

  • Presented at meeting, please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants