Skip to content

Schema: export default_factory defaults in JSON Schemas (#62) - #75

Merged
thorwhalen merged 1 commit into
mainfrom
fix/schema-factory-defaults-62
Oct 14, 2026
Merged

thorwhalen merged 1 commit into
mainfrom
fix/schema-factory-defaults-62

Conversation

@thorwhalen

Copy link
Copy Markdown
Collaborator

Closes the systemic fix recommended in #62.

  • New lacing/json_schema.py: DefaultFactoryJsonSchema, a GenerateJsonSchema subclass that writes default for every zero-argument default_factory field whose result is JSON-serialisable (factories that take validated data, or return something unencodable, are left alone); and SchemaModel, a BaseModel whose model_json_schema() uses it.
  • lacing.schema.json_schema() / export_json_schemas() always use the generator, so any registered body gets it whatever its base class. The in-repo bodies and envelope models (Provenance, Annotation, refs) now inherit SchemaModel, so a plain Model.model_json_schema() agrees with the committed artifacts.
  • character-voice/v1 loses its per-field json_schema_extra={"default": {}} (character-voice/v1: provider_voice_ids exports no JSON-Schema default, so zod mirrors parse it as undefined instead of {} #40): the generator emits the same default, and its committed schema is byte-identical.
  • Regenerated lacing/schema/*: exactly three additions — review/v1 target_annotation_ids [], continuity-violation/v1 evidence {}, reference-lock/v1 params {}. A schema default never invalidates a document (the fields stay optional), so no major bump; downstream zod mirrors will now parse an absent value as [] / {} instead of undefined.
  • Provenance.was_derived_from (envelope) now exports [] too. The envelope is not part of lacing/schema/* (only bodies are exported), so no committed file changes for it.
  • tests/test_json_schema.py: for every registered body, each zero-argument default_factory field exports a default equal to the model's, and stays optional; the three reported fields; committed schemas equal a fresh export (all bodies, not only character-voice); the generator on plain BaseModels; the unencodable/data-taking cases.

lacing-ui's codegen freshness gate will show the three-line mirror diff once it regenerates (tracked on reeleehq/lacing-ui#8).

Closes #62

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit e98578f into main Oct 14, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the fix/schema-factory-defaults-62 branch October 14, 2026 13:00
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.

default_factory fields in review, continuity-violation and reference-lock bodies also export no JSON-Schema default

1 participant