1
0
Fork 0

Merge pull request #6013 from stof/repository_schema

Implement schema validation for repositories
pull/6018/head
Jordi Boggiano 2016-12-31 16:42:14 +01:00 committed by GitHub
commit 87b68e8c2f
4 changed files with 132 additions and 4 deletions

View File

@ -23,7 +23,7 @@
}, },
"require": { "require": {
"php": "^5.3.2 || ^7.0", "php": "^5.3.2 || ^7.0",
"justinrainbow/json-schema": "^1.6 || ^2.0 || ^3.0 || ^4.0", "justinrainbow/json-schema": "^3.0 || ^4.0",
"composer/ca-bundle": "^1.0", "composer/ca-bundle": "^1.0",
"composer/semver": "^1.0", "composer/semver": "^1.0",
"composer/spdx-licenses": "^1.0", "composer/spdx-licenses": "^1.0",

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "deb4df08cdd39eac7d11880586076ba1", "content-hash": "e18501d127e13e3619f80abbcf372c81",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",

View File

@ -393,7 +393,23 @@
"repositories": { "repositories": {
"type": ["object", "array"], "type": ["object", "array"],
"description": "A set of additional repositories where packages can be found.", "description": "A set of additional repositories where packages can be found.",
"additionalProperties": true "additionalProperties": {
"oneOf": [
{ "$ref": "#/definitions/repository" },
{ "type": "boolean", "enum": [false] }
]
},
"items": {
"oneOf": [
{ "$ref": "#/definitions/repository" },
{
"type": "object",
"additionalProperties": { "type": "boolean", "enum": [false] },
"minProperties": 1,
"maxProperties": 1
}
]
}
}, },
"minimum-stability": { "minimum-stability": {
"type": ["string"], "type": ["string"],
@ -548,5 +564,111 @@
"type": ["array", "string"], "type": ["array", "string"],
"description": "A key to store comments in" "description": "A key to store comments in"
} }
},
"definitions": {
"repository": {
"type": "object",
"oneOf": [
{ "$ref": "#/definitions/composer-repository" },
{ "$ref": "#/definitions/vcs-repository" },
{ "$ref": "#/definitions/path-repository" },
{ "$ref": "#/definitions/artifact-repository" },
{ "$ref": "#/definitions/pear-repository" },
{ "$ref": "#/definitions/package-repository" }
]
},
"composer-repository": {
"type": "object",
"required": ["type", "url"],
"properties": {
"type": { "type": "string", "enum": ["composer"] },
"url": { "type": "string", "format": "uri" },
"options": {
"type": "object",
"additionalProperties": true
},
"allow_ssl_downgrade": { "type": "boolean" },
"force-lazy-providers": { "type": "boolean" }
}
},
"vcs-repository": {
"type": "object",
"required": ["type", "url"],
"properties": {
"type": { "type": "string", "enum": ["vcs", "github", "git", "gitlab", "git-bitbucket", "hg", "hg-bitbucket", "fossil", "perforce", "svn"] },
"url": { "type": "string", "format": "uri" },
"no-api": { "type": "boolean" },
"secure-http": { "type": "boolean" },
"svn-cache-credentials": { "type": "boolean" },
"trunk-path": { "type": "string" },
"branches-path": { "type": "string" },
"tags-path": { "type": "string" },
"package-path": { "type": "string" },
"depot": { "type": "string" },
"branch": { "type": "string" },
"unique_perforce_client_name": { "type": "string" },
"p4user": { "type": "string" },
"p4password": { "type": "string" }
}
},
"path-repository": {
"type": "object",
"required": ["type", "url"],
"properties": {
"type": { "type": "string", "enum": ["path"] },
"url": { "type": "string" },
"options": {
"type": "object",
"properties": {
"symlink": { "type": ["boolean", "null"] }
},
"additionalProperties": true
}
}
},
"artifact-repository": {
"type": "object",
"required": ["type", "url"],
"properties": {
"type": { "type": "string", "enum": ["artifact"] },
"url": { "type": "string" }
}
},
"pear-repository": {
"type": "object",
"required": ["type", "url"],
"properties": {
"type": { "type": "string", "enum": ["pear"] },
"url": { "type": "string", "format": "uri" },
"vendor-alias": { "type": "string" }
}
},
"package-repository": {
"type": "object",
"required": ["type", "package"],
"properties": {
"type": { "type": "string", "enum": ["package"] },
"package": {
"oneOf": [
{ "$ref": "#/definitions/inline-package" },
{
"type": "array",
"items": {
"type": { "$ref": "#/definitions/inline-package" }
}
}
]
}
}
},
"inline-package": {
"type": "object",
"allOf": [
{ "$ref": "#" },
{
"required": ["name", "version"]
}
]
}
} }
} }

View File

@ -157,7 +157,13 @@ class JsonFile
} }
$schemaFile = __DIR__ . '/../../../res/composer-schema.json'; $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
$schemaData = json_decode(file_get_contents($schemaFile));
// Prepend with file:// only when not using a special schema already (e.g. in the phar)
if (false === strpos($schemaFile, '://')) {
$schemaFile = 'file://' . $schemaFile;
}
$schemaData = (object) array('$ref' => $schemaFile);
if ($schema === self::LAX_SCHEMA) { if ($schema === self::LAX_SCHEMA) {
$schemaData->additionalProperties = true; $schemaData->additionalProperties = true;