Skip to content
This repository has been archived by the owner on Jul 5, 2021. It is now read-only.

Schema #12

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
371100a
first commit
Jul 7, 2010
1ed1903
Fixed README
Jul 7, 2010
e43f527
Changed schema location
Jul 7, 2010
70e1f66
Added described by rel
Jul 17, 2010
600d820
Added person and event derived types
Jul 17, 2010
7b2f0ba
test for application/json response for person
Jul 17, 2010
bae6e92
test for application/json response for person
Jul 17, 2010
19775da
remove due 501
Jul 17, 2010
a432f93
remove due 501
Jul 17, 2010
9511acb
Updated JSON extension and references
Jul 21, 2010
9fb754c
Merge branch 'master' of github.com:activitystreams/json-schema
Jul 21, 2010
0309588
Fixed references
Jul 23, 2010
21cb716
Removed action
Jul 23, 2010
76e2e73
Expanded the verbs and object types
Jul 23, 2010
d8983f2
Adding base library
Jul 23, 2010
f33b319
Added default and removed code which caused errors
Jul 23, 2010
a6d5234
Made references relative to avoid cross domain scripting
Jul 26, 2010
9886b3f
Added update verb
Jul 28, 2010
954ab7d
Made the author optional on activities so they can be used for sync a…
Aug 7, 2010
e8bb8a1
This should work
Aug 7, 2010
31b156b
Updating text so web server cache is popped and we can get the conten…
Aug 7, 2010
ae2f8e4
Linking to feed describedBy to json-schema.org
Aug 8, 2010
5eab8a2
New way of modeling updates
Aug 12, 2010
a91f22b
after discussions
Aug 13, 2010
29696bc
multiple
Aug 13, 2010
e6a3b89
Adding index file for JSON Schema folder
Jan 27, 2011
255ab62
Fix for typo
Jan 27, 2011
29db8e0
Added livestream
Jan 27, 2011
8e577e4
Added livestream
Jan 27, 2011
7c5a921
Added livestream
Jan 27, 2011
6748c07
Added livestream
Jan 27, 2011
ddf2e75
Added Styling
Jan 27, 2011
738d81e
Added Styling
Jan 27, 2011
06264bd
Added Styling
Jan 27, 2011
76b7da6
Added Styling
Jan 27, 2011
c857add
Making taller
Feb 5, 2011
15e6b30
Posting recordings
Feb 11, 2011
22b269f
Posting recordings
Feb 11, 2011
f80f5a9
So the schema is accessible
Mar 3, 2011
7af094b
Updates to match latest json activity spec
Mar 3, 2011
a5a7699
Escaping quotes
Mar 3, 2011
2025a80
Updated to show reactions
Mar 3, 2011
97c3123
Double quote escape
Mar 3, 2011
16556b3
Match spec on activity.json -- verb is optional tho
Mar 3, 2011
884ce10
Likes and Comments
Mar 3, 2011
79b5710
Braces
Mar 3, 2011
cbea5dd
old_index.html
Mar 4, 2011
2fe07bf
Restore Stream Discussion
Mar 23, 2011
6bdb059
renamed
Mar 23, 2011
c3a24fc
Clear old
Mar 23, 2011
4f642a1
Topic stream
Apr 2, 2011
e91b7f5
fix small typo
baroquebobcat Apr 11, 2011
c71458c
Renamed stream to collection and updated properties to match activity…
May 15, 2011
5caf320
Merge branch 'master' of github.com:activitystreams/json-schema
May 15, 2011
8f3c341
Object properties
May 16, 2011
d67d597
Consolidated object
May 16, 2011
3e964b3
Updated to json-schema draft 03, also updated activity.json
May 16, 2011
c446ec9
Cleanup of un needed files and syntax
May 16, 2011
56612ae
typo
May 16, 2011
4d0aeb1
fixed readme
May 16, 2011
1807f7d
Copied schema
May 16, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AddType application/json .json
15 changes: 12 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
This repository does contain a few specifications about publishing
activity streams.

This repository contains the JSON activity streams specification version 1.0

It also contains json-schema documents which map to all the constructs in the spec.

The syntax of the schema is defined at
http://json-schema.org/

To test you can use the following library:
https://github.com/Constellation/ruby-jsonchema

