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
fields
field, 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: true
to indicate that the field is required, - May specify
multiple: true
to indicate that the field is an array of the specified type, - Has a
reference
, if type isattachment
orreference
, which is theid
of another schema. - Has an
enum
, if type isenum
, which is an array of possible values,
The primitive types are:
string
number
boolean
enum
dict
attachment
reference
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
- oauth
Dict 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: dict
Attachment 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: true
Reference 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: true
List 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: true
A 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