nti.schema.jsonschema

For producing a JSON schema appropriate for use by clients, based on a Zope schema.

The TAG constants are intended to be set as (boolean) tagged values on fields of interfaces, helping determine how the schema is built.

Note

This schema is ad-hoc and non-standard.

class JsonSchemafier(schema, readonly_override=None, context=None)[source]

Bases: object

allow_field(name, field)[source]

Return if the field is allowed in the external schema.

By default, this checks to see if the field has a true value for the tag TAG_HIDDEN_IN_UI, or if the field’s name starts with an underscore.

Changed in version 1.12.0: This will now be called for nested fields, such as the value_type or key_type of collections and mappings. In those cases, commonly the name will be the empty string.

bind(schema)[source]
get_data_from_choice_field(field, base_type=None)[source]

Return the choices and base type for the specified field

get_ui_types_from_field(field)[source]

Return the type and base type for the specified field

make_schema()[source]

Create the JSON schema.

Individual fields of the schema will be checked and returned. See the various TAG constants for ways that the schema externalization can be influenced.

Returns:A dictionary consisting of dictionaries, one for each field. All the keys are strings and the values are strings, bools, numbers, or lists of primitives. Will be suitable for writing to JSON.
post_process_field(name, field, item_schema)[source]
process_choice_field(field, base_type=None)

Return the choices and base type for the specified field

ui_types_from_field(field)

Return the type and base type for the specified field

TAG_APPLICATION_INFO = 'nti.schema.jsonschema.field_application_info'

A tagged value that echos semi-arbitrary data back in the schema under the key application_info.

The value for this field must be a mapping object whose keys are strings and whose values are JSON serializable. Text values (specifically zope.i18nmessageid.Message objects) will be translated when put into the schema. The object in the schema will not be the object in the tagged value, and constituent composite values will also be copied. (In case any post-processing of the schema is done based on current user, request or site, this isolates such modifications.)

New in version 1.12.0.

TAG_HIDDEN_IN_UI = 'nti.dataserver.users.field_hidden_in_ui'

Don’t display this by default in the UI

TAG_READONLY_IN_UI = 'nti.dataserver.users.field_readonly'

Overrides the value from the field itself, if true

TAG_REQUIRED_IN_UI = 'nti.dataserver.users.field_required'

Overrides the value from the field itself

TAG_UI_TYPE = 'nti.dataserver.users.field_type'

Qualifying details about how the field should be treated, such as data source The UI_TYPE values are defined known values for this tag.

UI_TYPE_EMAIL = 'nti.dataserver.users.interfaces.EmailAddress'

The email type

UI_TYPE_HASHED_EMAIL = 'nti.dataserver.users.interfaces.EmailAddress:Hashed'

An email type that is stored as a non-recoverable hash. The value is chosen so that a begins-with test will match either this or UI_TYPE_EMAIL, making validation easier

UI_TYPE_ONE_TIME_CHOICE = 'nti.dataserver.users.interfaces.OneTimeChoice'

Something that can be set once, typically during account creation

get_data_from_choice_field(v, base_type=None)[source]
get_ui_type_from_field_interface(field)[source]
get_ui_type_from_interface(iface)[source]
get_ui_types_from_field(field)[source]
interface_to_ui_type(iface)
process_choice_field(v, base_type=None)
ui_type_from_field(field)
ui_type_from_field_iface(field)