More libraries available in http://json-schema.org/

85 changes: 85 additions & 0 deletions schema/activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"type" : "object",
"title" : "activity",
"description" : "An activity construct recounts what an actor did to an object in the past. If there is no actor it simply describes the change.",
"properties": {
"id" :{
"type" : "string",
"description" : "Uniquely identifies each activity within the service",
"default" :"{url}"
},
"actor" : {
"type": "object",
"required": true,
"description": "Describes the entity that performed the activity. An activity MUST contain one actor property whose value is a single Object.",
"properties" : {"$ref":"./object.json#properties"}
},
"verb" : {
"title" : "verb",
"type" : "string",
"default": "post",
"required": true,
"description" :"Identifies the action that the activity describes. An activity MUST contain a verb property whose value is a JSON String that is non-empty and matches either the \"isegment-nz-nc\" or the \"IRI\" production in [RFC3987]. Note that the use of a relative reference other than a simple name is not allowed."
},
"object" : {
"type": "object",
"required" : true,
"description" : "Describes the primary object of the activity. For instance, in the activity, \"John saved a movie to his wishlist\", the object of the activity is \"movie\". An activity SHOULD contain an object property whose value is a single Object. If the object property is not contained, the primary object of the activity MAY be implied by context.",
"properties" : {"$ref":"./object.json#properties"}
},
"target" : {
"type": "object",
"description" : "Describes the target of the activity. The precise meaning of the activity's target is dependent on the activities verb, but will often be the object the English preposition \"to\". For instance, in the activity, \"John saved a movie to his wishlist\", the target of the activity is \"wishlist\". The activity target MUST NOT be used to identity an indirect object that is not a target of the activity. An activity MAY contain a target property whose value is a single Object.",
"properties" : {"$ref":"./object.json#properties"}
},
"published" : {
"type" : "string",
"description": "The date and time at which the activity occurred. It is important to note that this is not necessarily the same as the time at which the activity was published. An activity MUST contain a postedTime property.",
"format" : "date-time"
},
"updated" : {
"type" : "string",
"description": "The date and time at which a previously published activity has been modified. An Activity MAY contain an updatedTime property",
"format" : "date-time"
},
"generator" : {
"type": "object",
"description": "Describes the application that generated the activity. An activity MAY contain a generator property whose value is a single Object.",
"properties" : {"$ref":"./object.json#properties"}
},
"icon" : {
"type": "object",
"properties" :{"$ref":"./media_link.json#properties"},
"description": "An IRI[RFC3987] identifying an image resource provides a visual representation of the activity, intended for human consumption. The image SHOULD have an aspect ratio of one (horizontal) to one (vertical) and SHOULD be suitable for presentation at a small size. An activity MAY have an icon property"
},
"provider" : {
"type": "object",
"description" : "Describes the application that published the activity. Note that this is not necessarily the same entity that generated the activity. An activity MAY contain a provider property whose value is a single Object",
"properties" : {"$ref":"./object.json#properties"}
},
"title" : {
"type" : "string",
"description" : "Natural-language title or headline for the activity encoded as a single JSON String containing HTML markup. An activity MAY contain a title property",
"format": "html"
},
"content" : {
"type" : "string",
"description" : "Natural-language description of the activity encoded as a single JSON String containing HTML markup. Visual elements such as thumbnail images MAY be included. An activity MAY contain a content property",
"format" : "html"
},
"url" : {
"type" : "string",
"description" : "An IRI [RFC3987] identifying a resource providing an HTML representation of the activity. An activity MAY contain a url property",
"format" : "url"
},
"links" : {
"type" : "array",
"description" :"Links between this object and other resources as defined in Web Linking",
"note": "Tell JSON schema team to not put links inside http://json-schema.org/hyper-schema#properties",
"properties" : {"$ref" : "http://json-schema.org/links#properties"}
}
},
"links": [
{"rel": "describedby", "href": "./verbs/{verb}.json"}
]
}
33 changes: 33 additions & 0 deletions schema/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type" : "object",
"title" : "collection",
"description" : "A collection is a generic list of Objects of any object type. The objectType of each item in the collection MAY be omitted if the type of object can be established through context. The collection is used primarily as the root of an Activity Streams document, but can be used as the value of extension properties in a variety of situations. ",
"properties" : {
"url" : {
"type" : "string",
"description": "An IRI [RFC3987] referencing a JSON document containing the full listing of objects in the collection."
},
"totalItems": {
"type" : "number",
"description" : "Non-negative integer specifying the total number of activities within the stream. The Stream serialization MAY contain a count property."
},
"items" : {
"type" : "array",
"required" : true,
"description" : "An array containing a listing of Objects of any object type. If used in combination with the url property, the items array can be used to provide a subset of the objects that may be found in the resource identified by the url.",
"items": {
"type" : "object",
"properties" :{"$ref":"./object.json#properties"}
}
},
"links" : {
"type" : "array",
"optional" : true,
"description" :"Links between an this object and other resources as defined in Web Linking",
"properties" : {"$ref" : "http://json-schema.org/links#properties"}
}
},
"links": [
{"rel": "describedby", "href": "http://json-schema.org/schema"}
]
}
225 changes: 225 additions & 0 deletions schema/library/jsonschema-b4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/**
* JSONSchema Validator - Validates JavaScript objects using JSON Schemas
* (http://www.json.com/json-schema-proposal/)
*
* Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
* Updated by: Monica Wilkinson on 07/23/2010
*
* Licensed under the MIT (MIT-LICENSE.txt) license.
To use the validator call JSONSchema.validate with an instance object and an optional schema object.
If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
that schema will be used to validate and the schema parameter is not necessary (if both exist,
both validations will occur).
The validate method will return an array of validation errors. If there are no errors, then an
empty list will be returned. A validation error will have two properties:
"property" which indicates which property had the error
"message" which indicates what the error was
*/

