public function testGenerate() { $generator = new JsonSchema('foo', 'http://api.phpsx.org', 'http://foo.phpsx.org'); $json = $generator->generate($this->getResource()); $expect = <<<'JSON' { "$schema": "http://json-schema.org/draft-04/schema#", "id": "foo", "type": "object", "definitions": {"ref993f4bb37f524889fc963fedd6381458": { "type": "object", "properties": { "id": {"type": "integer"}, "userId": {"type": "integer"}, "title": { "type": "string", "minLength": 3, "maxLength": 16, "pattern": "[A-z]+" }, "date": {"type": "string"} }, "additionalProperties": false }}, "properties": { "getResponse": { "type": "object", "properties": {"entry": { "type": "array", "items": {"$ref": "#/definitions/ref993f4bb37f524889fc963fedd6381458"} }}, "additionalProperties": false }, "postRequest": { "type": "object", "properties": { "id": {"type": "integer"}, "userId": {"type": "integer"}, "title": { "type": "string", "minLength": 3, "maxLength": 16, "pattern": "[A-z]+" }, "date": {"type": "string"} }, "required": [ "title", "date" ], "additionalProperties": false }, "postResponse": { "type": "object", "properties": { "success": {"type": "boolean"}, "message": {"type": "string"} }, "additionalProperties": false }, "putRequest": { "type": "object", "properties": { "id": {"type": "integer"}, "userId": {"type": "integer"}, "title": { "type": "string", "minLength": 3, "maxLength": 16, "pattern": "[A-z]+" }, "date": {"type": "string"} }, "required": ["id"], "additionalProperties": false }, "putResponse": { "type": "object", "properties": { "success": {"type": "boolean"}, "message": {"type": "string"} }, "additionalProperties": false }, "deleteRequest": { "type": "object", "properties": { "id": {"type": "integer"}, "userId": {"type": "integer"}, "title": { "type": "string", "minLength": 3, "maxLength": 16, "pattern": "[A-z]+" }, "date": {"type": "string"} }, "required": ["id"], "additionalProperties": false }, "deleteResponse": { "type": "object", "properties": { "success": {"type": "boolean"}, "message": {"type": "string"} }, "additionalProperties": false } } } JSON; $this->assertJsonStringEqualsJsonString($expect, $json); }
public function testGenerate() { $generator = new JsonSchema(); $result = $generator->generate($this->getSchema()); $expect = <<<'JSON' { "$schema": "http://json-schema.org/draft-04/schema#", "id": "urn:schema.phpsx.org#", "description": "An general news entry", "definitions": { "ref11c55f48b558e06534c2dccf005c97cb": { "type": "object", "description": "An simple author element with some description", "properties": { "title": { "type": "string", "pattern": "[A-z]{3,16}" }, "email": { "type": "string", "description": "We will send no spam to this addresss" }, "categories": { "type": "array", "maxItems": 8, "items": { "type": "string" } }, "locations": { "type": "array", "description": "Array of locations", "items": { "$ref": "#/definitions/refe081a664cb5227a334bc5e0fa367f178" } }, "origin": { "$ref": "#/definitions/refe081a664cb5227a334bc5e0fa367f178" } }, "required": [ "title" ], "additionalProperties": false }, "refe081a664cb5227a334bc5e0fa367f178": { "type": "object", "description": "Location of the person", "properties": { "lat": { "type": "integer" }, "long": { "type": "integer" } }, "additionalProperties": false }, "refaf92365f86505945496a4ce039023ec6": { "type": "object", "description": "An application", "properties": { "name": { "type": "string" }, "url": { "type": "string" } }, "additionalProperties": false } }, "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "string" }, "minItems": 1, "maxItems": 6 }, "receiver": { "type": "array", "items": { "$ref": "#/definitions/ref11c55f48b558e06534c2dccf005c97cb" }, "minItems": 1 }, "resources": { "type": "array", "items": { "oneOf": [{ "$ref": "#/definitions/refe081a664cb5227a334bc5e0fa367f178" },{ "$ref": "#/definitions/refaf92365f86505945496a4ce039023ec6" }] } }, "read": { "type": "boolean" }, "source": { "oneOf": [{ "$ref": "#/definitions/ref11c55f48b558e06534c2dccf005c97cb" },{ "$ref": "#/definitions/refaf92365f86505945496a4ce039023ec6" }] }, "author": { "$ref": "#/definitions/ref11c55f48b558e06534c2dccf005c97cb" }, "sendDate": { "type": "string" }, "readDate": { "type": "string" }, "expires": { "type": "string" }, "price": { "type": "number", "minimum": 1, "maximum": 100 }, "rating": { "type": "integer", "minimum": 1, "maximum": 5 }, "content": { "type": "string", "minLength": 3, "maxLength": 512, "description": "Contains the main content of the news entry" }, "question": { "type": "string", "enum": [ "foo", "bar" ] }, "coffeeTime": { "type": "string" } }, "required": [ "receiver", "author", "price", "content" ], "additionalProperties": false } JSON; $this->assertJsonStringEqualsJsonString($expect, $result); }