Skip to content

Conversation

@ubmarco
Copy link
Member

@ubmarco ubmarco commented Apr 16, 2025

Experimental implementation of a schema validation, aka. ontology check.
This is based on jsonschema, but also supports network validations.

Abandoned, see my new PR #1467.

@ubmarco ubmarco changed the title ✨ Schema validation (WIP) ✨ Schema validation 🚧 Apr 17, 2025
@ubmarco ubmarco mentioned this pull request Apr 22, 2025
@ubmarco ubmarco changed the title ✨ Schema validation 🚧 ✨ Schema validation Apr 24, 2025
@ubmarco ubmarco force-pushed the mh-schema-validation branch 6 times, most recently from 5cf6b49 to 75c6211 Compare May 2, 2025 10:55
@ubmarco ubmarco force-pushed the mh-schema-validation branch 2 times, most recently from 61538a3 to 22130fc Compare May 15, 2025 10:29
chrisjsewell added a commit that referenced this pull request May 15, 2025
This fixes the problem, that the `option_spec` attributes are modified
on a class level for:

- `NeedDirective`
- `NeedextendDirective`
- `NeedserviceDirective`

and thus remain changed for subsequent sphinx runs in the same
interpreter session.

The problem was a finding of
#1441.

This is particularly of issue for SN test cases, which all run in the
same Python interpreter,
and should ideally be reproducible, independent of any preceding tests
run.

The PR defines a `reset_options_spec` class method for modified
directives,
to revert the runtime changes during the `config-inited` event.

---------

Co-authored-by: Chris Sewell <[email protected]>
@ubmarco ubmarco force-pushed the mh-schema-validation branch from 22130fc to a8a8eca Compare May 15, 2025 15:41
@ubmarco ubmarco mentioned this pull request Jul 8, 2025
@ubmarco
Copy link
Member Author

ubmarco commented Jul 15, 2025

Closing this in favor of #1467

@ubmarco ubmarco closed this Jul 15, 2025
ubmarco added a commit that referenced this pull request Jul 24, 2025
This is the implementation of the discussion
#1451
and a follow-up on #1441.

The PR adds schema validation to Sphinx-Needs that
supports local validation and network validation.
The Sphinx-Needs internal data type representation is not changed yet,
all types are still strings. This will come shortly after merge.
Users can already try out the new interface and provide feedback.

Differences to PR 1441:
- Aligning with standards in JSON schema for re-using subschemas via
`$defs` and `$ref`
- Fully typed implementation including runtime checks of valid schema
user input
- Auto inject the default string type if not given
- Replace `trigger_schema` with `select` which aligns with query
language terminology
- Replace `trigger_schema_id` with the mentioned `$ref` mechanism
- New schemas root key `validate` with sub-keys `local` and `network`
for the 2 validation types
- Network validation items does not allow the `select` key anymore as
the selection happens by linking target needs.
  This cleans up an ambiguity in the other PR.
- Network validation errors now bubble up to the root json schema and
are displayed to see exactly why the chain fails
- More network rule types for better control over debug schema output
- Rewrite test cases to use a declarative definition as yaml, so all
pieces can be given in one place:
  - conf.py
  - ubproject.toml
  - index.rst
  - schemas.json
  - expected ontology warnings
- Simplified the code logic
- String patterns (regex) are constrained to a basic subset that works
across engines
- Added docs
  - Examples and explanations
- Comparison with `needs_warnings` and `needs_constraints` and migration
path
- Many more test cases
- `items` with `minItems` and `maxItems` and `contains` with
`minContains` and `maxContains` are now semantically equivalent to JSON
schema spec

---------

Co-authored-by: Chris Sewell <[email protected]>
PierreEtienneJ pushed a commit to PierreEtienneJ/sphinx-needs that referenced this pull request Jul 29, 2025
This is the implementation of the discussion
useblocks#1451
and a follow-up on useblocks#1441.

The PR adds schema validation to Sphinx-Needs that
supports local validation and network validation.
The Sphinx-Needs internal data type representation is not changed yet,
all types are still strings. This will come shortly after merge.
Users can already try out the new interface and provide feedback.

Differences to PR 1441:
- Aligning with standards in JSON schema for re-using subschemas via
`$defs` and `$ref`
- Fully typed implementation including runtime checks of valid schema
user input
- Auto inject the default string type if not given
- Replace `trigger_schema` with `select` which aligns with query
language terminology
- Replace `trigger_schema_id` with the mentioned `$ref` mechanism
- New schemas root key `validate` with sub-keys `local` and `network`
for the 2 validation types
- Network validation items does not allow the `select` key anymore as
the selection happens by linking target needs.
  This cleans up an ambiguity in the other PR.
- Network validation errors now bubble up to the root json schema and
are displayed to see exactly why the chain fails
- More network rule types for better control over debug schema output
- Rewrite test cases to use a declarative definition as yaml, so all
pieces can be given in one place:
  - conf.py
  - ubproject.toml
  - index.rst
  - schemas.json
  - expected ontology warnings
- Simplified the code logic
- String patterns (regex) are constrained to a basic subset that works
across engines
- Added docs
  - Examples and explanations
- Comparison with `needs_warnings` and `needs_constraints` and migration
path
- Many more test cases
- `items` with `minItems` and `maxItems` and `contains` with
`minContains` and `maxContains` are now semantically equivalent to JSON
schema spec

---------

Co-authored-by: Chris Sewell <[email protected]>
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.

2 participants