Repository navigation
Conversation
This was referenced Oct 9, 2026
export-schema --union combines the Pywr v1 schema, generated by pywr-v1-schema, with the v2 model and multi-network schemas. Each version's definitions are namespaced and the document kind is selected by its identifying property: nodes, models, network or networks.
Every v2 model, including the multi-network ones, and every v1 conversion input must validate, and a document that mixes the v1 and v2 identifying properties, or has none, must be rejected.
A new workflow exports the v2 schema and the combined v1 and v2 schema with pywr-cli and uploads them to the release that was published, so that each version has its schemas at a stable URL.
pywr_model_schema returns a Result with a JsonSchemaError instead of panicking when a schema generator produces an unexpected shape, and the CLI reports it with context. Both v2 document types are generated by one SchemaGenerator, so they share a single definition namespace and cannot number a clashing definition name differently. Root definitions are named from JsonSchema::schema_name rather than from the schema's title, which a doc comment heading or a schemars attribute can change. The help text of --union now says what the default export covers and how v1 custom types are treated.
…hema The union selected its document kind with a oneOf over four alternatives, so any invalid document failed with a bare "not valid under any of the given schemas" and the whole document echoed back. The kind is now chosen by an `if`/`then` on its identifying property, with a oneOf of bare `required` clauses enforcing that exactly one of them is present. The set of accepted documents is unchanged, and a document with a missing or mistyped field reports that field. The tests now reject invalid documents: none or two identifying properties, a missing `time` or `timestepper`, mistyped fields, an unknown v2 node type and a bad v1 edge. Each of the schema's parts is needed by one of them. A further test compares the v2 half of the union with the standalone v2 schema.
gh release upload fails on an asset that already exists, so re-running the job on a release failed. With --clobber the assets are replaced.
CI builds with --locked, which fails when the lock file lacks the entries for a dependency the manifest declares.
Mearman
force-pushed
the
feat/schema-union-export
branch
from
October 9, 2026 10:40
0220688 to
3d93df8
Compare
Mearman
marked this pull request as ready for review
October 17, 2026 04:54
Contributor
Author
|
@jetuk this exports one JSON Schema for v1 and v2 model files ( |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
pywr-cli export-schema --union, which writes one JSON Schema that accepts a Pywr v1 model, a v1 multi-model, a v2 model or a v2 multi-network model. The four formats are told apart by their identifying top-level key (nodes,models,network,networks), and each side's definitions sit under av1_orv2_prefix so shared names such asNodeandParameterdo not collide. Without the flag the output is unchanged.The branch is chosen with
if/thenon the identifying key, so a document that fails reports the errors of its own kind (a v2 model missingtimesteppersays so) instead of a single "not valid under any of the given schemas". A document with none of the keys, or with two of them, is rejected.pywr_model_schemareturns aResultwithJsonSchemaErrorinstead of panicking.The v1 half uses the
json_schemamodule added topywr-v1-schemain pywr/pywr-v1-schema#300, which first shipped in 0.25.1, so the workspace requirement is raised to0.25.1("0.25"would still admit 0.25.0, which lacks the module) and the lockfile resolves it from crates.io. #900, the derives for the multi-network types, is already in this branch's base.Against the published crate, the union accepts every v1 and v2 model in the test directories through its own branch only, and rejects documents with no identifying key, two of them, a mistyped field or a bad v1 edge. The tests assert those rejections, and renaming the branch
$refkey, dropping the forbidden sibling keys or pointing a branch at the wrong root each fail one. The defaultexport-schemaoutput is byte-identical tomain.One commit adds a workflow that attaches
pywr-v2.schema.jsonand the unionpywr.schema.jsonto a published release (re-runs replace the assets). It has been run on a fork release, not here, so please drop it if a release-asset step is not wanted.