Schemas
Schemas are defined in .pschema.yaml (or .pschema.json) files. Schemas describe the structure of your data objects. They define the fields of your data objects. Every schema:
- Has an
id, which is unique across all schemas, - Has a
name, which is a human-readable name for the schema, - Has an optional
description, which is a human-readable description of the schema, - Has a
fieldsfield, which is an array of fields.
Each field:
- Has a
name, which is unique within the schema, - Has a
type, which is one of the primitive types listed below, - Has an optional
description, which is a human-readable description of the field, - May specify
required: trueto indicate that the field is required, - May specify
multiple: trueto indicate that the field is an array of the specified type, - Has a
reference, if type isattachmentorreference, which is theidof another schema. - Has an
enum, if type isenum, which is an array of possible values,
The primitive types are:
stringnumberbooleanenumdictattachmentreference
An empty schema in .pschema.yaml format looks like this:
id: empty-schema
name: Empty Schema
description: This is an empty schema.
fields: []Enum fields
You can create enum fields, by specifying the type as enum, and providing an enum field with an array of possible values. For example:
id: Service
name: Service
description: A service in the application.
fields:
- name: authenticationType
type: enum
description: The type of authentication required for the service.
enum:
- none
- basic
- token
- oauthDict fields
You can create dict fields, by specifying the type as dict. A dict field is a YAML (or JSON) object of arbitrary key-value pairs. For example:
id: GameObject
name: GameObject
description: A game object type.
fields:
- name: propertyTypes
description: The types of the properties of the game object, each value must be a valid JSON type.
type: dictAttachment fields
Attachment fields are used to embed other structured data objects. This data objects still must follow a schema, but they don't have their own ID, and live only as a part of another data object. For example:
id: Service
name: Service
description: A service in the application.
fields:
- name: operations
description: The operations that the service provides.
type: attachment
references: Operation
multiple: trueWhen you create an attachment field, ProJor will expect you to embed the referenced data structure into the field data. For multiple: true attachment fields ProJor will thus expect a list of objects.
PData example for the example schema above
id: services
name: Services
description: The services of the application
schema: Service
objects:
- name: ServiceOne
operations:
- name: operation_one
description: First operation
- name: operation_two
description: Second operationReference fields
Reference fields are used to reference other data objects. This reference can be to the same, or a different data collection. For example:
id: OperationParameter
name: OperationParameter
description: A parameter of an operation.
fields:
- name: type
description: The type of the parameter.
type: reference
references: BasicType
required: trueWhen you create a reference field, ProJor will expect you to use the data-collection-id#data-object-name reference syntax in the field data. For multiple: true reference fields ProJor will thus expect a list of strings.
PData example for the example schema above
id: parameters
name: Parameters
description: Operation parameters
schema: OperationParameter
objects:
- name: parameter_one
type: my-types#string
- name: parameter_two
type: my-types#integerList fields
You can set multiple: true on a field to make it a list field. List fields are arrays of the specified type. For example:
id: Operation
name: Operation
description: An operation of a service.
fields:
- name: parameters
description: The parameters of the operation.
type: attachment
references: OperationParameter
multiple: trueA more involved example
Here is a more real-world-like example of a schema:
id: Entity
name: Entity
description: An entity in the application.
fields:
- name: attributes
description: The attributes of the entity
type: attachment
references: EntityAttribute
multiple: true
- name: relationships
description: The relationships of the entity
type: attachment
references: EntityRelationship
multiple: true