1
0
Fork 0

Merge pull request #5843 from stof/enforce_map_types

Enhance the json schema with validation for map objects
pull/5836/merge
Jordi Boggiano 2016-11-06 17:02:38 +01:00 committed by GitHub
commit 98a599d6c3
2 changed files with 73 additions and 14 deletions

View File

@ -77,32 +77,44 @@
"require": { "require": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that are required to run this package.", "description": "This is a hash of package name (keys) and version constraints (values) that are required to run this package.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"replace": { "replace": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that can be replaced by this package.", "description": "This is a hash of package name (keys) and version constraints (values) that can be replaced by this package.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"conflict": { "conflict": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that conflict with this package.", "description": "This is a hash of package name (keys) and version constraints (values) that conflict with this package.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"provide": { "provide": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that this package provides in addition to this package's name.", "description": "This is a hash of package name (keys) and version constraints (values) that this package provides in addition to this package's name.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"require-dev": { "require-dev": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that this package requires for developing it (testing tools and such).", "description": "This is a hash of package name (keys) and version constraints (values) that this package requires for developing it (testing tools and such).",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"suggest": { "suggest": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and descriptions (values) that this package suggests work well with it (this will be suggested to the user during installation).", "description": "This is a hash of package name (keys) and descriptions (values) that this package suggests work well with it (this will be suggested to the user during installation).",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"config": { "config": {
"type": "object", "type": "object",
@ -134,12 +146,16 @@
"github-oauth": { "github-oauth": {
"type": "object", "type": "object",
"description": "A hash of domain name => github API oauth tokens, typically {\"github.com\":\"<token>\"}.", "description": "A hash of domain name => github API oauth tokens, typically {\"github.com\":\"<token>\"}.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"gitlab-oauth": { "gitlab-oauth": {
"type": "object", "type": "object",
"description": "A hash of domain name => gitlab API oauth tokens, typically {\"gitlab.com\":\"<token>\"}.", "description": "A hash of domain name => gitlab API oauth tokens, typically {\"gitlab.com\":\"<token>\"}.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"disable-tls": { "disable-tls": {
"type": "boolean", "type": "boolean",
@ -160,7 +176,20 @@
"http-basic": { "http-basic": {
"type": "object", "type": "object",
"description": "A hash of domain name => {\"username\": \"...\", \"password\": \"...\"}.", "description": "A hash of domain name => {\"username\": \"...\", \"password\": \"...\"}.",
"additionalProperties": true "additionalProperties": {
"type": "object",
"required": ["username", "password"],
"properties": {
"username": {
"type": "string",
"description": "The username used for HTTP Basic authentication"
},
"password": {
"type": "string",
"description": "The password used for HTTP Basic authentication"
}
}
}
}, },
"store-auths": { "store-auths": {
"type": ["string", "boolean"], "type": ["string", "boolean"],
@ -169,7 +198,9 @@
"platform": { "platform": {
"type": "object", "type": "object",
"description": "This is a hash of package name (keys) and version (values) that will be used to mock the platform packages on this machine.", "description": "This is a hash of package name (keys) and version (values) that will be used to mock the platform packages on this machine.",
"additionalProperties": true "additionalProperties": {
"type": "string"
}
}, },
"vendor-dir": { "vendor-dir": {
"type": "string", "type": "string",
@ -275,12 +306,22 @@
"psr-0": { "psr-0": {
"type": "object", "type": "object",
"description": "This is a hash of namespaces (keys) and the directories they can be found in (values, can be arrays of paths) by the autoloader.", "description": "This is a hash of namespaces (keys) and the directories they can be found in (values, can be arrays of paths) by the autoloader.",
"additionalProperties": true "additionalProperties": {
"type": ["string", "array"],
"items": {
"type": "string"
}
}
}, },
"psr-4": { "psr-4": {
"type": "object", "type": "object",
"description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.", "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.",
"additionalProperties": true "additionalProperties": {
"type": ["string", "array"],
"items": {
"type": "string"
}
}
}, },
"classmap": { "classmap": {
"type": "array", "type": "array",
@ -303,12 +344,22 @@
"psr-0": { "psr-0": {
"type": "object", "type": "object",
"description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.", "description": "This is a hash of namespaces (keys) and the directories they can be found into (values, can be arrays of paths) by the autoloader.",
"additionalProperties": true "additionalProperties": {
"type": ["string", "array"],
"items": {
"type": "string"
}
}
}, },
"psr-4": { "psr-4": {
"type": "object", "type": "object",
"description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.", "description": "This is a hash of namespaces (keys) and the PSR-4 directories they can map to (values, can be arrays of paths) by the autoloader.",
"additionalProperties": true "additionalProperties": {
"type": ["string", "array"],
"items": {
"type": "string"
}
}
}, },
"classmap": { "classmap": {
"type": "array", "type": "array",

View File

@ -44,6 +44,14 @@ class ComposerSchemaTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->check($json)); $this->assertTrue($this->check($json));
} }
public function testRequireTypes()
{
$json = '{"name": "name", "description": "description", "require": {"a": ["b"]} }';
$this->assertEquals(array(
array('property' => 'require.a', 'message' => 'Array value found, but a string is required', 'constraint' => 'type'),
), $this->check($json));
}
public function testMinimumStabilityValues() public function testMinimumStabilityValues()
{ {
$json = '{ "name": "vendor/package", "description": "generic description", "minimum-stability": "" }'; $json = '{ "name": "vendor/package", "description": "generic description", "minimum-stability": "" }';