JSONSchema = {
validate : function(/*Any*/instance,/*Object*/schema) {
// Summary:
// To use the validator call JSONSchema.validate with an instance object and an optional schema object.
// If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
// that schema will be used to validate and the schema parameter is not necessary (if both exist,
// both validations will occur).
// The validate method will return an object with two properties:
// valid: A boolean indicating if the instance is valid by the schema
// errors: An array of validation errors. If there are no errors, then an
// empty list will be returned. A validation error will have two properties:
// property: which indicates which property had the error
// message: which indicates what the error was
//
return this._validate(instance,schema,false);
},
checkPropertyChange : function(/*Any*/value,/*Object*/schema, /*String*/ property) {
// Summary:
// The checkPropertyChange method will check to see if an value can legally be in property with the given schema
// This is slightly different than the validate method in that it will fail if the schema is readonly and it will
// not check for self-validation, it is assumed that the passed in value is already internally valid.
// The checkPropertyChange method will return the same object type as validate, see JSONSchema.validate for
// information.
//
return this._validate(value,schema, property || "property");
},
_validate : function(/*Any*/instance,/*Object*/schema,/*Boolean*/ _changing) {

var errors = [];
// validate a value against a property definition
function checkProp(value, schema, path,i){
var l;
path += path ? typeof i == 'number' ? '[' + i + ']' : typeof i == 'undefined' ? '' : '.' + i : i;
function addError(message){
errors.push({property:path,message:message});
}

if((typeof schema != 'object' || schema instanceof Array) && (path || typeof schema != 'function')){
if(typeof schema == 'function'){
if(!(value instanceof schema)){
addError("is not an instance of the class/constructor " + schema.name);
}
}else if(schema){
addError("Invalid schema/property definition " + schema);
}
return null;
}
if(_changing && schema.readonly){
addError("is a readonly field, it can not be changed");
}
if(schema['extends']){ // if it extends another schema, it must pass that schema as well
checkProp(value,schema['extends'],path,i);
}
// validate a value against a type definition
function checkType(type,value){
if(type){
if(typeof type == 'string' && type != 'any' &&
(type == 'null' ? value !== null : typeof value != type) &&
!(value instanceof Array && type == 'array') &&
!(type == 'integer' && value%1===0)){
return [{property:path,message:(typeof value) + " value found, but a " + type + " is required"}];
}
if(type instanceof Array){
var unionErrors=[];
for(var j = 0; j < type.length; j++){ // a union type
if(!(unionErrors=checkType(type[j],value)).length){
break;
}
}
if(unionErrors.length){
return unionErrors;
}
}else if(typeof type == 'object'){
var priorErrors = errors;
errors = [];
checkProp(value,type,path);
var theseErrors = errors;
errors = priorErrors;
return theseErrors;
}
}
return [];
}
// Monica: Added code to check the default
if(value === undefined){
value = schema["default"];
}
if(value === undefined){
if(!schema.optional){
addError("is missing and it is not optional");
}
}else{
errors = errors.concat(checkType(schema.type,value));
if(schema.disallow && !checkType(schema.disallow,value).length){
addError(" disallowed value was matched");
}
if(value !== null){
if(value instanceof Array){
if(schema.items){
if(schema.items instanceof Array){
for(i=0,l=value.length; i<l; i++){
errors.concat(checkProp(value[i],schema.items[i],path,i));
}
}else{
for(i=0,l=value.length; i<l; i++){
errors.concat(checkProp(value[i],schema.items,path,i));
}
}
}
if(schema.minItems && value.length < schema.minItems){
addError("There must be a minimum of " + schema.minItems + " in the array");
}
if(schema.maxItems && value.length > schema.maxItems){
addError("There must be a maximum of " + schema.maxItems + " in the array");
}
}else if(schema.properties){
errors.concat(checkObj(value,schema.properties,path,schema.additionalProperties));
}
if(schema.pattern && typeof value == 'string' && !value.match(schema.pattern)){
addError("does not match the regex pattern " + schema.pattern);
}
if(schema.maxLength && typeof value == 'string' && value.length > schema.maxLength){
addError("may only be " + schema.maxLength + " characters long");
}
if(schema.minLength && typeof value == 'string' && value.length < schema.minLength){
addError("must be at least " + schema.minLength + " characters long");
}
if(typeof schema.minimum !== undefined && typeof value == typeof schema.minimum &&
schema.minimum > value){
addError("must have a minimum value of " + schema.minimum);
}
if(typeof schema.maximum !== undefined && typeof value == typeof schema.maximum &&
schema.maximum < value){
addError("must have a maximum value of " + schema.maximum);
}
if(schema['enum']){
var enumer = schema['enum'];
l = enumer.length;
var found;
for(var j = 0; j < l; j++){
if(enumer[j]===value){
found=1;
break;
}
}
if(!found){
addError("does not have a value in the enumeration " + enumer.join(", "));
}
}
if(typeof schema.maxDecimal == 'number' &&
(value.toString().match(new RegExp("\\.[0-9]{" + (schema.maxDecimal + 1) + ",}")))){
addError("may only have " + schema.maxDecimal + " digits of decimal places");
}
}

}
return null;
}
// validate an object against a schema
function checkObj(instance,objTypeDef,path,additionalProp){

if(typeof objTypeDef =='object'){
if(typeof instance != 'object' || instance instanceof Array){
errors.push({property:path,message:"an object is required"});
}

// check all the properties are present as required in the schema
for(var i in objTypeDef){
if(objTypeDef.hasOwnProperty(i) && !(i.charAt(0) == '_' && i.charAt(1) == '_')){
var value = instance[i];
var propDef = objTypeDef[i];
checkProp(value,propDef,path,i);
}
}
}

// check the properties of the instance
for(i in instance){
if(instance.hasOwnProperty(i) && !(i.charAt(0) == '_' && i.charAt(1) == '_') && objTypeDef && !objTypeDef[i] && additionalProp===false){
errors.push({property:path,message:(typeof value) + "The property " + i +
" is not defined in the schema and the schema does not allow additional properties"});
}
var requires = objTypeDef && objTypeDef[i] && objTypeDef[i].requires;
if(requires && !(requires in instance)){
errors.push({property:path,message:"the presence of the property " + i + " requires that " + requires + " also be present"});
}
value = instance[i];

if(!_changing && value && value.$schema){
errors = errors.concat(checkProp(value,value.$schema,path,i));
}
}
return errors;
}
if(schema){
checkProp(instance,schema,'',_changing || '');
}
if(!_changing && instance && instance.$schema){
checkProp(instance,instance.$schema,'','');
}
return {valid:!errors.length,errors:errors};
}
/* will add this later
newFromSchema : function() {
}
*/
}
Loading