Repository navigation
Share schema and value conversion helpers - #2071
Merged
Merged
Conversation
Documentation build overview
|
davisagli
reviewed
Oct 20, 2026
davisagli
left a comment
Member
There was a problem hiding this comment.
@sneridagh I only started reviewing it, I have to continue tomorrow.
Member
Author
|
@jenkins-plone-org please run jobs |
sneridagh
force-pushed
the
issue-2061-schema-helpers
branch
from
November 1, 2026 02:41
4d5de75 to
57e0d34
Compare
Member
Author
|
@jenkins-plone-org please run jobs |
davisagli
approved these changes
Nov 1, 2026
Control panels, content rules and new settings services all build JSON schemas and convert values for plain zope.schema interfaces. Move that logic to plone.restapi.types.utils: - SchemaValues, a transient context providing IDexterityContent that replaces the three FakeDXContext copies (kept as an alias). - get_jsonschema_for_schema, which also marks read-only and display fields as readOnly and leaves them out of required. - serialize_schema_values and deserialize_schema_values, with a strict mode that reports unknown, read-only and missing fields and checks invariants against the merged current values. Control panels and content rules now use them, with unchanged output. Also describe and convert schema.Object fields that are not files or images: no File factory, plain property names, required fields, and JSON object values, including in lists.
Strings other than "true" and "false" used to become False silently, and numbers were stored as they were.
Fields such as collective.z3cform.datagridfield's DictRow subclass schema.Object but store plain dicts, and the new collection branch failed to serialize them. Content Object fields would also have stored SchemaValues instances. Keep the JSON schema fix for Object fields only.
- Prefix the shared schema helpers with an underscore, as they are not public API, and add type annotations. - Define the FakeDXContext BBB aliases by assignment instead of a noqa import. - Split the Bool fix into its own news entry. - Test that control panel updates keep omitted fields and report invariant errors once.
davisagli
force-pushed
the
issue-2061-schema-helpers
branch
from
November 1, 2026 19:31
fd2070e to
fd29194
Compare
Member
|
@jenkins-plone-org please run jobs |
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.
Control panels, content rules, and the upcoming
@content-typesservice all build JSON schemas and convert values for plainzope.schemainterfaces. Each had its own copy of that logic. This PR moves it toplone.restapi.types.utilsand switches control panels and content rules over, with unchanged output.Step 2a of #2061, stacked on #2069. Review it against
issue-2061-acceptance-server. #2070 builds on it.Shared helpers
SchemaValuesis a transient context that providesIDexterityContent, so the content field converters and JSON schema providers work for any schema. It replaces the threeFakeDXContextcopies, andFakeDXContextstays as an alias.get_jsonschema_for_schema()returnsproperties,required, andfieldsetsin the control panel format. It marks read-only and display-mode fieldsreadOnlyand leaves them out ofrequired. Hidden fields are still submitted by forms, so they aren't marked.serialize_schema_values()/deserialize_schema_values()convert values through the registered field adapters.strictmode reports unknown, read-only, and missing required fields. It also checks schema invariants against the merged current values, so partial updates are validated correctly.format_errors()translates error messages and masks Python error classes, as control panels did before.Bug fixes
schema.Objectfields: see the next section.Boolfields: these accepted any string and silently storedFalsefor everything except"true", and numbers were stored as they were. They now accept JSON booleans,"true","false", andnull, and reject anything else.JSON schema of
schema.ObjectfieldsObjectJsonSchemaProvider(types/adapters.py) is used for everyschema.Objectfield in@types, control panels, and content rules. It was written for file and image fields, and described every otherschema.Objectfield as a file as well.What changes, by the schema of the field:
factorybeforefactoryafterrequiredINamedBlobImageImageImageINamedImage(not blob)FileImageINamedFile,INamedBlobFileFileFileFileFor example,
schema.Object(title="Range", schema=IRange), whereIRangehas a requiredstartand an optionalend.Before:
{ "type": "object", "title": "Range", "factory": "File", "properties": { "range.start": {"type": "integer", "title": "Start"}, "range.end": {"type": "integer", "title": "End"} } }After:
{ "type": "object", "title": "Range", "properties": { "start": {"type": "integer", "title": "Start"}, "end": {"type": "integer", "title": "End"} }, "required": ["start"] }Compatibility:
image.data, apart from non-blobNamedImagefields, which now reportImageinstead ofFile.@typesresponses for the default content types and theuserschemaexample don't change.schema.Objectfields no longer pose as files, so a frontend doesn't pick a file widget for them. Their nestedpropertiesare now valid JSON schema, keyed by field name, with arequiredlist that leaves out read-only fields.schema.Objectvalues. An earlier version of this PR addedObjectFieldSerializerandObjectFieldDeserializer, but removed them for two reasons:collective.z3cform.datagridfieldrows, whoseDictRowsubclassesschema.Objectbut stores plain dicts.schema.Objectfields would have started storing restapi'sSchemaValuesobjects in the ZODB.Why it is part of this PR: it came up while sharing the schema helpers, and
get_jsonschema_for_schema()relies on the provider for nested schemas. #2070 no longer has anyschema.Objectsetting, since its allowed content types are two flat fields, so nothing in the #2061 stack depends on this fix. It's covered bytest_objectintest_types.pyand bytest_nested_object_schemaandtest_file_objects_keep_legacy_shapeintest_types_schema_helpers.py.Validation
test_types_schema_helpers.pycovers the helpers, strict and lenient modes, invariants with partial data, context source binders, and the nested Object schema.