Skip to content

fix: keep the stored jsonschema when store_entity regenerates it - #216

Open
LukasGold wants to merge 1 commit into
mainfrom
fix/store-entity-keeps-jsonschema
Open

LukasGold wants to merge 1 commit into
mainfrom
fix/store-entity-keeps-jsonschema

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Closes #215

Changes

  • store_entity passes the stored jsonschema slot as target_schema=. The old keyword schema= is not a field of AggregateGeneratedSchemasParam, so the aggregation always started from {} and dropped the hand-written schema.
  • A page without a jsonschema slot starts from {}, as before.
  • New function remove_generated_schema_section() in src/osw/core.py. It removes $defs/generated and the allOf entry {"$ref": "#/$defs/generated"}, as osl.util.postProcessPage in PageBot.js does.
  • store_entity calls it in DEFINITIONS_SECTION mode (Characteristics) before the aggregation, so the generated section is replaced instead of merged. It is called only when template generation produced at least one generated schema, so a failed generation keeps the stored schema.

Tests

New tests/test_store_entity_keeps_jsonschema.py, 5 tests. They run store_entity with offline=True and a fake site that serves the meta category, so no wiki is needed.

  • ROOT_LEVEL keeps hand-written properties.
  • DEFINITIONS_SECTION keeps $defs entries outside the generated section.
  • A second save with a different template drops a stale required and type, and $comment names the meta category once.
  • A template that produces invalid JSON leaves the stored schema unchanged.
  • A repeated ROOT_LEVEL save gives the same schema.

The first four tests failed on main before the fix. With only the target_schema= change, the stale-section test still failed at required.

Local gate: make check passed, make test reported 805 passed.

Not in this PR

As noted in the issue, resetGeneratedJsonLdContext and stripRootMembersSupersededByGenerated from PageBot.js are not ported. In ROOT_LEVEL mode a root entry that a later template no longer produces stays in the schema.

- pass target_schema= instead of the ignored schema= (#215)
- replace $defs/generated in DEFINITIONS_SECTION mode instead of merging
- add offline regression tests through store_entity
@LukasGold
LukasGold requested a review from simontaurus October 16, 2026 16:32
@github-actions

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.8.3 (current: v2.8.2).

Changelog preview (truncated)
## v2.8.3 (2026-10-16)

### Bug Fixes

- Keep the stored jsonschema when store_entity regenerates it
  ([`9b76a8f`](https://github.com/OpenSemanticLab/osw-python/commit/9b76a8fbeb813b34c4881b54d329e9e837b08f95))

Preview via python-semantic-release and conventional commits.

This branch has not been deployed

No deployments
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.

store_entity discards the stored jsonschema slot and keeps a stale generated section

1 participant