Repository navigation
Schema: export default_factory defaults in JSON Schemas (#62) - #75
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Closes the systemic fix recommended in #62.
lacing/json_schema.py:DefaultFactoryJsonSchema, aGenerateJsonSchemasubclass that writesdefaultfor every zero-argumentdefault_factoryfield whose result is JSON-serialisable (factories that take validated data, or return something unencodable, are left alone); andSchemaModel, aBaseModelwhosemodel_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 inheritSchemaModel, so a plainModel.model_json_schema()agrees with the committed artifacts.character-voice/v1loses its per-fieldjson_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.lacing/schema/*: exactly three additions —review/v1target_annotation_ids[],continuity-violation/v1evidence{},reference-lock/v1params{}. A schemadefaultnever invalidates a document (the fields stay optional), so no major bump; downstream zod mirrors will now parse an absent value as[]/{}instead ofundefined.Provenance.was_derived_from(envelope) now exports[]too. The envelope is not part oflacing/schema/*(only bodies are exported), so no committed file changes for it.tests/test_json_schema.py: for every registered body, each zero-argumentdefault_factoryfield 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 plainBaseModels; 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