Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
{
     "name":"Product",
     "properties":{
       "id":{
         "type":"number",
         "description":"Product identifier",
         "required":true
       },
       "name":{
         "description":"Name of the product",
         "type":"string",
         "required":true
       },
       "price":{
         "required":true,
         "type": "number",
         "minimum":0,
         "required":true
       },
       "tags":{
         "type":"array",
         "items":{
           "type":"string"
         }
       }
     },
     "additionalProperties":{        "releaseStatus":{
         "type":"string",
         "description":"The release status of a product",
         "enum":[ "PROTOTYPE", "RELEASED", "RECALLED", "DEPRECIATED"]
       }
     },
     # not used...
     "additionalProperties":{
     }
   }

In the above example, we can seen an how various types of data can be defined for a Product using the JSON Schema. For example, "id" is a number and required, while "releaseStatus" is an enumeration of strings.

The following pseudo-code snippet shows a partial implementation of the json-schema-03 represented as a Model class:

Code Block

// This class represents a JSON Schema as defined by: http://tools.ietf.org/html/draft-zyp-json-schema-03
class ObjectSchema {

...
	// This map defines the primary fields of an Object
	Map<String, ObjectSchema> properties;
	// This map defines the additional Annotations of an Object.
	Map<String, ObjectSchema> additionalProperties;
...
}

In the above class each property has a name and schema that defines the property. We are proposing to use the ObjectSchema.properties to define the primary fields of a Synapse Entity, and the ObjectScheam.additinalProperties to define the Annotations of a Synapse Entity.

There is a lot more detail to the JSON Schema definition that we will not cover here.We are proposing to use the "properties" to define the primary fields of a Synapse Entity. These primary fields can be considered the expected data of all instances of a given entity. Using the Product example from above, this implies that all instances of Product would have "id", "name", "price" and "tags.

Initially we were planning to use "additinalProperties" to define the Annotations of a Synapse Entity, but this raised a fundamental issue. If the Annotations of an entity are provided for ad-hock user data, then formally defining them in the entity schema for all instances of a type seems like a poor fit. That said, we still have many use cases where we want to constrain the data of an annotation when they are added to an instance of an entity. Therefore, we are positioning that these annotation types are set on a per-instances basis rather than at the entity type definition. Annotation types are covered in a separate document: Proposal for Annotation Types

Schema Life-cycle

For the initial implementation we are proposing that an Entity Schema can only be defined and edited as part of the compile of synapse. This means run-time edits or additions to each schema will not be possible. The reason for this limitation is to keep the Life-cycle of the schema as simple as possible. As we will see, the life-cycle is already complicated even with this limitation.

...