├── tests
├── tmp
│ └── placeholder
├── phartest
│ ├── examples
│ ├── testcases
│ ├── phpunit.xml
│ └── bootstrap.php
├── phpini.sh
├── pharBuilder
│ ├── key.pub.pem
│ ├── makePhar.php
│ └── key.priv.pem
└── phpunit
│ ├── examples
│ ├── swaggerMultiFile.json
│ ├── multiSwaggerFile
│ │ └── parameters.json
│ └── swaggerPetStoreHeroku.json
│ ├── testcases
│ └── OverrideSwagger.php
│ ├── phpunit.xml
│ └── bootstrap.php
├── .gitignore
├── bin
└── SwaggerValidator.phar
├── doc
├── JsonSerializable.md
├── SwaggerValidator-SwaggerAutoload.md
├── SwaggerValidator-Exception.md
├── SwaggerValidator-Interfaces-ContextDataParser.md
├── SwaggerValidator-Interfaces-ContextDataLoader.md
├── SwaggerValidator-Interfaces-ContextLog.md
├── README.md
├── SwaggerValidator-Common-ReferenceItem.md
├── SwaggerValidator-Swagger.md
├── SwaggerValidator-Common-ReferenceFile.md
└── SwaggerValidator-Common-Collection.md
├── phpdoc.xml
├── .codeclimate.yml
├── src
├── Interfaces
│ ├── ContextDataParser.php
│ ├── ContextDataLoader.php
│ ├── ContextLog.php
│ └── ContextBase.php
├── Exception.php
├── Common
│ ├── SandBoxItem.php
│ ├── ReferenceItem.php
│ ├── Factory.php
│ ├── Sandbox.php
│ └── CollectionFile.php
├── Object
│ ├── Contact.php
│ ├── License.php
│ ├── Definitions.php
│ ├── ExternalDocs.php
│ ├── SecurityItem.php
│ ├── SecurityDefinitions.php
│ ├── SecurityRequirement.php
│ ├── Info.php
│ ├── Security.php
│ ├── ParameterBody.php
│ ├── Headers.php
│ ├── HeaderItem.php
│ ├── PathItem.php
│ ├── Responses.php
│ ├── Reference.php
│ ├── Operation.php
│ ├── Paths.php
│ ├── ResponseItem.php
│ └── Parameters.php
├── Security
│ ├── OAuth2PasswordSecurityScopes.php
│ ├── BasicAuthenticationSecurity.php
│ ├── ApiKeySecurity.php
│ ├── OAuth2PasswordSecurity.php
│ ├── OAuth2ImplicitSecurity.php
│ ├── OAuth2ApplicationSecurity.php
│ └── OAuth2AccessCodeSecurity.php
├── Example.php
├── SwaggerAutoload.php
├── DataType
│ ├── TypeFile.php
│ ├── TypeBoolean.php
│ └── TypeInteger.php
└── Compat.php
├── .travis.yml
├── composer.json
├── CHANGELOG.md
└── README.md
/tests/tmp/placeholder:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/phartest/examples:
--------------------------------------------------------------------------------
1 | ../phpunit/examples/
--------------------------------------------------------------------------------
/tests/phartest/testcases:
--------------------------------------------------------------------------------
1 | ../phpunit/testcases/
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | tests/metric*
3 | composer.lock
4 | #build*/*
5 | nbproject/
6 |
7 |
--------------------------------------------------------------------------------
/bin/SwaggerValidator.phar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nabbar/SwaggerValidator-PHP/HEAD/bin/SwaggerValidator.phar
--------------------------------------------------------------------------------
/doc/JsonSerializable.md:
--------------------------------------------------------------------------------
1 | JsonSerializable
2 | ===============
3 |
4 |
5 |
6 |
7 |
8 |
9 | * Interface name: JsonSerializable
10 | * Namespace:
11 | * This is an **interface**
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/tests/phpini.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | grep max_execution_time -H /etc/php*/cli/php.ini
4 | sed -i "s/^max_execution_time.*/max_execution_time = $1/" /etc/php*/cli/php.ini
5 | grep max_execution_time -H /etc/php*/cli/php.ini
6 |
--------------------------------------------------------------------------------
/phpdoc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Swagger Validator PHP
4 |
5 | ./doc
6 | utf8
7 |
8 | php
9 |
10 |
11 |
12 | phpdoc-md
13 |
14 |
15 |
16 |
17 |
18 | ./src
19 | ./src/Example.php
20 | ./src/Compat.php
21 | ./src/SwaggerAutoload.php
22 |
23 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-SwaggerAutoload.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\SwaggerAutoload
2 | ===============
3 |
4 | Description of SwaggerCommonAutoload
5 |
6 |
7 |
8 |
9 | * Class name: SwaggerAutoload
10 | * Namespace: SwaggerValidator
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Methods
19 | -------
20 |
21 |
22 | ### autoload
23 |
24 | mixed SwaggerValidator\SwaggerAutoload::autoload($className)
25 |
26 | Slim PSR-0 autoloader
27 |
28 |
29 |
30 | * Visibility: **public**
31 | * This method is **static**.
32 |
33 |
34 | #### Arguments
35 | * $className **mixed**
36 |
37 |
38 |
39 | ### registerAutoloader
40 |
41 | mixed SwaggerValidator\SwaggerAutoload::registerAutoloader()
42 |
43 | Register Slim's PSR-0 autoloader
44 |
45 |
46 |
47 | * Visibility: **public**
48 | * This method is **static**.
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/tests/pharBuilder/key.pub.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwVhHcAnf7MnRoHTBs6Rd
3 | /nOPlbnbd8ta4qdBH48HpGZRclhq1wiFOOffXbScK/MfTIAhhYoA8b4hvyMRYG1S
4 | 4vWHpKMJZbWZMP0yUP+G8kMuFKk5aTcUeIbU3y3wXafIJb/g3dlPDFmuAD3vbsbo
5 | Nr7liYH68aS3D3KrX3mlDEsBRx8vxr+TyUyvWvcWPZhYS0tUKVdq3DNRhGizpNzU
6 | 3SVxjRSMhBTHwHbx1BuZ31XGSGUkEy+KZK9KKAqqqo7gO+932+K5TWLInK5pC0uh
7 | rsoGTepjohuEodtLzc2ZJu/ynt5o+6GSHp2D7KZl7gtOgCXZklllk0XHlb1UjENv
8 | Y/BNinrfdCNm0oeqJHXsTa9gz2WMbw9vq052AuTvidcowaeNe42vVOvdH8SgIoSA
9 | 6OtXBn1VGmTt8NZYl4OaWiP9YC5FFFNwp8CZTBtjq3ZJ3nm1UNU8FQSS85ilzyyw
10 | S77WnCPoawQJqT7z8HOKjsSJlRBYLRaKja3ECl+6OsX/5E136Jxsxx2cHVXiT9Nx
11 | XzMz1B5z2tC9rGVkpDq1QBxGT5oiXkqzD0AXGTPE8Qh2+y2aqlNhUePaqRGjpUXn
12 | 8571JnVCQQ8uOLT057J62RC30LipP1qivDsEhskNV1nN4P3mfV1A1u70gu51Ls7e
13 | mqJGGxUKRyF1hBfRHYcYoLMCAwEAAQ==
14 | -----END PUBLIC KEY-----
15 |
--------------------------------------------------------------------------------
/tests/phpunit/examples/swaggerMultiFile.json:
--------------------------------------------------------------------------------
1 | {
2 | "swagger": "2.0",
3 | "info": {
4 | "version": "1.1",
5 | "title": "Twitter REST API"
6 | },
7 | "host": "api.twitter.com",
8 | "basePath": "/1.1",
9 | "schemes": [
10 | "http",
11 | "https"
12 | ],
13 | "consumes": [
14 | "application/json"
15 | ],
16 | "produces": [
17 | "application/json"
18 | ],
19 | "securityDefinitions": {
20 | "oauth": {
21 | "type": "oauth2",
22 | "flow": "implicit",
23 | "authorizationUrl": "https://twitter.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token",
24 | "scopes": {
25 | "basic": "to read any and all data related to twitter\n"
26 | }
27 | }
28 | },
29 | "security": [
30 | {
31 | "oauth": [
32 | "basic"
33 | ]
34 | }
35 | ],
36 | "paths": {
37 | "$ref": "multiSwaggerFile/paths.json#/"
38 | }
39 | }
--------------------------------------------------------------------------------
/.codeclimate.yml:
--------------------------------------------------------------------------------
1 | JavaScript: false
2 | Ruby: true
3 | Python: false
4 | PHP: true
5 |
6 | engines:
7 | duplication:
8 | enabled: true
9 | config:
10 | languages:
11 | - php
12 | # ... CONFIG CONTENT ...
13 | exclude_fingerprints:
14 | - 76c112c9507ab128765341298ecd6357
15 | - b7d4f063c55c4d9ec76db0f96fcf7e3c
16 | - 173b13479e6c1511c82345eefdbb5984
17 | - 0492c8204eb5003410274fc50cda3797
18 | - a36041b2a0627d98cbec7defde7f2caa
19 | - 3ecfcf8a545d88e08726203db815b433
20 | - 3ecfcf8a545d88e08726203db815b433
21 | - d511a4c8ddff97ad43ebc1ba8a7bc011
22 | - 0104ef9b41312ebdf17335e593f0c65c
23 | - 3e03180c6da2aaa9cf9227e662fd225a
24 | - 02062aa9d2003162c04c173c6eeb6175
25 | - 20905dbe0685363922f052c525d6a85d
26 | - c40012d33580a4ed294339c790ca228c
27 | - c94c35014d56aca7c5a8bb545e029d8b
28 | - b2a636cd86c21718021883cd30262de2
29 | - d47a2eb59744cc17573bacc4e89ddcbc
30 | fixme:
31 | enabled: true
32 | phpmd:
33 | enabled: true
34 |
35 | ratings:
36 | paths:
37 | - src/**
38 | - src/SwaggerValidator/**
39 | - "**.php"
40 |
41 | exclude_paths:
42 | - tests/**/*
43 | - vendor/**/*
44 | - bin/**/*
45 | - doc/**/*
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/Interfaces/ContextDataParser.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Interfaces;
20 |
21 | /**
22 | *
23 | * @author Nicolas JUHEL
24 | * @version 1.0.0
25 | */
26 | interface ContextDataParser
27 | {
28 |
29 | public function checkDataIsEmpty();
30 |
31 | public function dataLoad();
32 |
33 | public function loadBodyByContent($headers, $rawBody);
34 |
35 | public function buildBodyJson($contents);
36 |
37 | public function buildBodyXml($contents);
38 | }
39 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # safelist
2 | branches:
3 | only:
4 | - master
5 |
6 | # Required to run your project under the correct environment.
7 | language: php
8 |
9 | # Versions of PHP you want your project run with.
10 | # php:
11 | # - 5.3
12 | # - 5.4
13 | # - 5.5
14 | # - 5.6
15 | # - 7.0
16 | # - hhvm
17 |
18 | # Commands to be run before your environment runs.
19 | before_script:
20 | - composer self-update
21 | - composer install --prefer-source --no-interaction
22 |
23 | # allow_failures: Allow this build to fail under the specified environments.
24 | # fast_finish: If your build fails do not continue trying to build, just stop.
25 | matrix:
26 | include:
27 | - php: "5.3"
28 | env: SCRIPTBUILD=gitBuild
29 | - php: "5.4"
30 | env: SCRIPTBUILD=gitBuild
31 | - php: "5.5"
32 | env: SCRIPTBUILD=gitBuildCoverage
33 | - php: "5.6"
34 | env: SCRIPTBUILD=gitBuild
35 | - php: "7.0"
36 | env: SCRIPTBUILD=gitBuild
37 | - php: "hhvm"
38 | env: SCRIPTBUILD=gitBuild
39 | allow_failures:
40 | - php: hhvm
41 | fast_finish: true
42 |
43 | # Commands you want to run that will verify your build.
44 | script: composer run-script --timeout=0 $SCRIPTBUILD
45 |
46 | # Customize when the notification emails are sent.
47 | notifications:
48 | email:
49 | on_success: change
50 | on_failure: always
51 |
52 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Exception.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Exception
2 | ===============
3 |
4 | Description of Exception
5 |
6 |
7 |
8 |
9 | * Class name: Exception
10 | * Namespace: SwaggerValidator
11 | * Parent class: Exception
12 |
13 |
14 |
15 |
16 |
17 | Properties
18 | ----------
19 |
20 |
21 | ### $contextError
22 |
23 | private \SwaggerValidator\Common\Context $contextError
24 |
25 |
26 |
27 |
28 |
29 | * Visibility: **private**
30 |
31 |
32 | Methods
33 | -------
34 |
35 |
36 | ### setFile
37 |
38 | mixed SwaggerValidator\Exception::setFile($file)
39 |
40 |
41 |
42 |
43 |
44 | * Visibility: **public**
45 |
46 |
47 | #### Arguments
48 | * $file **mixed**
49 |
50 |
51 |
52 | ### setLine
53 |
54 | mixed SwaggerValidator\Exception::setLine($line)
55 |
56 |
57 |
58 |
59 |
60 | * Visibility: **public**
61 |
62 |
63 | #### Arguments
64 | * $line **mixed**
65 |
66 |
67 |
68 | ### setContext
69 |
70 | mixed SwaggerValidator\Exception::setContext(\SwaggerValidator\Common\Context $context)
71 |
72 |
73 |
74 |
75 |
76 | * Visibility: **public**
77 |
78 |
79 | #### Arguments
80 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
81 |
82 |
83 |
84 | ### getContext
85 |
86 | mixed SwaggerValidator\Exception::getContext()
87 |
88 |
89 |
90 |
91 |
92 | * Visibility: **public**
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Interfaces-ContextDataParser.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Interfaces\ContextDataParser
2 | ===============
3 |
4 |
5 |
6 |
7 |
8 |
9 | * Interface name: ContextDataParser
10 | * Namespace: SwaggerValidator\Interfaces
11 | * This is an **interface**
12 |
13 |
14 |
15 |
16 |
17 |
18 | Methods
19 | -------
20 |
21 |
22 | ### checkDataIsEmpty
23 |
24 | mixed SwaggerValidator\Interfaces\ContextDataParser::checkDataIsEmpty()
25 |
26 |
27 |
28 |
29 |
30 | * Visibility: **public**
31 |
32 |
33 |
34 |
35 | ### dataLoad
36 |
37 | mixed SwaggerValidator\Interfaces\ContextDataParser::dataLoad()
38 |
39 |
40 |
41 |
42 |
43 | * Visibility: **public**
44 |
45 |
46 |
47 |
48 | ### loadBodyByContent
49 |
50 | mixed SwaggerValidator\Interfaces\ContextDataParser::loadBodyByContent($headers, $rawBody)
51 |
52 |
53 |
54 |
55 |
56 | * Visibility: **public**
57 |
58 |
59 | #### Arguments
60 | * $headers **mixed**
61 | * $rawBody **mixed**
62 |
63 |
64 |
65 | ### buildBodyJson
66 |
67 | mixed SwaggerValidator\Interfaces\ContextDataParser::buildBodyJson($contents)
68 |
69 |
70 |
71 |
72 |
73 | * Visibility: **public**
74 |
75 |
76 | #### Arguments
77 | * $contents **mixed**
78 |
79 |
80 |
81 | ### buildBodyXml
82 |
83 | mixed SwaggerValidator\Interfaces\ContextDataParser::buildBodyXml($contents)
84 |
85 |
86 |
87 |
88 |
89 | * Visibility: **public**
90 |
91 |
92 | #### Arguments
93 | * $contents **mixed**
94 |
95 |
96 |
--------------------------------------------------------------------------------
/tests/phpunit/testcases/OverrideSwagger.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerTest;
20 |
21 | /**
22 | * Description of Swagger
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OverrideSwagger extends \SwaggerValidator\Object\Swagger
28 | {
29 |
30 | public $testProperties = true;
31 |
32 | /**
33 | * Var Export Method
34 | */
35 | public static function __set_state(array $properties)
36 | {
37 | $obj = new static;
38 |
39 | foreach ($properties as $key => $value) {
40 | if (property_exists(__CLASS__, $key)) {
41 | $obj->$key = $value;
42 | }
43 | else {
44 | $obj->__set($key, $value);
45 | }
46 | }
47 |
48 | return $obj;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/tests/phpunit/examples/multiSwaggerFile/parameters.json:
--------------------------------------------------------------------------------
1 | {
2 | "count": {
3 | "name": "count",
4 | "in": "query",
5 | "description": "Specifies the number of tweets to try and retrieve",
6 | "required": false,
7 | "type": "string"
8 | },
9 | "since_id": {
10 | "name": "since_id",
11 | "in": "query",
12 | "description": "Returns result with an ID greater than the specified ID",
13 | "required": false,
14 | "type": "string"
15 | },
16 | "max_id": {
17 | "name": "max_id",
18 | "in": "query",
19 | "description": "Returns results with an ID less than or equal to the specified ID",
20 | "required": false,
21 | "type": "string"
22 | },
23 | "trim_user": {
24 | "name": "trim_user",
25 | "in": "query",
26 | "description": "When set to either true, t or 1, each tweet returned in a timeline will include a user object",
27 | "required": false,
28 | "type": "string"
29 | },
30 | "contributor_details": {
31 | "name": "contributor_details",
32 | "in": "query",
33 | "description": "This parameter enhances the contributors element of the status response",
34 | "required": false,
35 | "type": "string"
36 | },
37 | "include_entities": {
38 | "name": "include_entities",
39 | "in": "query",
40 | "description": "The entities node will be disincluded when set to false",
41 | "required": false,
42 | "type": "string"
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Interfaces/ContextDataLoader.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Interfaces;
20 |
21 | /**
22 | *
23 | * @author Nicolas JUHEL
24 | * @version 1.0.0
25 | */
26 | interface ContextDataLoader
27 | {
28 |
29 | public function loadUri();
30 |
31 | public function getResponseStatus();
32 |
33 | public function getRequestFormDataKey();
34 |
35 | public function loadRequestFormData($paramName);
36 |
37 | public function loadRequestPath($paramName);
38 |
39 | public function getRequestQueryKey();
40 |
41 | public function loadRequestQuery($paramName);
42 |
43 | public function loadRequestHeader($paramName);
44 |
45 | public function loadResponseHeader($paramName);
46 |
47 | public function loadRequestBody();
48 |
49 | public function loadResponseBody();
50 | }
51 |
--------------------------------------------------------------------------------
/src/Exception.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator;
20 |
21 | /**
22 | * Description of Exception
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Exception extends \Exception
28 | {
29 |
30 | /**
31 | *
32 | * @var \SwaggerValidator\Common\Context
33 | */
34 | private $contextError;
35 |
36 | public function setFile($file)
37 | {
38 | if (!empty($file) && is_string($file)) {
39 | $this->file = $file;
40 | }
41 | }
42 |
43 | public function setLine($line)
44 | {
45 | if (!empty($line) && is_integer($line)) {
46 | $this->line = $line;
47 | }
48 | }
49 |
50 | public function setContext(\SwaggerValidator\Common\Context $context)
51 | {
52 | $this->contextError = $context;
53 | }
54 |
55 | public function getContext()
56 | {
57 | return $this->contextError;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/tests/phartest/phpunit.xml:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 | testcases/
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ../../bin
34 |
35 | ../../src
36 | ../../build
37 | ../../doc
38 | ../../tests
39 | ../../vendor
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/tests/phpunit/phpunit.xml:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 | testcases/
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ../../src
35 |
36 | ../../src/Example.php
37 | ../../bin
38 | ../../build
39 | ../../doc
40 | ../../tests
41 | ../../vendor
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/Interfaces/ContextLog.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Interfaces;
20 |
21 | /**
22 | *
23 | * @author Nicolas JUHEL
24 | * @version 1.0.0
25 | */
26 | interface ContextLog
27 | {
28 |
29 | public function logLoadFile($file, $method = null, $line = null);
30 |
31 | public function logDecode($className, $method = null, $line = null);
32 |
33 | public function logValidate($className, $method = null, $line = null);
34 |
35 | public function logModel($method = null, $line = null);
36 |
37 | public function logReference($type, $ref, $oldRef = null, $method = null, $line = null);
38 |
39 | public function logMessage($type, $message, $method = null, $line = null);
40 |
41 | public function logValidationError($validationType, $messageException = null, $method = null, $line = null);
42 |
43 | public function logException($messageException = null, $method = null, $line = null);
44 |
45 | public function throwException($message, $method = null, $line = null);
46 |
47 | public function setValidationError($valitionType, $messageException = null, $method = null, $line = null);
48 | }
49 |
--------------------------------------------------------------------------------
/tests/phartest/bootstrap.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * Bootstrap for PHPUnit
21 | *
22 | * @author Nicolas JUHEL
23 | * @version 1.0.0
24 | */
25 | define('PHPUNIT_PATH_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
26 | define('PHPUNIT_PATH_TEMP', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "tmp" . DIRECTORY_SEPARATOR);
27 | define('PHPUNIT_PATH_EXPECTED', PHPUNIT_PATH_ROOT . "expected" . DIRECTORY_SEPARATOR);
28 | define('PHPUNIT_PATH_EXAMPLE', PHPUNIT_PATH_ROOT . "examples" . DIRECTORY_SEPARATOR);
29 | define('REPOS_PATH_TESTS', dirname(PHPUNIT_PATH_ROOT) . DIRECTORY_SEPARATOR);
30 | define('REPOS_PATH_ROOT', dirname(REPOS_PATH_TESTS) . DIRECTORY_SEPARATOR);
31 | define('REPOS_PATH_SRC', REPOS_PATH_ROOT . 'src' . DIRECTORY_SEPARATOR);
32 | define('REPOS_PATH_BIN', REPOS_PATH_ROOT . 'bin' . DIRECTORY_SEPARATOR);
33 | define('SWAGGER_PATH_ROOT', REPOS_PATH_SRC);
34 |
35 | require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testcases' . DIRECTORY_SEPARATOR . 'genericTestClass.php';
36 | require_once REPOS_PATH_BIN . 'SwaggerValidator.phar';
37 |
38 | require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testcases' . DIRECTORY_SEPARATOR . 'OverrideSwagger.php';
39 |
--------------------------------------------------------------------------------
/tests/phpunit/bootstrap.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * Bootstrap for PHPUnit
21 | *
22 | * @author Nicolas JUHEL
23 | * @version 1.0.0
24 | */
25 | define('PHPUNIT_PATH_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
26 | define('PHPUNIT_PATH_TEMP', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "tmp" . DIRECTORY_SEPARATOR);
27 | define('PHPUNIT_PATH_EXPECTED', PHPUNIT_PATH_ROOT . "expected" . DIRECTORY_SEPARATOR);
28 | define('PHPUNIT_PATH_EXAMPLE', PHPUNIT_PATH_ROOT . "examples" . DIRECTORY_SEPARATOR);
29 | define('REPOS_PATH_TESTS', dirname(PHPUNIT_PATH_ROOT) . DIRECTORY_SEPARATOR);
30 | define('REPOS_PATH_ROOT', dirname(REPOS_PATH_TESTS) . DIRECTORY_SEPARATOR);
31 | define('REPOS_PATH_SRC', REPOS_PATH_ROOT . 'src' . DIRECTORY_SEPARATOR);
32 | define('REPOS_PATH_BIN', REPOS_PATH_ROOT . 'bin' . DIRECTORY_SEPARATOR);
33 | define('SWAGGER_PATH_ROOT', REPOS_PATH_SRC);
34 |
35 | require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testcases' . DIRECTORY_SEPARATOR . 'genericTestClass.php';
36 |
37 | require_once SWAGGER_PATH_ROOT . 'SwaggerAutoload.php';
38 | \SwaggerValidator\SwaggerAutoload::registerAutoloader();
39 |
40 | require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testcases' . DIRECTORY_SEPARATOR . 'OverrideSwagger.php';
41 |
--------------------------------------------------------------------------------
/src/Common/SandBoxItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Common;
20 |
21 | /**
22 | * Description of SandBoxItem
23 | *
24 | * @author Nicolas JUHEL
25 | */
26 | class SandBoxItem extends \SwaggerValidator\Common\Collection
27 | {
28 |
29 | public function jsonSerialize()
30 | {
31 | return null;
32 | }
33 |
34 | public function serialize()
35 | {
36 | return null;
37 | }
38 |
39 | public function unserialize($data)
40 | {
41 | return null;
42 | }
43 |
44 | public function get($name)
45 | {
46 | return parent::__get($name);
47 | }
48 |
49 | public function set($name, $value = null)
50 | {
51 | return parent::__set($name, $value);
52 | }
53 |
54 | /**
55 | * Var Export Method
56 | */
57 | protected function __storeData($key, $value = null)
58 | {
59 | if (property_exists($this, $key)) {
60 | $this->$key = $value;
61 | }
62 | else {
63 | parent::__storeData($key, $value);
64 | }
65 | }
66 |
67 | public static function __set_state(array $properties)
68 | {
69 | $obj = new static;
70 |
71 | foreach ($properties as $key => $value) {
72 | $obj->__storeData($key, $value);
73 | }
74 |
75 | return $obj;
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/Object/Contact.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Contact
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Contact extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
65 | }
66 |
67 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/Object/License.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of License
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class License extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
65 | }
66 |
67 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/Object/Definitions.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Definitions
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Definitions extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
65 | }
66 |
67 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/Object/ExternalDocs.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of ExternalDocs
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class ExternalDocs extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
65 | }
66 |
67 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/Object/SecurityItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Security
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class SecurityItem extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/Object/SecurityDefinitions.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of SecurityDefinitions
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class SecurityDefinitions extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/Object/SecurityRequirement.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of SecurityRequirement
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class SecurityRequirement extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/Object/Info.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Info
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Info extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
65 | }
66 |
67 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
68 | }
69 |
70 | public function getApiVersion()
71 | {
72 | if (isset($this->version) && is_string($this->version)) {
73 | return $this->version;
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/Object/Security.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Security
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Security extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | if (!is_array($jsonData)) {
62 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
63 | }
64 |
65 | parent::setJSONIsArray();
66 |
67 | foreach ($jsonData as $key => $value) {
68 |
69 | $value = $this->extractNonRecursiveReference($context, $value);
70 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
71 | }
72 |
73 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/Security/OAuth2PasswordSecurityScopes.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of oauth2PasswordSecurityScopes
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OAuth2PasswordSecurityScopes extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | if (!is_object($jsonData)) {
62 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
63 | }
64 |
65 | if (!($jsonData instanceof \stdClass)) {
66 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
67 | }
68 |
69 | foreach (get_object_vars($jsonData) as $key => $value) {
70 | $value = $this->extractNonRecursiveReference($context, $value);
71 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
72 | }
73 |
74 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/Security/BasicAuthenticationSecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of basicAuthenticationSecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class BasicAuthenticationSecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | if (!is_object($jsonData)) {
62 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
63 | }
64 |
65 | if (!($jsonData instanceof \stdClass)) {
66 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
67 | }
68 |
69 | foreach (get_object_vars($jsonData) as $key => $value) {
70 | $value = $this->extractNonRecursiveReference($context, $value);
71 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
72 | }
73 |
74 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/Security/ApiKeySecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of apiKeySecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class ApiKeySecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | parent::registerMandatoryKey('name');
34 | parent::registerMandatoryKey('in');
35 | }
36 |
37 | /**
38 | * Var Export Method
39 | */
40 | protected function __storeData($key, $value = null)
41 | {
42 | if (property_exists($this, $key)) {
43 | $this->$key = $value;
44 | }
45 | else {
46 | parent::__storeData($key, $value);
47 | }
48 | }
49 |
50 | public static function __set_state(array $properties)
51 | {
52 | $obj = new static;
53 |
54 | foreach ($properties as $key => $value) {
55 | $obj->__storeData($key, $value);
56 | }
57 |
58 | return $obj;
59 | }
60 |
61 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
62 | {
63 | if (!is_object($jsonData)) {
64 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
65 | }
66 |
67 | if (!($jsonData instanceof \stdClass)) {
68 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
69 | }
70 |
71 | foreach (get_object_vars($jsonData) as $key => $value) {
72 | $value = $this->extractNonRecursiveReference($context, $value);
73 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
74 | }
75 |
76 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/Security/OAuth2PasswordSecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of oauth2PasswordSecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OAuth2PasswordSecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | parent::registerMandatoryKey('flow');
34 | parent::registerMandatoryKey('tokenUrl');
35 | }
36 |
37 | /**
38 | * Var Export Method
39 | */
40 | protected function __storeData($key, $value = null)
41 | {
42 | if (property_exists($this, $key)) {
43 | $this->$key = $value;
44 | }
45 | else {
46 | parent::__storeData($key, $value);
47 | }
48 | }
49 |
50 | public static function __set_state(array $properties)
51 | {
52 | $obj = new static;
53 |
54 | foreach ($properties as $key => $value) {
55 | $obj->__storeData($key, $value);
56 | }
57 |
58 | return $obj;
59 | }
60 |
61 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
62 | {
63 | if (!is_object($jsonData)) {
64 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
65 | }
66 |
67 | if (!($jsonData instanceof \stdClass)) {
68 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
69 | }
70 |
71 | foreach (get_object_vars($jsonData) as $key => $value) {
72 | $value = $this->extractNonRecursiveReference($context, $value);
73 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
74 | }
75 |
76 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/Security/OAuth2ImplicitSecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of oauth2ImplicitSecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OAuth2ImplicitSecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | parent::registerMandatoryKey('flow');
34 | parent::registerMandatoryKey('authorizationUrl');
35 | }
36 |
37 | /**
38 | * Var Export Method
39 | */
40 | protected function __storeData($key, $value = null)
41 | {
42 | if (property_exists($this, $key)) {
43 | $this->$key = $value;
44 | }
45 | else {
46 | parent::__storeData($key, $value);
47 | }
48 | }
49 |
50 | public static function __set_state(array $properties)
51 | {
52 | $obj = new static;
53 |
54 | foreach ($properties as $key => $value) {
55 | $obj->__storeData($key, $value);
56 | }
57 |
58 | return $obj;
59 | }
60 |
61 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
62 | {
63 | if (!is_object($jsonData)) {
64 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
65 | }
66 |
67 | if (!($jsonData instanceof \stdClass)) {
68 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
69 | }
70 |
71 | foreach (get_object_vars($jsonData) as $key => $value) {
72 | $value = $this->extractNonRecursiveReference($context, $value);
73 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
74 | }
75 |
76 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/Security/OAuth2ApplicationSecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of oauth2ApplicationSecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OAuth2ApplicationSecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | parent::registerMandatoryKey('flow');
34 | parent::registerMandatoryKey('tokenUrl');
35 | }
36 |
37 | /**
38 | * Var Export Method
39 | */
40 | protected function __storeData($key, $value = null)
41 | {
42 | if (property_exists($this, $key)) {
43 | $this->$key = $value;
44 | }
45 | else {
46 | parent::__storeData($key, $value);
47 | }
48 | }
49 |
50 | public static function __set_state(array $properties)
51 | {
52 | $obj = new static;
53 |
54 | foreach ($properties as $key => $value) {
55 | $obj->__storeData($key, $value);
56 | }
57 |
58 | return $obj;
59 | }
60 |
61 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
62 | {
63 | if (!is_object($jsonData)) {
64 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
65 | }
66 |
67 | if (!($jsonData instanceof \stdClass)) {
68 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
69 | }
70 |
71 | foreach (get_object_vars($jsonData) as $key => $value) {
72 | $value = $this->extractNonRecursiveReference($context, $value);
73 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
74 | }
75 |
76 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/Security/OAuth2AccessCodeSecurity.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Security;
20 |
21 | /**
22 | * Description of oauth2AccessCodeSecurity
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class OAuth2AccessCodeSecurity extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | parent::registerMandatoryKey('flow');
34 | parent::registerMandatoryKey('authorizationUrl');
35 | parent::registerMandatoryKey('tokenUrl');
36 | }
37 |
38 | /**
39 | * Var Export Method
40 | */
41 | protected function __storeData($key, $value = null)
42 | {
43 | if (property_exists($this, $key)) {
44 | $this->$key = $value;
45 | }
46 | else {
47 | parent::__storeData($key, $value);
48 | }
49 | }
50 |
51 | public static function __set_state(array $properties)
52 | {
53 | $obj = new static;
54 |
55 | foreach ($properties as $key => $value) {
56 | $obj->__storeData($key, $value);
57 | }
58 |
59 | return $obj;
60 | }
61 |
62 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
63 | {
64 | if (!is_object($jsonData)) {
65 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
66 | }
67 |
68 | if (!($jsonData instanceof \stdClass)) {
69 | $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
70 | }
71 |
72 | foreach (get_object_vars($jsonData) as $key => $value) {
73 | $value = $this->extractNonRecursiveReference($context, $value);
74 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
75 | }
76 |
77 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Interfaces-ContextDataLoader.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Interfaces\ContextDataLoader
2 | ===============
3 |
4 |
5 |
6 |
7 |
8 |
9 | * Interface name: ContextDataLoader
10 | * Namespace: SwaggerValidator\Interfaces
11 | * This is an **interface**
12 |
13 |
14 |
15 |
16 |
17 |
18 | Methods
19 | -------
20 |
21 |
22 | ### loadUri
23 |
24 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadUri()
25 |
26 |
27 |
28 |
29 |
30 | * Visibility: **public**
31 |
32 |
33 |
34 |
35 | ### getResponseStatus
36 |
37 | mixed SwaggerValidator\Interfaces\ContextDataLoader::getResponseStatus()
38 |
39 |
40 |
41 |
42 |
43 | * Visibility: **public**
44 |
45 |
46 |
47 |
48 | ### getRequestFormDataKey
49 |
50 | mixed SwaggerValidator\Interfaces\ContextDataLoader::getRequestFormDataKey()
51 |
52 |
53 |
54 |
55 |
56 | * Visibility: **public**
57 |
58 |
59 |
60 |
61 | ### loadRequestFormData
62 |
63 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadRequestFormData($paramName)
64 |
65 |
66 |
67 |
68 |
69 | * Visibility: **public**
70 |
71 |
72 | #### Arguments
73 | * $paramName **mixed**
74 |
75 |
76 |
77 | ### loadRequestPath
78 |
79 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadRequestPath($paramName)
80 |
81 |
82 |
83 |
84 |
85 | * Visibility: **public**
86 |
87 |
88 | #### Arguments
89 | * $paramName **mixed**
90 |
91 |
92 |
93 | ### getRequestQueryKey
94 |
95 | mixed SwaggerValidator\Interfaces\ContextDataLoader::getRequestQueryKey()
96 |
97 |
98 |
99 |
100 |
101 | * Visibility: **public**
102 |
103 |
104 |
105 |
106 | ### loadRequestQuery
107 |
108 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadRequestQuery($paramName)
109 |
110 |
111 |
112 |
113 |
114 | * Visibility: **public**
115 |
116 |
117 | #### Arguments
118 | * $paramName **mixed**
119 |
120 |
121 |
122 | ### loadRequestHeader
123 |
124 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadRequestHeader($paramName)
125 |
126 |
127 |
128 |
129 |
130 | * Visibility: **public**
131 |
132 |
133 | #### Arguments
134 | * $paramName **mixed**
135 |
136 |
137 |
138 | ### loadResponseHeader
139 |
140 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadResponseHeader($paramName)
141 |
142 |
143 |
144 |
145 |
146 | * Visibility: **public**
147 |
148 |
149 | #### Arguments
150 | * $paramName **mixed**
151 |
152 |
153 |
154 | ### loadRequestBody
155 |
156 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadRequestBody()
157 |
158 |
159 |
160 |
161 |
162 | * Visibility: **public**
163 |
164 |
165 |
166 |
167 | ### loadResponseBody
168 |
169 | mixed SwaggerValidator\Interfaces\ContextDataLoader::loadResponseBody()
170 |
171 |
172 |
173 |
174 |
175 | * Visibility: **public**
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/src/Example.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * @author Nicolas JUHEL
21 | * @version 1.0.0
22 | */
23 | if (file_exists('bin/SwaggerValidator.phar')) {
24 | //using phar package
25 | include_once 'phar://bin/SwaggerValidator.phar';
26 | }
27 | else {
28 | // using source package
29 | include_once 'Swagger.php';
30 | }
31 |
32 | date_default_timezone_set('UTC');
33 |
34 | //\SwaggerValidator\Swagger::setSwaggerFile("swagger_example.json");
35 | \SwaggerValidator\Swagger::setSwaggerFile(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . 'swaggerPetStoreHeroku.json');
36 | $swagger = \SwaggerValidator\Swagger::load(new \SwaggerValidator\Common\Context());
37 |
38 | /**
39 | * Validate request in Deny Mode (like strict : generate error if request is in error)
40 | */
41 | $swagger->validate(new \SwaggerValidator\Common\Context(\SwaggerValidator\Common\Context::TYPE_REQUEST, \SwaggerValidator\Common\Context::MODE_DENY));
42 |
43 | /**
44 | * Validate request in Pass Mode (like ignore & clean : clean not validated parameters in request)
45 | */
46 | $swagger->validate(new \SwaggerValidator\Common\Context(\SwaggerValidator\Common\Context::TYPE_REQUEST, \SwaggerValidator\Common\Context::MODE_PASS));
47 |
48 | /**
49 | * Validate response in Deny Mode (like strict : generate error if request is in error)
50 | */
51 | $swagger->validate(new \SwaggerValidator\Common\Context(\SwaggerValidator\Common\Context::TYPE_RESPONSE, \SwaggerValidator\Common\Context::MODE_DENY));
52 |
53 | /**
54 | * Validate response in Pass Mode (like ignore & clean : clean not validated element in response)
55 | */
56 | $swagger->validate(new \SwaggerValidator\Common\Context(\SwaggerValidator\Common\Context::TYPE_RESPONSE, \SwaggerValidator\Common\Context::MODE_PASS));
57 |
58 | /**
59 | * Generate an array for each operation with request & response model
60 | * use example in the sagger primitive type to define example
61 | * or less the swagger validator generate example contents
62 | */
63 | $swagger->getModel(new \SwaggerValidator\Common\Context());
64 |
65 | json_encode($swagger);
66 |
--------------------------------------------------------------------------------
/src/SwaggerAutoload.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator;
20 |
21 | /**
22 | * Description of SwaggerCommonAutoload
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | final class SwaggerAutoload
28 | {
29 | /* * ******************************************************************************
30 | * PSR-0 Autoloader
31 | *
32 | * Do not use if you are using Composer to autoload dependencies.
33 | * ***************************************************************************** */
34 |
35 | /**
36 | * Slim PSR-0 autoloader
37 | */
38 | final public static function autoload($className)
39 | {
40 | if (\Phar::running() && defined('PHAR_SWAGGER_VALIDATOR_ROOT_PATH')) {
41 | $baseDir = PHAR_SWAGGER_VALIDATOR_ROOT_PATH;
42 | }
43 | elseif (\Phar::running()) {
44 | $baseDir = null;
45 | }
46 | else {
47 | $baseDir = __DIR__ . DIRECTORY_SEPARATOR;
48 | }
49 |
50 | $thisClass = 'SwaggerValidator';
51 |
52 | $namespace = explode('\\', $className);
53 | $className = array_pop($namespace);
54 | $rootPath = array_shift($namespace);
55 |
56 | if ($rootPath == $thisClass) {
57 | $namespace = $baseDir . trim(implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
58 | }
59 | else {
60 | $namespace = $baseDir . trim($rootPath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $namespace), DIRECTORY_SEPARATOR);
61 | }
62 |
63 | if (substr($namespace, -1, 1) != DIRECTORY_SEPARATOR) {
64 | $namespace .= DIRECTORY_SEPARATOR;
65 | }
66 |
67 | if ($namespace == DIRECTORY_SEPARATOR) {
68 | $namespace = "";
69 | }
70 |
71 | $fileName = $namespace . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
72 |
73 | if (file_exists($fileName)) {
74 | require_once $fileName;
75 | }
76 | }
77 |
78 | /**
79 | * Register Slim's PSR-0 autoloader
80 | */
81 | final public static function registerAutoloader()
82 | {
83 | spl_autoload_register("\\SwaggerValidator\\SwaggerAutoload::autoload");
84 | }
85 |
86 | }
87 |
88 | require_once 'Compat.php';
89 |
--------------------------------------------------------------------------------
/tests/pharBuilder/makePhar.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * Builder for PHAR archive
21 | *
22 | * @author Nicolas JUHEL
23 | * @version 1.0.0
24 | */
25 | define('REPOS_PATH_ROOT', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR);
26 | define('REPOS_PATH_SRC', REPOS_PATH_ROOT . 'src' . DIRECTORY_SEPARATOR);
27 | define('REPOS_PATH_BIN', REPOS_PATH_ROOT . 'bin' . DIRECTORY_SEPARATOR);
28 | define('SWAGGER_PATH_ROOT', REPOS_PATH_SRC);
29 |
30 | function getPrivateKey($pharPath)
31 | {
32 | /*
33 | * Generate a key with this command :
34 | * openssl genrsa -out key.priv.pem -aes256 4096
35 | * openssl rsa -in key.priv.pem -pubout -out key.pub.pem
36 | */
37 | $path = dirname(__FILE__);
38 | $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
39 | $path = str_replace('//', '/', $path . '/key.priv.pem');
40 | $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
41 |
42 | copy(str_replace('.priv.', '.pub.', $path), $pharPath . '.pubkey');
43 |
44 | $private = openssl_get_privatekey(file_get_contents($path), readline('Passphrase :'));
45 | $result = '';
46 |
47 | openssl_pkey_export($private, $result);
48 | return $private;
49 | }
50 |
51 | if (!Phar::canWrite()) {
52 | die("\n\n\t\t" . 'cannot write phar : change the ini phar.readonly to 0 !!' . "\n\n");
53 | }
54 |
55 | $pharPath = REPOS_PATH_BIN . 'SwaggerValidator.phar';
56 | $phar = new Phar($pharPath, 0, 'SwaggerValidator.phar');
57 |
58 | //$phar->buildFromDirectory(getPath());
59 | $list = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath(SWAGGER_PATH_ROOT), FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS));
60 | $files = array();
61 | $exclude = array(
62 | '/Example.php',
63 | );
64 |
65 | foreach ($list as $key => $value) {
66 | $key = str_replace(realpath(SWAGGER_PATH_ROOT), '', $key);
67 |
68 | if (in_array($key, $exclude)) {
69 | continue;
70 | }
71 |
72 | $files[$key] = $value . "";
73 | }
74 | if (version_compare(PHP_VERSION, '5.4', '<')) {
75 | ksort($files);
76 | }
77 | else {
78 | ksort($files, SORT_NATURAL);
79 | }
80 |
81 | $phar->buildFromIterator(new ArrayIterator($files));
82 | $phar->setDefaultStub('Swagger.php');
83 | //$phar->setSignatureAlgorithm(Phar::OPENSSL, getPrivateKey($pharPath));
84 |
85 |
86 |
--------------------------------------------------------------------------------
/src/Interfaces/ContextBase.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Interfaces;
20 |
21 | /**
22 | *
23 | * @author Nicolas JUHEL
24 | */
25 | interface ContextBase
26 | {
27 |
28 | public function __construct($mode = null, $type = null);
29 |
30 | public function __get($name);
31 |
32 | public function __set($name, $value);
33 |
34 | public function __isset($name);
35 |
36 | public function __unset($name);
37 |
38 | public function __toString();
39 |
40 | public function __debugInfo();
41 |
42 | public function setMode($value = null);
43 |
44 | public function getMode();
45 |
46 | public function setType($value = null);
47 |
48 | public function getType();
49 |
50 | public function setLocation($value = null);
51 |
52 | public function getLocation();
53 |
54 | public function setMethod($value = null);
55 |
56 | public function getMethod();
57 |
58 | public function loadMethod();
59 |
60 | public function setBasePath($value = null);
61 |
62 | public function getBasePath();
63 |
64 | public function setRoutePath($value = null);
65 |
66 | public function getRoutePath();
67 |
68 | public function setRequestPath($value = null);
69 |
70 | public function getRequestPath();
71 |
72 | public function setScheme($value = null);
73 |
74 | public function getScheme();
75 |
76 | public function setHost($value = null);
77 |
78 | public function getHost();
79 |
80 | public function addContext($key = null, $value = null);
81 |
82 | public function getContext();
83 |
84 | public function setCombined($value = false);
85 |
86 | public function getCombined();
87 |
88 | public function setDataPath($value = null);
89 |
90 | public function getDataPath();
91 |
92 | public function setExternalRef($value = null);
93 |
94 | public function getExternalRef();
95 |
96 | public function getLastExternalRef();
97 |
98 | public function checkExternalRef($value = NULL);
99 |
100 | public function setDataCheck($value = null);
101 |
102 | public function getDataCheck();
103 |
104 | public function setDataValue($value = null);
105 |
106 | public function getDataValue();
107 |
108 | public function isDataExists();
109 |
110 | public function isDataEmpty();
111 | }
112 |
--------------------------------------------------------------------------------
/src/Object/ParameterBody.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of ParameterBody
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class ParameterBody extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('schema');
33 | parent::__set('name', \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY);
34 | }
35 |
36 | /**
37 | * Var Export Method
38 | */
39 | protected function __storeData($key, $value = null)
40 | {
41 | if (property_exists($this, $key)) {
42 | $this->$key = $value;
43 | }
44 | else {
45 | parent::__storeData($key, $value);
46 | }
47 | }
48 |
49 | public static function __set_state(array $properties)
50 | {
51 | $obj = new static;
52 |
53 | foreach ($properties as $key => $value) {
54 | $obj->__storeData($key, $value);
55 | }
56 |
57 | return $obj;
58 | }
59 |
60 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
61 | {
62 | $this->checkJsonObject($context, $jsonData);
63 |
64 | $schemaKey = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
65 |
66 | if (property_exists($jsonData, $schemaKey)) {
67 | $jsonData->$schemaKey = $this->extractNonRecursiveReference($context, $jsonData->$schemaKey);
68 | }
69 |
70 | foreach (get_object_vars($jsonData) as $key => $value) {
71 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
72 | }
73 |
74 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
75 | }
76 |
77 | public function validate(\SwaggerValidator\Common\Context $context)
78 | {
79 | $keySchema = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
80 | return $this->$keySchema->validate($context);
81 | }
82 |
83 | public function getModel(\SwaggerValidator\Common\Context $context)
84 | {
85 | $schemaKey = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
86 | return $this->$schemaKey->getModel($context->setType(\SwaggerValidator\Common\Context::TYPE_REQUEST));
87 | }
88 |
89 | public function isRequired()
90 | {
91 | if (isset($this->required)) {
92 | return (bool) ($this->required);
93 | }
94 |
95 | return false;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/Object/Headers.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Headers
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Headers extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 | $value = $this->extractNonRecursiveReference($context, $value);
65 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
66 | }
67 |
68 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
69 | }
70 |
71 | public function validate(\SwaggerValidator\Common\Context $context)
72 | {
73 | $check = true;
74 |
75 | foreach ($this->keys() as $key) {
76 | if (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\Object\HeaderItem)) {
77 | $check = $check && $this->$key->validate($context->setDataPath($key)->setSandBox());
78 | }
79 | }
80 |
81 | return $check;
82 | }
83 |
84 | public function getModel(\SwaggerValidator\Common\Context $context, $globalResponse = array())
85 | {
86 | foreach ($this->keys() as $key) {
87 |
88 | if (!is_object($this->$key) || !($this->$key instanceof \SwaggerValidator\Object\HeaderItem)) {
89 | continue;
90 | }
91 |
92 | $globalResponse[$key] = $this->$key->getModel($context->setDataPath($key));
93 | }
94 |
95 | $context->logModel(__METHOD__, __LINE__);
96 | return $globalResponse;
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/tests/pharBuilder/key.priv.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | Proc-Type: 4,ENCRYPTED
3 | DEK-Info: AES-256-CBC,81BF3495F2C9DA743AA25BA5C85BA41B
4 |
5 | ELVEuJUrmcwA/E2Cjb35mhFuutb5Lj9qyMg/rnseZaa8dkQ6FZrgIkcpN93YWP5Q
6 | 4g2Y6g9kMOLA2v1BCVO0ZqAa3T3DwTkBNBo0B9xKGXHlmjop9U71Cq/vaRsPsoal
7 | yp3ejfN8wNv6QrYZEkQymn8J0Eq06kBVoNcBtUsV76yJpjZxp5LMHgxp6GIu3WGI
8 | F/v7MSw8FPmURGyix8NNbDkextf2Abl8qCKikKZaUs7NUqTuv8MRzNZOniZyKV6e
9 | vWb90er1xzoC9D7QylgnNpzWVaVnBdGy/ZjqU7WkPEKabxZiAZL+d49s0BWRYuRO
10 | 1cgot3IluzdXiSenfy0w0IYAG61bO1hkahTvU7aP164PiCSBmA/87jOhWxJ7OmkO
11 | 6cQhCwXtrcQ/x+RHBUMMCckC25zCdcIPb0WiD7bjh7VYbYaYIzTgmIQG2b3FqPoY
12 | CSgBeSZUPW91y1Em5mPRrXhaEVUZfazDXRY1SfQnnHbpgjdGyog/MvXYGyItCjBU
13 | kJrDjqtV99XHWmNZFujJ+orO9NjFItPJNGVLlXoBFd0DiCgsXHxWCek7B7hO127f
14 | xggYzzgHBMqBEWAtEmN+dZooiTaS3+F9bFlwRy//pUnxevCpOkAbMI2zUumxXGnP
15 | P1SZml8V4PQzz3NYRgn9QrgflLHVOZlhTStiXfTKHPKtuUBuOJ1f35xM09d+Lzuz
16 | auRuqH/ke6VrbTGqdkZgdPbL3yRZPN/pIVjQx1CNWFHdy2nL5HgqprB7NvtWmj1L
17 | w46JDFGksGW/ETu96OnGE9ceXKaJuiqiC1c13ffQorqnrv1fm68JkaU7icjMmCeg
18 | oivsEr1DuaPROdUGxOanx6sU1BNf6z1mRKaxyYNom/9/RTK/vIZ721gmTtZEo6wk
19 | 0dVmfhm17r+lS2/SkCTfGWSWfp87aBzrf4uE5y/u4BogUD1t8KOT+baXlaG2Ifhj
20 | zpBwj7dexwFXq9PfaTxRPEYudWvSh7do2XrwgIwvdlE9rXQKSXidaFZWG0zBIjO/
21 | tlgOd9zq7+10roBTfec3Cd+R1mVuRlq9uOvrXf6J6PyXi5ImT8M5OpWVv3NJK9ny
22 | Vmd9+7ktV6Bqwm7HE66gPwCrJmRx1fDxQbghMNyx9eR+XwUmh7avkHkC4Y8ld/Vd
23 | 3BNDYHEXTXcd4A4gQrEVkh+3Q3VtIPRyPCFoxwZmrCLXkrmq6eyEFMT7xUBuDiEr
24 | Ssy44aWrLIj85vkhJ2XJesAhhAGxPxR4PlpFdKxSL3jcWFAnika+ks8M5GN0fs6R
25 | HI4BGhU3fojyF55qDE4q50vKicJGAlHHDlwn20NeC+tOygnrtfc9+7lkIZNRQBDB
26 | 0rnaSndmWrxTcKWRanmPsrOzAHjcUfziVTb+D2hZFPrOEbb+BKmymEcUZSMM17mB
27 | VtYCgbgkw3q79YQeGubghvyqvv2gHg3KYbqODuwzdSZxUMhopxK1qrYHaFVN2ptj
28 | Xjd+oux6P/7CDLsIwN8nucpcUK0iprfickIsn4BIxK4WF+jSVD1OuiPrpvRxOiiR
29 | pC3RKUrRiGZgDDsr3kOrhEJUevHKIIKRzQq6urdkwRYH2kVMORACxY7RJpUcObmW
30 | BeF3VXDtEPH8FHlMytBm8VLuAc18itg00fZWgplvZDNhASd1VtGzgqpejVWJfl+O
31 | eu2GL/hoJhqaggBcsk3aQ4J1JbEXq9QMUeoT181FC8MfWZKosV8NNmXQP14TJqCj
32 | 5hK+z+yXhbcJrWruOiyJATWeCJzYcROCUtIZ/5beQ3PjdsUtIisRPFYgTLmdkmau
33 | ozavWlcHp493QznkIJqXCFLsdyHKtbqf4koahFt+Ksosg46kccqNOnMZr6wD57qj
34 | B681sp0xw1yd/ZP4HxCOooeV9/eOwaqa25FpE0q5hSJXFMxRAM9mRQJqAA4zAVDE
35 | REhIyEJuX5PDDtl+GkhQSqNXoboEzI4NWNiFnApQKI39L4oCdKjITLVnt2HsEtz6
36 | zs4RlaUV8/2ALi0Q+jJQkOOowNVnH3ofjkRi7pWrff+FwNaSy3jBryiTRpm72Sfo
37 | Y4Zlmgm9emPPvWgx1BLQR/66DIm6QWUBRhmFeYz8Ar9nu6zMgxwLyn+j0b81IkKe
38 | J/Bm//nanH8WC9EH3w1cBhPqkR6b8o++lJuk+zl9/SXdbmGpgwgoPJb3nIljeRgM
39 | 7f2rv4z2g8PIkBoNiRwSTGMitrxilP70u0eEewzbf+WjpGnT49hyqytSuSejiK9/
40 | I6MVX3oHkox8k7VzdrXVYFueSSoH66c74kzz17/q2ZxgKIuNW6ehZsT9NzlhZyo5
41 | X5xZprJbND3n2XAR7EdccT8tzA7CUnW8FXP+/olyzaJ5y7F95R+0OJODyeiyB/cN
42 | s5Kbakyx9eGrS3CpfGVcY7o6JkCMvQH7RUggV18qJ7IBSpQpNeT3UkSPIk/s+MCj
43 | +GukSXwCfd5t1+29345Pj7SdKuyfp3l2K55ocWHypQOLzIqZwbO+QA6GTPmLw/JN
44 | ql2EVtSsnnoMrxqiY6+B1cnT7pu6OMB3VYWjVcyr2AHQHIWwLTZeYXdWT0M9ZldO
45 | OZP9b+Hp5zBKLoTQvtp/mjq0azKWZsLKFfBpE1nsty3INuQ4EIF5s5Oy7ywrQ77b
46 | /ws+1AbQOTPJzc77+WFBdDtOBIKQ1ofxlB1gHJkVXToq9xvbYjzy3tmEd+WvpOJu
47 | qGlWHaYXinQRuwBKydjpHaHf9MH1//e+6GWER6Ai/fsWEVwYnqTPKLlyfw+kVvhj
48 | wjRLRuT4DLt8ZPp3l2bpjlRlgEA93Pauf6owY8aABcKnflxVCvFQ9eGcZFoL92Ki
49 | 6LfhmE6wGl3zAxDQqglONsMeQb9aXI+prZrVqV1nAaF49htCQxJPDVerTNGsThfK
50 | kn/Ai4uZ6vp+IKtHEQp54jsL91GaHDKZIaUQoJeu41gb+NDOxW3k7wrLV9lCP+Id
51 | /VqZuOSmiHbNtrWHxMa15UYc1KL+Xj+V7s+qgERky7hlLQD7ypi0XQTDRy0lKsym
52 | 37wAG+Czoa09yErpyQ0EZyu77OU8Ks8IT0yL5G4cEXK5MppaRQCeE3B/hgiT+MmW
53 | ax02RNwvfmqBQZLFtUBrG7j27QxDR2+orC092hNvLI4Qx5P9wsPx3M2voM/sXQCm
54 | -----END RSA PRIVATE KEY-----
55 |
--------------------------------------------------------------------------------
/src/Object/HeaderItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of HeaderItem
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class HeaderItem extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | const KEY_ITEM = 'item';
31 |
32 | public function __construct()
33 | {
34 |
35 | }
36 |
37 | /**
38 | * Var Export Method
39 | */
40 | protected function __storeData($key, $value = null)
41 | {
42 | if (property_exists($this, $key)) {
43 | $this->$key = $value;
44 | }
45 | else {
46 | parent::__storeData($key, $value);
47 | }
48 | }
49 |
50 | public static function __set_state(array $properties)
51 | {
52 | $obj = new static;
53 |
54 | foreach ($properties as $key => $value) {
55 | $obj->__storeData($key, $value);
56 | }
57 |
58 | return $obj;
59 | }
60 |
61 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
62 | {
63 | $this->checkJsonObject($context, $jsonData);
64 | $keyItem = self::KEY_ITEM;
65 |
66 | $header = $this->extractNonRecursiveReference($context, $jsonData);
67 |
68 | $this->set(
69 | $keyItem, \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize(
70 | $context->setDataPath('header'), $this->getCleanClass(__CLASS__), $this->name, $header
71 | )
72 | );
73 |
74 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
75 | }
76 |
77 | public function jsonSerialize()
78 | {
79 | return json_decode(parent::jsonEncode($this->item));
80 | }
81 |
82 | public function validate(\SwaggerValidator\Common\Context $context)
83 | {
84 | if ($this->__isset(self::KEY_ITEM)) {
85 |
86 | $context->setLocation(\SwaggerValidator\Common\FactorySwagger::LOCATION_HEADER);
87 | $context->dataLoad();
88 |
89 | return $this->get(self::KEY_ITEM)->validate($context);
90 | }
91 |
92 | $context->throwException('Cannot find a well formed item in the headeritem object', __METHOD__, __LINE__);
93 | }
94 |
95 | public function getModel(\SwaggerValidator\Common\Context $context)
96 | {
97 | if ($this->__isset(self::KEY_ITEM)) {
98 |
99 | $context->setLocation(\SwaggerValidator\Common\FactorySwagger::LOCATION_HEADER);
100 |
101 | return $this->get(self::KEY_ITEM)->getModel($context);
102 | }
103 |
104 | $context->throwException('Cannot find a well formed item in the headeritem object', __METHOD__, __LINE__);
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Interfaces-ContextLog.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Interfaces\ContextLog
2 | ===============
3 |
4 |
5 |
6 |
7 |
8 |
9 | * Interface name: ContextLog
10 | * Namespace: SwaggerValidator\Interfaces
11 | * This is an **interface**
12 |
13 |
14 |
15 |
16 |
17 |
18 | Methods
19 | -------
20 |
21 |
22 | ### logLoadFile
23 |
24 | mixed SwaggerValidator\Interfaces\ContextLog::logLoadFile($file, $method, $line)
25 |
26 |
27 |
28 |
29 |
30 | * Visibility: **public**
31 |
32 |
33 | #### Arguments
34 | * $file **mixed**
35 | * $method **mixed**
36 | * $line **mixed**
37 |
38 |
39 |
40 | ### logDecode
41 |
42 | mixed SwaggerValidator\Interfaces\ContextLog::logDecode($className, $method, $line)
43 |
44 |
45 |
46 |
47 |
48 | * Visibility: **public**
49 |
50 |
51 | #### Arguments
52 | * $className **mixed**
53 | * $method **mixed**
54 | * $line **mixed**
55 |
56 |
57 |
58 | ### logValidate
59 |
60 | mixed SwaggerValidator\Interfaces\ContextLog::logValidate($className, $method, $line)
61 |
62 |
63 |
64 |
65 |
66 | * Visibility: **public**
67 |
68 |
69 | #### Arguments
70 | * $className **mixed**
71 | * $method **mixed**
72 | * $line **mixed**
73 |
74 |
75 |
76 | ### logModel
77 |
78 | mixed SwaggerValidator\Interfaces\ContextLog::logModel($method, $line)
79 |
80 |
81 |
82 |
83 |
84 | * Visibility: **public**
85 |
86 |
87 | #### Arguments
88 | * $method **mixed**
89 | * $line **mixed**
90 |
91 |
92 |
93 | ### logReference
94 |
95 | mixed SwaggerValidator\Interfaces\ContextLog::logReference($type, $ref, $oldRef, $method, $line)
96 |
97 |
98 |
99 |
100 |
101 | * Visibility: **public**
102 |
103 |
104 | #### Arguments
105 | * $type **mixed**
106 | * $ref **mixed**
107 | * $oldRef **mixed**
108 | * $method **mixed**
109 | * $line **mixed**
110 |
111 |
112 |
113 | ### logMessage
114 |
115 | mixed SwaggerValidator\Interfaces\ContextLog::logMessage($type, $message, $method, $line)
116 |
117 |
118 |
119 |
120 |
121 | * Visibility: **public**
122 |
123 |
124 | #### Arguments
125 | * $type **mixed**
126 | * $message **mixed**
127 | * $method **mixed**
128 | * $line **mixed**
129 |
130 |
131 |
132 | ### logValidationError
133 |
134 | mixed SwaggerValidator\Interfaces\ContextLog::logValidationError($validationType, $messageException, $method, $line)
135 |
136 |
137 |
138 |
139 |
140 | * Visibility: **public**
141 |
142 |
143 | #### Arguments
144 | * $validationType **mixed**
145 | * $messageException **mixed**
146 | * $method **mixed**
147 | * $line **mixed**
148 |
149 |
150 |
151 | ### logException
152 |
153 | mixed SwaggerValidator\Interfaces\ContextLog::logException($messageException, $method, $line)
154 |
155 |
156 |
157 |
158 |
159 | * Visibility: **public**
160 |
161 |
162 | #### Arguments
163 | * $messageException **mixed**
164 | * $method **mixed**
165 | * $line **mixed**
166 |
167 |
168 |
169 | ### throwException
170 |
171 | mixed SwaggerValidator\Interfaces\ContextLog::throwException($message, $method, $line)
172 |
173 |
174 |
175 |
176 |
177 | * Visibility: **public**
178 |
179 |
180 | #### Arguments
181 | * $message **mixed**
182 | * $method **mixed**
183 | * $line **mixed**
184 |
185 |
186 |
187 | ### setValidationError
188 |
189 | mixed SwaggerValidator\Interfaces\ContextLog::setValidationError($valitionType, $messageException, $method, $line)
190 |
191 |
192 |
193 |
194 |
195 | * Visibility: **public**
196 |
197 |
198 | #### Arguments
199 | * $valitionType **mixed**
200 | * $messageException **mixed**
201 | * $method **mixed**
202 | * $line **mixed**
203 |
204 |
205 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "njuhel/swagger-validator",
3 | "description": "A Swagger Validation and Parser as lib for PHP to secure and helpful application for request / response validating, security stage, testunit skeleton, testauto generation, ... This lib can be used into any existing application who's having a swagger definition file for request/response (no framework dependancies or included).",
4 | "version": "1.3.2-dev",
5 | "type": "library",
6 | "keywords": ["swagger", "OAI", "openapi", "validator", "parser", "filter", "model", "security", "api", "restfull", "php"],
7 | "license": "Apache-2.0",
8 | "authors": [
9 | {
10 | "name": "Nicolas JUHEL",
11 | "email": "swaggervalidator@nabbar.com",
12 | "role": "Lead Developer"
13 | }
14 | ],
15 | "support": {
16 | "email": "swaggervalidator@nabbar.com"
17 | },
18 | "bin": [
19 | "bin/SwaggerValidator.phar"
20 | ],
21 | "archive": {
22 | "exclude": ["!/src", "!/bin"]
23 | },
24 | "autoload": {
25 | "psr-4": {
26 | "SwaggerValidator\\": "src/"
27 | }
28 | },
29 | "minimum-stability": "stable",
30 | "prefer-stable": true,
31 | "require": {
32 | "php": ">5.3.10",
33 | "ext-bcmath": "*",
34 | "ext-dom": "*",
35 | "ext-json": "*",
36 | "ext-pcre": "*",
37 | "ext-reflection": "*",
38 | "ext-spl": "*"
39 | },
40 | "require-dev": {
41 | "phpunit/phpunit": "<=5.6",
42 | "phpunit/php-file-iterator": "^1.4",
43 | "phpunit/php-text-template": "^1.2",
44 | "phpunit/php-code-coverage": "<=4.0",
45 | "phpunit/php-timer": "^1",
46 | "phpunit/phpunit-mock-objects": "<=3.4",
47 | "codeclimate/php-test-reporter": "dev-master",
48 | "phpdocumentor/phpdocumentor" : "^2.0",
49 | "evert/phpdoc-md" : "^0.2"
50 | },
51 | "scripts": {
52 | "Coverage": [
53 | "php vendor/phpunit/phpunit/phpunit --enforce-time-limit --debug --process-isolation --report-useless-tests --colors=always --stop-on-error --stop-on-failure --verbose --configuration tests/phpunit/phpunit.xml --bootstrap tests/phpunit/bootstrap.php --coverage-clover=build/logs/clover.xml --coverage-text=php://stdout"
54 | ],
55 | "Phpunit": [
56 | "php vendor/phpunit/phpunit/phpunit --enforce-time-limit --debug --process-isolation --report-useless-tests --colors=always --stop-on-error --stop-on-failure --verbose --configuration tests/phpunit/phpunit.xml --bootstrap tests/phpunit/bootstrap.php"
57 | ],
58 | "PharBuilder": [
59 | "php -d phar.readonly=0 -f tests/pharBuilder/makePhar.php",
60 | "chmod ugo+x bin/SwaggerValidator.phar"
61 | ],
62 | "PharTest": [
63 | "php vendor/phpunit/phpunit/phpunit --enforce-time-limit --debug --process-isolation --report-useless-tests --colors=always --stop-on-error --stop-on-failure --verbose --configuration tests/phartest/phpunit.xml --bootstrap tests/phartest/bootstrap.php"
64 | ],
65 | "PhpDoc": [
66 | "rm -vrf doc/; mkdir -vp doc;mkdir -vp temp;",
67 | "vendor/phpdocumentor/phpdocumentor/bin/phpdoc -c ./phpdoc.xml --target ./doc --validate --progressbar --cache-folder ./temp",
68 | "vendor/evert/phpdoc-md/bin/phpdocmd doc/structure.xml doc/",
69 | "rm -rf doc/structure.xml temp/; mv doc/ApiIndex.md doc/README.md"
70 | ],
71 | "build": [
72 | "@Phpunit",
73 | "@PharBuilder",
74 | "@PharTest",
75 | "@Coverage",
76 | "@PhpDoc"
77 | ],
78 | "gitBuild": [
79 | "@Phpunit",
80 | "@PharBuilder",
81 | "@PharTest"
82 | ],
83 | "gitBuildCoverage": [
84 | "@PharBuilder",
85 | "@PharTest",
86 | "@Coverage",
87 | "./vendor/bin/test-reporter"
88 | ],
89 | "test": [
90 | "@Phpunit"
91 | ]
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/DataType/TypeFile.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\DataType;
20 |
21 | /**
22 | * Description of File
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class TypeFile extends \SwaggerValidator\DataType\TypeCommon
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function validate(\SwaggerValidator\Common\Context $context)
60 | {
61 | if ($context->getLocation() !== \SwaggerValidator\Common\FactorySwagger::LOCATION_FORM) {
62 | return $context->setDataCheck('location/type')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
63 | }
64 |
65 | if (!isset($this->type)) {
66 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
67 | }
68 |
69 | if ($this->type != \SwaggerValidator\Common\FactorySwagger::TYPE_FILE) {
70 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
71 | }
72 |
73 | $value = $context->getDataValue();
74 |
75 | if (is_array($value) && !empty($value['tmp_name']) && array_key_exists('error', $value)) {
76 |
77 | if ($value['error'] == UPLOAD_ERR_OK) {
78 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
79 | return true;
80 | }
81 | else {
82 | return $context->setDataCheck('type')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATAVALUE, null, __METHOD__, __LINE__);
83 | }
84 | }
85 |
86 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATATYPE, null, __METHOD__, __LINE__);
87 | }
88 |
89 | protected function format(\SwaggerValidator\Common\Context $context, $valueParams)
90 | {
91 | return true;
92 | }
93 |
94 | protected function type(\SwaggerValidator\Common\Context $context, $valueParams)
95 | {
96 | return true;
97 | }
98 |
99 | protected function getExampleFormat(\SwaggerValidator\Common\Context $context)
100 | {
101 | return $this->getExampleType($context);
102 | }
103 |
104 | protected function getExampleType(\SwaggerValidator\Common\Context $context)
105 | {
106 | $context->logModel(__METHOD__, __LINE__);
107 | return array(
108 | 'tmp_name' => uniqid('file_'),
109 | 'error' => UPLOAD_ERR_OK,
110 | );
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/Object/PathItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of PathItem
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class PathItem extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | public function validate(\SwaggerValidator\Common\Context $context)
73 | {
74 | foreach ($this->keys() as $key) {
75 | if (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\Object\Operation)) {
76 | continue;
77 | }
78 |
79 | if (is_object($this->$key) && method_exists($this->$key, 'validate')) {
80 | $this->$key->validate($context->setDataPath($key));
81 | }
82 | }
83 |
84 | $currentMethod = $context->getMethod();
85 |
86 | if (isset($this->$currentMethod) && is_object($this->$currentMethod) && ($this->$key instanceof \SwaggerValidator\Object\Operation)) {
87 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
88 | return $this->$currentMethod->validate($context->setDataPath($currentMethod));
89 | }
90 |
91 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_METHOD_ERROR, 'Method not found to this route', __METHOD__, __LINE__);
92 | }
93 |
94 | public function getModel(\SwaggerValidator\Common\Context $context, $generalItems = array())
95 | {
96 | $result = array();
97 | $generalItems = $this->getMethodGeneric($context, __FUNCTION__, $generalItems);
98 |
99 | foreach ($this->keys() as $key) {
100 | if (!is_object($this->$key) || !($this->$key instanceof \SwaggerValidator\Object\Operation)) {
101 | continue;
102 | }
103 |
104 | $result[$key] = $this->$key->getModel($context->setDataPath($key), $generalItems);
105 | }
106 |
107 | $context->logModel(__METHOD__, __LINE__);
108 | return $result;
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/src/Compat.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * @author Nicolas JUHEL
21 | * @version 1.0.0
22 | */
23 | if (!function_exists('apache_response_headers')) {
24 |
25 | function apache_response_headers()
26 | {
27 | $arh = array();
28 | $headers = headers_list();
29 | foreach ($headers as $header) {
30 | $header = explode(":", $header);
31 | $arh[array_shift($header)] = trim(implode(":", $header));
32 | }
33 | return $arh;
34 | }
35 |
36 | }
37 |
38 | if (!function_exists('apache_request_headers')) {
39 |
40 | function apache_request_headers()
41 | {
42 | $arh = array();
43 |
44 | foreach ($_SERVER as $key => $val) {
45 |
46 | if (strtoupper(substr($key, 0, 5)) == 'HTTP_') {
47 | $key = substr($key, 5);
48 | $arh_key = implode('-', array_map('ucfirst', explode('_', $key)));
49 | $arh[$arh_key] = $val;
50 | }
51 | elseif (strtoupper(substr($key, 0, 2)) == 'X_') {
52 | $arh_key = implode('-', array_map('ucfirst', explode('_', $key)));
53 | $arh[$arh_key] = $val;
54 | }
55 | elseif ($key === 'CONTENT_TYPE') {
56 | $arh['Content-Type'] = $val;
57 | }
58 | elseif ($key === 'CONTENT_LENGTH') {
59 | $arh['Content-Length'] = $val;
60 | }
61 | }
62 | return( $arh );
63 | }
64 |
65 | }
66 |
67 | if (version_compare(PHP_VERSION, "5.4", "<")) {
68 |
69 | interface JsonSerializable
70 | {
71 |
72 | }
73 |
74 | If (!defined('JSON_UNESCAPED_SLASHES')) {
75 | define('JSON_UNESCAPED_SLASHES', 0);
76 | }
77 |
78 | If (!defined('JSON_UNESCAPED_UNICODE')) {
79 | define('JSON_UNESCAPED_UNICODE', 0);
80 | }
81 | }
82 |
83 | if (!function_exists('random_int')) {
84 |
85 | if (!function_exists('mcrypt_create_iv')) {
86 | throw new \Exception('Library mcrypt must be loaded for random_int to work');
87 | }
88 |
89 | function random_int($min, $max)
90 | {
91 | if (!is_int($min) || !is_int($max)) {
92 | trigger_error('$min and $max must be integer values', E_USER_NOTICE);
93 | $min = (int) $min;
94 | $max = (int) $max;
95 | }
96 |
97 | if ($min > $max) {
98 | trigger_error('$max can\'t be lesser than $min', E_USER_WARNING);
99 | return null;
100 | }
101 |
102 | $range = $counter = $max - $min;
103 | $bits = 1;
104 |
105 | while ($counter >>= 1) {
106 | ++$bits;
107 | }
108 |
109 | $bytes = (int) max(ceil($bits / 8), 1);
110 | $bitmask = pow(2, $bits) - 1;
111 |
112 | if ($bitmask >= PHP_INT_MAX) {
113 | $bitmask = PHP_INT_MAX;
114 | }
115 |
116 | do {
117 | $result = hexdec(
118 | bin2hex(
119 | mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
120 | )
121 | ) & $bitmask;
122 | }
123 | while ($result > $range);
124 |
125 | return $result + $min;
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/tests/phpunit/examples/swaggerPetStoreHeroku.json:
--------------------------------------------------------------------------------
1 | {
2 | "swagger": "2.0",
3 | "info": {
4 | "version": "1.0.0",
5 | "title": "PetStore on Heroku",
6 | "description": "**This example has a working backend hosted in Heroku**\n\nYou can try all HTTP operation described in this Swagger spec.\n\nFind source code of this API [here](https://github.com/mohsen1/petstore-api)\n"
7 | },
8 | "host": "petstore-api.herokuapp.com",
9 | "basePath": "/pet",
10 | "schemes": [
11 | "http",
12 | "https"
13 | ],
14 | "consumes": [
15 | "application/json",
16 | "text/xml"
17 | ],
18 | "produces": [
19 | "application/json",
20 | "text/html"
21 | ],
22 | "paths": {
23 | "/": {
24 | "get": {
25 | "parameters": [
26 | {
27 | "name": "limit",
28 | "in": "query",
29 | "description": "number of pets to return",
30 | "type": "integer",
31 | "default": 11,
32 | "minimum": 11,
33 | "maximum": 10000
34 | }
35 | ],
36 | "responses": {
37 | "200": {
38 | "description": "List all pets",
39 | "schema": {
40 | "title": "Pets",
41 | "type": "array",
42 | "items": {
43 | "$ref": "#/definitions/Pet"
44 | }
45 | }
46 | }
47 | }
48 | },
49 | "post": {
50 | "parameters": [
51 | {
52 | "name": "pet",
53 | "in": "body",
54 | "description": "The pet JSON you want to post",
55 | "schema": {
56 | "$ref": "#/definitions/Pet"
57 | },
58 | "required": true
59 | }
60 | ],
61 | "responses": {
62 | "200": {
63 | "description": "Make a new pet"
64 | }
65 | }
66 | },
67 | "put": {
68 | "parameters": [
69 | {
70 | "name": "pet",
71 | "in": "body",
72 | "description": "The pet JSON you want to post",
73 | "schema": {
74 | "$ref": "#/definitions/Pet"
75 | },
76 | "required": true
77 | }
78 | ],
79 | "responses": {
80 | "200": {
81 | "description": "Updates the pet"
82 | }
83 | }
84 | }
85 | },
86 | "/{petId}": {
87 | "get": {
88 | "parameters": [
89 | {
90 | "name": "petId",
91 | "in": "path",
92 | "type": "string",
93 | "description": "ID of the pet",
94 | "required": true
95 | }
96 | ],
97 | "responses": {
98 | "200": {
99 | "description": "Sends the pet with pet Id"
100 | }
101 | }
102 | }
103 | }
104 | },
105 | "definitions": {
106 | "Pet": {
107 | "type": "object",
108 | "properties": {
109 | "name": {
110 | "type": "string"
111 | },
112 | "birthday": {
113 | "type": "integer",
114 | "format": "int32"
115 | }
116 | }
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 | API Index
2 | =========
3 |
4 | * SwaggerValidator
5 | * [Exception](SwaggerValidator-Exception.md)
6 | * [Swagger](SwaggerValidator-Swagger.md)
7 | * SwaggerValidator\Object
8 | * [Paths](SwaggerValidator-Object-Paths.md)
9 | * [Headers](SwaggerValidator-Object-Headers.md)
10 | * [Contact](SwaggerValidator-Object-Contact.md)
11 | * [License](SwaggerValidator-Object-License.md)
12 | * [Reference](SwaggerValidator-Object-Reference.md)
13 | * [ResponseItem](SwaggerValidator-Object-ResponseItem.md)
14 | * [Responses](SwaggerValidator-Object-Responses.md)
15 | * [Parameters](SwaggerValidator-Object-Parameters.md)
16 | * [HeaderItem](SwaggerValidator-Object-HeaderItem.md)
17 | * [ExternalDocs](SwaggerValidator-Object-ExternalDocs.md)
18 | * [ParameterBody](SwaggerValidator-Object-ParameterBody.md)
19 | * [SecurityRequirement](SwaggerValidator-Object-SecurityRequirement.md)
20 | * [PathItem](SwaggerValidator-Object-PathItem.md)
21 | * [Definitions](SwaggerValidator-Object-Definitions.md)
22 | * [Swagger](SwaggerValidator-Object-Swagger.md)
23 | * [SecurityDefinitions](SwaggerValidator-Object-SecurityDefinitions.md)
24 | * [Security](SwaggerValidator-Object-Security.md)
25 | * [SecurityItem](SwaggerValidator-Object-SecurityItem.md)
26 | * [Info](SwaggerValidator-Object-Info.md)
27 | * [Operation](SwaggerValidator-Object-Operation.md)
28 | * SwaggerValidator\Security
29 | * [OAuth2ApplicationSecurity](SwaggerValidator-Security-OAuth2ApplicationSecurity.md)
30 | * [OAuth2PasswordSecurity](SwaggerValidator-Security-OAuth2PasswordSecurity.md)
31 | * [OAuth2AccessCodeSecurity](SwaggerValidator-Security-OAuth2AccessCodeSecurity.md)
32 | * [OAuth2PasswordSecurityScopes](SwaggerValidator-Security-OAuth2PasswordSecurityScopes.md)
33 | * [BasicAuthenticationSecurity](SwaggerValidator-Security-BasicAuthenticationSecurity.md)
34 | * [OAuth2ImplicitSecurity](SwaggerValidator-Security-OAuth2ImplicitSecurity.md)
35 | * [ApiKeySecurity](SwaggerValidator-Security-ApiKeySecurity.md)
36 | * SwaggerValidator\DataType
37 | * [TypeCommon](SwaggerValidator-DataType-TypeCommon.md)
38 | * [TypeArrayItems](SwaggerValidator-DataType-TypeArrayItems.md)
39 | * [TypeBoolean](SwaggerValidator-DataType-TypeBoolean.md)
40 | * [TypeNumber](SwaggerValidator-DataType-TypeNumber.md)
41 | * [TypeArray](SwaggerValidator-DataType-TypeArray.md)
42 | * [TypeFile](SwaggerValidator-DataType-TypeFile.md)
43 | * [TypeInteger](SwaggerValidator-DataType-TypeInteger.md)
44 | * [TypeObject](SwaggerValidator-DataType-TypeObject.md)
45 | * [TypeString](SwaggerValidator-DataType-TypeString.md)
46 | * [TypeCombined](SwaggerValidator-DataType-TypeCombined.md)
47 | * SwaggerValidator\Interfaces
48 | * [ContextLog](SwaggerValidator-Interfaces-ContextLog.md)
49 | * [ContextDataLoader](SwaggerValidator-Interfaces-ContextDataLoader.md)
50 | * [ContextDataParser](SwaggerValidator-Interfaces-ContextDataParser.md)
51 | * [ContextBase](SwaggerValidator-Interfaces-ContextBase.md)
52 | * SwaggerValidator\Common
53 | * [CollectionType](SwaggerValidator-Common-CollectionType.md)
54 | * [CollectionReference](SwaggerValidator-Common-CollectionReference.md)
55 | * [FactorySwagger](SwaggerValidator-Common-FactorySwagger.md)
56 | * [Factory](SwaggerValidator-Common-Factory.md)
57 | * [SandBoxItem](SwaggerValidator-Common-SandBoxItem.md)
58 | * [Context](SwaggerValidator-Common-Context.md)
59 | * [ReferenceItem](SwaggerValidator-Common-ReferenceItem.md)
60 | * [ReferenceFile](SwaggerValidator-Common-ReferenceFile.md)
61 | * [CollectionFile](SwaggerValidator-Common-CollectionFile.md)
62 | * [ContextBase](SwaggerValidator-Common-ContextBase.md)
63 | * [Sandbox](SwaggerValidator-Common-Sandbox.md)
64 | * [Collection](SwaggerValidator-Common-Collection.md)
65 | * [CollectionSwagger](SwaggerValidator-Common-CollectionSwagger.md)
66 | * [SwaggerAutoload](SwaggerValidator-SwaggerAutoload.md)
67 | * [JsonSerializable](JsonSerializable.md)
68 |
69 |
--------------------------------------------------------------------------------
/src/DataType/TypeBoolean.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\DataType;
20 |
21 | /**
22 | * Description of Boolean
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class TypeBoolean extends \SwaggerValidator\DataType\TypeCommon
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function validate(\SwaggerValidator\Common\Context $context)
60 | {
61 | if (!isset($this->type)) {
62 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
63 | }
64 |
65 | if ($this->type != \SwaggerValidator\Common\FactorySwagger::TYPE_BOOLEAN) {
66 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
67 | }
68 |
69 | if (!$this->type($context, $context->getDataValue())) {
70 | return $context->setDataCheck('type')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATATYPE, null, __METHOD__, __LINE__);
71 | }
72 |
73 | if (!$this->pattern($context, $context->getDataValue())) {
74 | return $context->setDataCheck('pattern')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_PATTERN, null, __METHOD__, __LINE__);
75 | }
76 |
77 | // completer les test integer
78 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
79 | return true;
80 | }
81 |
82 | protected function format(\SwaggerValidator\Common\Context $context, $valueParams)
83 | {
84 | return true;
85 | }
86 |
87 | protected function type(\SwaggerValidator\Common\Context $context, $valueParams)
88 | {
89 | if (is_string($valueParams) || is_int($valueParams)) {
90 |
91 | switch (strtolower($valueParams)) {
92 | case '1':
93 | case '0':
94 | case 'true':
95 | case 'false':
96 | case 'on':
97 | case 'off':
98 | case 'yes':
99 | case 'no':
100 | case 'y':
101 | case 'n':
102 | return true;
103 | default:
104 | return false;
105 | }
106 | }
107 |
108 | return is_bool($valueParams);
109 | }
110 |
111 | protected function getExampleFormat(\SwaggerValidator\Common\Context $context)
112 | {
113 | $context->logModel(__METHOD__, __LINE__);
114 | return random_int(0, 1);
115 | }
116 |
117 | protected function getExampleType(\SwaggerValidator\Common\Context $context)
118 | {
119 | $context->logModel(__METHOD__, __LINE__);
120 | return random_int(0, 1);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Common-ReferenceItem.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Common\ReferenceItem
2 | ===============
3 |
4 | Description of ReferenceItem
5 |
6 |
7 |
8 |
9 | * Class name: ReferenceItem
10 | * Namespace: SwaggerValidator\Common
11 |
12 |
13 |
14 |
15 |
16 | Properties
17 | ----------
18 |
19 |
20 | ### $contents
21 |
22 | private mixed $contents
23 |
24 |
25 |
26 |
27 |
28 | * Visibility: **private**
29 |
30 |
31 | ### $object
32 |
33 | private mixed $object
34 |
35 |
36 |
37 |
38 |
39 | * Visibility: **private**
40 |
41 |
42 | Methods
43 | -------
44 |
45 |
46 | ### __construct
47 |
48 | mixed SwaggerValidator\Common\ReferenceItem::__construct()
49 |
50 |
51 |
52 |
53 |
54 | * Visibility: **public**
55 |
56 |
57 |
58 |
59 | ### setJsonData
60 |
61 | mixed SwaggerValidator\Common\ReferenceItem::setJsonData($jsonData)
62 |
63 |
64 |
65 |
66 |
67 | * Visibility: **public**
68 |
69 |
70 | #### Arguments
71 | * $jsonData **mixed**
72 |
73 |
74 |
75 | ### __get
76 |
77 | mixed SwaggerValidator\Common\ReferenceItem::__get($name)
78 |
79 |
80 |
81 |
82 |
83 | * Visibility: **public**
84 |
85 |
86 | #### Arguments
87 | * $name **mixed**
88 |
89 |
90 |
91 | ### __storeData
92 |
93 | mixed SwaggerValidator\Common\ReferenceItem::__storeData($key, $value)
94 |
95 | Var Export Method
96 |
97 |
98 |
99 | * Visibility: **protected**
100 |
101 |
102 | #### Arguments
103 | * $key **mixed**
104 | * $value **mixed**
105 |
106 |
107 |
108 | ### __set_state
109 |
110 | mixed SwaggerValidator\Common\ReferenceItem::__set_state(array $properties)
111 |
112 |
113 |
114 |
115 |
116 | * Visibility: **public**
117 | * This method is **static**.
118 |
119 |
120 | #### Arguments
121 | * $properties **array**
122 |
123 |
124 |
125 | ### extractAllReferences
126 |
127 | mixed SwaggerValidator\Common\ReferenceItem::extractAllReferences(\SwaggerValidator\Common\Context $context)
128 |
129 |
130 |
131 |
132 |
133 | * Visibility: **public**
134 |
135 |
136 | #### Arguments
137 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
138 |
139 |
140 |
141 | ### extractReferenceArray
142 |
143 | mixed SwaggerValidator\Common\ReferenceItem::extractReferenceArray(\SwaggerValidator\Common\Context $context, array $array)
144 |
145 |
146 |
147 |
148 |
149 | * Visibility: **private**
150 |
151 |
152 | #### Arguments
153 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
154 | * $array **array**
155 |
156 |
157 |
158 | ### extractReferenceObject
159 |
160 | mixed SwaggerValidator\Common\ReferenceItem::extractReferenceObject(\SwaggerValidator\Common\Context $context, \stdClass $stdClass)
161 |
162 |
163 |
164 |
165 |
166 | * Visibility: **private**
167 |
168 |
169 | #### Arguments
170 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
171 | * $stdClass **stdClass**
172 |
173 |
174 |
175 | ### getJson
176 |
177 | mixed SwaggerValidator\Common\ReferenceItem::getJson(\SwaggerValidator\Common\Context $context)
178 |
179 |
180 |
181 |
182 |
183 | * Visibility: **public**
184 |
185 |
186 | #### Arguments
187 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
188 |
189 |
190 |
191 | ### getObject
192 |
193 | mixed SwaggerValidator\Common\ReferenceItem::getObject(\SwaggerValidator\Common\Context $context)
194 |
195 |
196 |
197 |
198 |
199 | * Visibility: **public**
200 |
201 |
202 | #### Arguments
203 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
204 |
205 |
206 |
207 | ### getCleanClass
208 |
209 | mixed SwaggerValidator\Common\ReferenceItem::getCleanClass($class)
210 |
211 |
212 |
213 |
214 |
215 | * Visibility: **protected**
216 |
217 |
218 | #### Arguments
219 | * $class **mixed**
220 |
221 |
222 |
223 | ### jsonUnSerialize
224 |
225 | mixed SwaggerValidator\Common\ReferenceItem::jsonUnSerialize(\SwaggerValidator\Common\Context $context)
226 |
227 |
228 |
229 |
230 |
231 | * Visibility: **public**
232 |
233 |
234 | #### Arguments
235 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
236 |
237 |
238 |
--------------------------------------------------------------------------------
/src/Object/Responses.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Responses
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Responses extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | if (!preg_match('/^([0-9]{3})$|^(' . \SwaggerValidator\Common\FactorySwagger::KEY_DEFAULT . ')$/', $key)) {
66 | $context->throwException('Invalid Key "' . $key . '" for a response item', __METHOD__, __LINE__);
67 | }
68 |
69 | $value = $this->extractNonRecursiveReference($context, $value);
70 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
71 | }
72 |
73 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
74 | }
75 |
76 | public function validate(\SwaggerValidator\Common\Context $context)
77 | {
78 | $status = $context->getResponseStatus();
79 |
80 | if ($this->has($status)) {
81 | return $this->$status->validate($context->setDataPath($status));
82 | }
83 |
84 | $keyDefault = \SwaggerValidator\Common\FactorySwagger::KEY_DEFAULT;
85 |
86 | if ($this->has($keyDefault)) {
87 | return $this->$keyDefault->validate($context->setDataPath($keyDefault));
88 | }
89 |
90 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_RESPONSE_ERROR, 'Response Code not found to this route', __METHOD__, __LINE__);
91 | }
92 |
93 | public function getModel(\SwaggerValidator\Common\Context $context, $listParameters)
94 | {
95 | foreach ($this->keys() as $key) {
96 |
97 | if (!preg_match('/^([0-9]{3})$|^(default)$/', $key) || !is_object($this->$key) || !($this->$key instanceof \SwaggerValidator\Object\ResponseItem)) {
98 | continue;
99 | }
100 |
101 | if (!array_key_exists($key, $listParameters)) {
102 | $listParameters[$key] = array();
103 | }
104 |
105 | $response = $this->$key->getModel($context->setDataPath($key), $listParameters[$key]);
106 |
107 | if (empty($response)) {
108 | $response = null;
109 | }
110 |
111 | $listParameters[$key] = $response;
112 | }
113 |
114 | $context->logModel(__METHOD__, __LINE__);
115 | return $listParameters;
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/Object/Reference.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Reference
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Reference extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | protected $referenceId;
31 | protected $reference;
32 |
33 | public function __construct()
34 | {
35 |
36 | }
37 |
38 | /**
39 | * Var Export Method
40 | */
41 | protected function __storeData($key, $value = null)
42 | {
43 | if (property_exists($this, $key)) {
44 | $this->$key = $value;
45 | }
46 | else {
47 | parent::__storeData($key, $value);
48 | }
49 | }
50 |
51 | public static function __set_state(array $properties)
52 | {
53 | $obj = new static;
54 |
55 | foreach ($properties as $key => $value) {
56 | $obj->__storeData($key, $value);
57 | }
58 |
59 | return $obj;
60 | }
61 |
62 | public function jsonSerialize()
63 | {
64 | $keyRef = \SwaggerValidator\Common\FactorySwagger::KEY_REFERENCE;
65 |
66 | $result = new \stdClass();
67 | $result->$keyRef = '#/' . \SwaggerValidator\Common\FactorySwagger::KEY_DEFINITIONS . '/' . str_replace(':', '', $this->referenceId);
68 |
69 | return $result;
70 | }
71 |
72 | public function serialize()
73 | {
74 | return serialize(array(
75 | 'ref' => $this->reference,
76 | 'id' => $this->referenceId
77 | ));
78 | }
79 |
80 | public function unserialize($data)
81 | {
82 | if (!is_array($data)) {
83 | $data = unserialize($data);
84 | }
85 |
86 | $this->reference = $data['ref'];
87 | $this->referenceId = $data['id'];
88 | }
89 |
90 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
91 | {
92 | $keyRef = \SwaggerValidator\Common\FactorySwagger::KEY_REFERENCE;
93 |
94 | $this->reference = $jsonData->$keyRef;
95 | $this->referenceId = \SwaggerValidator\Common\CollectionReference::getIdFromRef($context, $this->reference);
96 |
97 | if ($this->reference == $this->referenceId) {
98 | $this->reference = null;
99 | }
100 |
101 | $object = \SwaggerValidator\Common\CollectionReference::getInstance()->get($context->setExternalRef($this->reference), $this->referenceId);
102 | $this->registerRecursiveDefinitions($context, $jsonData);
103 |
104 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
105 | }
106 |
107 | public function validate(\SwaggerValidator\Common\Context $context)
108 | {
109 | $object = \SwaggerValidator\Common\CollectionReference::getInstance()->get($context->setExternalRef($this->reference), $this->referenceId);
110 | return $object->getObject($context->setExternalRef($this->referenceId))->validate($context->setExternalRef($this->referenceId));
111 | }
112 |
113 | public function getModel(\SwaggerValidator\Common\Context $context)
114 | {
115 | if ($context->checkExternalRef($this->referenceId)) {
116 | return new \stdClass();
117 | }
118 |
119 | $object = \SwaggerValidator\Common\CollectionReference::getInstance()->get($context->setExternalRef($this->reference), $this->referenceId);
120 | return $object->getObject($context->setExternalRef($this->referenceId))->getModel($context->setExternalRef($this->referenceId));
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Version 1.0.0 - 2016-07-30
2 | - Initial Version
3 | ### patch #1 :
4 | - Fix Code Climate + minor bug
5 | ### patch #2 :
6 | - Fix Packagist Composer file + minor bug
7 | ### patch #3 :
8 | - Fix major issue with json_encode of a swagger object
9 | - Fix major issue with cache managment
10 | - Fix other minor issue
11 | - Fix cache managment
12 | - Add Interface for Context class to help override it
13 | ### patch #4:
14 | - Fix bug with unit test and hashed value in test document generated by json_encode
15 | - Fix some compatibilities error with PHP 5.3
16 | - Fix a forget check in the primitive data type (size : minimum, exclusiveMinimum, minLength, ...)
17 | - Fix bug with unit test and hashed value in test document generated by json_encode
18 | - Fix some compatibilities error with PHP 5.3
19 | - Fix a forget check in the primitive data type (size : minimum, exclusiveMinimum, minLength, ...)
20 | - Fix a forget check if the mini size is not set or equal to zero and empty data, then skip other test
21 |
22 | # Version 1.1.0 - 2016-08-07 :
23 | - Fix the validating format value integer/number/boolean
24 | - Fix validation string format binary, password
25 | - Fix getModel from format for string
26 | - Fix PHP 5.3 compatibility
27 | - Add random value for getModel Primitives Data Type
28 | - Add Coverage calculation & CodeClimate report in travis build run
29 | - Add Sandbox feature : keep validated params and drop global magic variable
30 |
31 | # Version 1.2.0 - 2016-08-21 :
32 | - Refactor FS Structure
33 | - Refactor autoloader to PSR 4
34 | - Fix error in overriding classes
35 | - Fix minor bug
36 |
37 | # Version 1.2.1 - 2016-09-05 :
38 | - 4ed9b0a Fix major bug in cleaning working reference from all reference
39 | - 4ed9b0a Refactor generic method for parsing generic items (parameters, responses, ...)
40 | - 4ed9b0a Add missing key as constant in FactorySwagger (keys as reserved in swagger definition)
41 | - 4ed9b0a Fix error on identify local file or remote url in reference file (used indeed for swagger main file)
42 | - 4ed9b0a Refactor log method for reference operation Fix minor bug
43 | - 919da48 Update README.md
44 |
45 | # Version 1.2.2 - 2016-09-10 :
46 | - 9b22172 Fix Build script
47 | - 6c4065b Add Build Script
48 | - b7e2e0d Fix timeout error in travais run test
49 | - ba01238 Replace simple phpunit test + coverge by only coverage test for build test
50 | - 9a28eff Fix error of using constant not defined in PHP 5.3
51 | - b6f7010 Add test for false value / request
52 | - b6f7010 Fix error found following test Add type validation in exception resturn
53 | - b6f7010 Fix empty exception message when init exception
54 |
55 | # Version 1.2.3 - 2016-09-11 :
56 | - e3bdd93 Fix minor bug
57 | - 50de5b8 Add collectionFormat in array type for read query params
58 | - 50de5b8 Add collectionFormat managment in model constructor
59 | - 50de5b8 Add min/max items randamize for model creator
60 | - 50de5b8 Refactoring log message as debug, validation error and exception to add option for disabled it
61 | - 50de5b8 Refactoring message in validation
62 | - 50de5b8 Expand test for collection format as array
63 | - 2069990 Add response test in false test
64 |
65 | # Version 1.3.0 - 2016-10-17 :
66 | - f0e3169 Update composer version
67 | - a37953a Replace rand() by random_int (or his equal function) for best practice
68 | - 26d9358 Refactor Context : log / exception with problem if trying to override static
69 | - a3b2fc9 Change serialize to var_export function
70 |
71 | # Version 1.3.1 - 2017-04-24 :
72 | - 593c7d2 Fix PHPUnit release to still be compatible to the full scope
73 | - 94eba2c Fix still resident old github repos url
74 | - deca968 Fix Exception::init call
75 | - deca968 Add implicit object in arrayItems Schema if propeties key is find and type=object not find
76 |
77 | # Version 1.3.2 - 2017-04-24 :
78 | - ed1981c Fix Issue #20 : error in some definition class, error in some array to string convertion for log, error with basepath = / and paths start mandatory with /
79 | - ed1981c Fix Issue #18 : with some missing refactoring method in last releases
80 | - ed1981c Extand the implicit type=object understanding at last when json part is an object with propertie key and no type key
81 |
82 |
--------------------------------------------------------------------------------
/src/Object/Operation.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Operation
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Operation extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('responses');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | public function validate(\SwaggerValidator\Common\Context $context)
73 | {
74 | switch ($context->getType()) {
75 | case \SwaggerValidator\Common\Context::TYPE_RESPONSE:
76 | return $this->validateResponse($context);
77 |
78 | default:
79 | return $this->validateRequest($context);
80 | }
81 | }
82 |
83 | private function validateRequest(\SwaggerValidator\Common\Context $context)
84 | {
85 | $keyParameters = \SwaggerValidator\Common\FactorySwagger::KEY_PARAMETERS;
86 |
87 | if (isset($this->$keyParameters) && is_object($this->$keyParameters)) {
88 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
89 | return $this->$keyParameters->validate($context->setDataPath($keyParameters));
90 | }
91 |
92 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
93 | return true;
94 | }
95 |
96 | private function validateResponse(\SwaggerValidator\Common\Context $context)
97 | {
98 | $keyResponses = \SwaggerValidator\Common\FactorySwagger::KEY_RESPONSES;
99 |
100 | if (isset($this->$keyResponses)) {
101 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
102 | return $this->$keyResponses->validate($context->setDataPath($keyResponses));
103 | }
104 |
105 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, 'Responses key not found', __METHOD__, __LINE__);
106 | }
107 |
108 | public function getModel(\SwaggerValidator\Common\Context $context, $generalItems = array())
109 | {
110 | $parameters = \SwaggerValidator\Common\FactorySwagger::KEY_PARAMETERS;
111 | $responses = \SwaggerValidator\Common\FactorySwagger::KEY_RESPONSES;
112 | $consumes = \SwaggerValidator\Common\FactorySwagger::KEY_CONSUMES;
113 | $produces = \SwaggerValidator\Common\FactorySwagger::KEY_PRODUCES;
114 | $generalItems = $this->getMethodGeneric($context, __FUNCTION__, $generalItems);
115 |
116 | foreach (array_keys($generalItems) as $key) {
117 | if (empty($generalItems[$key])) {
118 | $generalItems[$key] = null;
119 | }
120 | }
121 |
122 | $context->logModel(__METHOD__, __LINE__);
123 | return $generalItems;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://gemnasium.com/github.com/nabbar/SwaggerValidator-PHP) ~ [](https://codeclimate.com/github/nabbar/SwaggerValidator-PHP) ~ [](https://codeclimate.com/github/nabbar/SwaggerValidator-PHP/coverage) ~ [](https://travis-ci.org/nabbar/SwaggerValidator-PHP)
2 |
3 | [](https://packagist.org/packages/njuhel/swagger-validator) ~ [](https://packagist.org/packages/njuhel/swagger-validator)
4 |
5 | # **Swagger Validator _PHP_**
6 |
7 | A Swagger(OpenAPI) Validation and Parser as lib for PHP to secure and helpful application for request / response validating,
8 | security stage, testunit skeleton, testauto generation, ... This lib can be used into any existing application who's
9 | having a swagger definition file for request/response.
10 |
11 | Swagger is old name of [OpenAPI Projet](https://openapis.org/) and who manage the [OAI Specification](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas/)
12 |
13 | ## **Why Using a Swagger Validator**
14 | A Swagger *Validator* could be understand as a validation of our swagger definition file with the swagger definition.
15 | A Swagger *Parser* could be understand as a parser for request entry (sometimes in addition parsing response)
16 | The Swagger Validator is doing all this. It validate your swagger file, validate your entry request and response.
17 |
18 | ### _Validation / Parsing are mandatory_
19 | - validating the swagger guarantee that your definition file has no error and will be understand correctly
20 | - validating the request is a security stage to filter bad request, attempted hack, limit the control and
21 | filtering statement in your working source code, ...
22 | - validating the response is also security stage to filter not needed information before sent them, to
23 | limit and prevent error code attack, limit the control and filtering statement in your working source code
24 | ...
25 |
26 | ## **Features**
27 | - Best for Swagger First, Code after
28 | - Validate / Filter All Request & Response
29 | - Integration easy with any existing framework, application, ...
30 | - Allow a soft migration for a complete application MVC to HIM/API application
31 | - Give example model of request/response based on the swagger to example built automated testing stage, human skeleton for code, documentation skeletton, ...
32 | - Validate the swagger file in following the Swagger 2.0 specification and JSON Draft v4 (swagger has higher priority to json draft 4)
33 | - Custimization easy : all classes are overriding without writing the parser (using a customized factory)
34 | - Working finely with single and multi file swagger definition
35 | - Can generate single swagger definition file based on multi swagger definition file
36 | - Allow local and remote definition file
37 | - Allow using circular reference (only for no required properties in an object)
38 | - Store validated request params into a sandbox to access only validated params (and clean magics globals variables)
39 | - Follow RFC and recommandation for primitive type and format and not native language understanding type and format
40 | - Using cache for working file in parsing request/response
41 | - Using easy overriding IO class for collect request/response data to be validated
42 | - Unit test in your environnement for checking compatibility
43 |
44 | ## **Need to do**
45 | - response building automaticly base on content type response, accept and produce
46 | - reduce scope to PHP 7.1 (release >= 1.4)
47 | - swagger / openapi version 3.0 (release >= 2.0)
48 |
49 | ## **Compatibility**
50 | - release <= 1.3 : scope PHP 5.3.10 (bug reported, need some more compatibilities) to PHP 7.0
51 | - release >= 1.4 : scope PHP 7.1
52 | - release >= 2.0 : openapi release 3.0 & PHP 7.1
53 |
54 |
55 | ## **Installation Guide**
56 | - Install into a git repository as submodule :
57 | ```sh
58 | git submodule init
59 | git submodule add http://srv01.https://github.com/nabbar/SwaggerValidator-PHP src/lib/SwaggerValidator
60 | git submodule update
61 | ```
62 |
63 | - Install by cloning git :
64 | ```sh
65 | git clone https://github.com/nabbar/SwaggerValidator-PHP SwaggerValidator
66 | ```
67 |
68 | - Install with composer (adding this in composer.json):
69 | ```json
70 | "require": {
71 | "nabbar/swagger-validator":">=1.2.0"
72 | },
73 | ```
74 |
75 | - Install with phar :
76 | ```sh
77 | wget https://github.com/nabbar/SwaggerValidator-PHP/raw/master/bin/SwaggerValidator.phar
78 | ```
79 |
80 |
81 | ## **Example & Docs**
82 | - **Examples** : [Example.php](src/Example.php)
83 | - **Documentation** : [generated](doc/README.md)
84 |
85 |
86 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Swagger.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Swagger
2 | ===============
3 |
4 | Description of Swagger
5 |
6 |
7 |
8 |
9 | * Class name: Swagger
10 | * Namespace: SwaggerValidator
11 |
12 |
13 |
14 |
15 |
16 | Properties
17 | ----------
18 |
19 |
20 | ### $cacheEnable
21 |
22 | private boolean $cacheEnable
23 |
24 | flag to store capability of using cache file
25 |
26 |
27 |
28 | * Visibility: **private**
29 | * This property is **static**.
30 |
31 |
32 | ### $cachePath
33 |
34 | private string $cachePath
35 |
36 | Path for the cache file
37 |
38 |
39 |
40 | * Visibility: **private**
41 | * This property is **static**.
42 |
43 |
44 | ### $cacheLifeTime
45 |
46 | private integer $cacheLifeTime
47 |
48 | Timestamp addition to check if the modify time of the cache file is out or not
49 |
50 |
51 |
52 | * Visibility: **private**
53 | * This property is **static**.
54 |
55 |
56 | ### $swaggerFile
57 |
58 | private string $swaggerFile
59 |
60 | the swagger json definition file path or file url
61 |
62 |
63 |
64 | * Visibility: **private**
65 | * This property is **static**.
66 |
67 |
68 | Methods
69 | -------
70 |
71 |
72 | ### setCachePath
73 |
74 | mixed SwaggerValidator\Swagger::setCachePath(string $pathCacheFile)
75 |
76 | Store the cache path and check if the file cache can enabled or not
77 |
78 |
79 |
80 | * Visibility: **public**
81 | * This method is **static**.
82 |
83 |
84 | #### Arguments
85 | * $pathCacheFile **string**
86 |
87 |
88 |
89 | ### getCachePath
90 |
91 | string|null SwaggerValidator\Swagger::getCachePath()
92 |
93 | return the cache file path
94 |
95 |
96 |
97 | * Visibility: **public**
98 | * This method is **static**.
99 |
100 |
101 |
102 |
103 | ### setCacheLifeTime
104 |
105 | mixed SwaggerValidator\Swagger::setCacheLifeTime(integer $maxTimeStamp)
106 |
107 | Store the number of second for available lifetime for cache file
108 |
109 |
110 |
111 | * Visibility: **public**
112 | * This method is **static**.
113 |
114 |
115 | #### Arguments
116 | * $maxTimeStamp **integer**
117 |
118 |
119 |
120 | ### getCacheLifeTime
121 |
122 | integer SwaggerValidator\Swagger::getCacheLifeTime()
123 |
124 | return the value of the cache lifetime
125 |
126 |
127 |
128 | * Visibility: **public**
129 | * This method is **static**.
130 |
131 |
132 |
133 |
134 | ### setSwaggerFile
135 |
136 | mixed SwaggerValidator\Swagger::setSwaggerFile(string $pathFileSwagger)
137 |
138 | The pathfile or url to the swagger file definition
139 | For multi file specify only the main definition file (other references must be in relative path based of location of each current file)
140 |
141 |
142 |
143 | * Visibility: **public**
144 | * This method is **static**.
145 |
146 |
147 | #### Arguments
148 | * $pathFileSwagger **string**
149 |
150 |
151 |
152 | ### getSwaggerFile
153 |
154 | string|null SwaggerValidator\Swagger::getSwaggerFile()
155 |
156 | Return the path/url of the Swagger Definition File
157 |
158 |
159 |
160 | * Visibility: **public**
161 | * This method is **static**.
162 |
163 |
164 |
165 |
166 | ### load
167 |
168 | \SwaggerValidator\Object\Swagger SwaggerValidator\Swagger::load(\SwaggerValidator\Common\Context $context)
169 |
170 | Load the Swagger Object from the cache file or create a new
171 |
172 |
173 |
174 | * Visibility: **public**
175 | * This method is **static**.
176 |
177 |
178 | #### Arguments
179 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
180 |
181 |
182 |
183 | ### regenSwagger
184 |
185 | \SwaggerValidator\Object\Swagger SwaggerValidator\Swagger::regenSwagger(\SwaggerValidator\Common\Context $context)
186 |
187 | Return a Swagger Object new object
188 |
189 |
190 |
191 | * Visibility: **protected**
192 | * This method is **static**.
193 |
194 |
195 | #### Arguments
196 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
197 |
198 |
199 |
200 | ### loadCache
201 |
202 | \SwaggerValidator\Object\Swagger SwaggerValidator\Swagger::loadCache(\SwaggerValidator\Common\Context $context)
203 |
204 | load cache file or call regen file cache
205 |
206 |
207 |
208 | * Visibility: **protected**
209 | * This method is **static**.
210 |
211 |
212 | #### Arguments
213 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
214 |
215 |
216 |
217 | ### storeCache
218 |
219 | \SwaggerValidator\Object\Swagger SwaggerValidator\Swagger::storeCache(\SwaggerValidator\Object\Swagger $swagger, \SwaggerValidator\Common\Context $context)
220 |
221 | store the new swagger object is available
222 |
223 |
224 |
225 | * Visibility: **protected**
226 | * This method is **static**.
227 |
228 |
229 | #### Arguments
230 | * $swagger **[SwaggerValidator\Object\Swagger](SwaggerValidator-Object-Swagger.md)**
231 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
232 |
233 |
234 |
235 | ### cleanInstances
236 |
237 | mixed SwaggerValidator\Swagger::cleanInstances()
238 |
239 |
240 |
241 |
242 |
243 | * Visibility: **public**
244 | * This method is **static**.
245 |
246 |
247 |
248 |
--------------------------------------------------------------------------------
/src/Object/Paths.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Paths
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Paths extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | foreach (get_object_vars($jsonData) as $key => $value) {
64 |
65 | $value = $this->extractNonRecursiveReference($context, $value);
66 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
67 | }
68 |
69 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
70 | }
71 |
72 | public function validate(\SwaggerValidator\Common\Context $context)
73 | {
74 | foreach ($this->keys() as $key) {
75 | if (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\Object\PathItem)) {
76 | continue;
77 | }
78 |
79 | if (is_object($this->$key) && method_exists($this->$key, 'validate')) {
80 | $this->$key->validate($context->setDataPath($key));
81 | }
82 | }
83 |
84 | $requestPath = explode('/', $context->getRequestPath());
85 | $listFindRoute = array();
86 |
87 | foreach ($this->keys() as $key) {
88 | if (!is_object($this->$key) || !($this->$key instanceof \SwaggerValidator\Object\PathItem)) {
89 | continue;
90 | }
91 |
92 | if (substr($key, 0, 1) != '/') {
93 | continue;
94 | }
95 |
96 | $route = explode('/', $key);
97 |
98 | if (count($requestPath) != count($route)) {
99 | continue;
100 | }
101 |
102 | $findRoute = array(
103 | 'base' => $key,
104 | 'params' => 0,
105 | );
106 |
107 | for ($i = 0; $i < count($route); $i++) {
108 | if (substr($route[$i], 0, 1) == '{' && substr($route[$i], -1, 1) == '}') {
109 | $findRoute['params'] ++;
110 | continue;
111 | }
112 | if ($route[$i] != $requestPath[$i]) {
113 | $findRoute = null;
114 | break;
115 | }
116 | }
117 |
118 | if ($findRoute !== null) {
119 | $listFindRoute[$findRoute['base']] = $findRoute['params'];
120 | }
121 | }
122 |
123 | $findRoute = null;
124 | $min = null;
125 |
126 | foreach ($listFindRoute as $key => $value) {
127 | if ($findRoute === null || $value < $min) {
128 | $min = $value;
129 | $findRoute = $key;
130 | }
131 | }
132 |
133 | if ($findRoute === null) {
134 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_ROUTE_ERROR, 'Route not found', __METHOD__, __LINE__);
135 | }
136 |
137 | $context->setRoutePath($findRoute);
138 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
139 | return $this->$findRoute->validate($context->setDataPath($findRoute));
140 | }
141 |
142 | public function getModel(\SwaggerValidator\Common\Context $context, $generalItems = array())
143 | {
144 | $result = array();
145 | $generalItems = $this->getMethodGeneric($context, __FUNCTION__, $generalItems);
146 |
147 | foreach ($this->keys() as $key) {
148 | if (!is_object($this->$key) || !($this->$key instanceof \SwaggerValidator\Object\PathItem)) {
149 | continue;
150 | }
151 |
152 | if (substr($key, 0, 1) != '/') {
153 | continue;
154 | }
155 |
156 | $result[$key] = $this->$key->getModel($context->setDataPath($key), $generalItems);
157 | }
158 |
159 | $context->logModel(__METHOD__, __LINE__);
160 | return $result;
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/src/Object/ResponseItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of ResponseItem
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class ResponseItem extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('description');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObject($context, $jsonData);
62 |
63 | $schemaKey = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
64 | if (property_exists($jsonData, $schemaKey)) {
65 | $jsonData->$schemaKey = $this->extractNonRecursiveReference($context, $jsonData->$schemaKey);
66 | }
67 |
68 | foreach (get_object_vars($jsonData) as $key => $value) {
69 |
70 | $value = $this->extractNonRecursiveReference($context, $value);
71 |
72 | $schemaKey = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
73 | if (is_object($value) && property_exists($value, $schemaKey)) {
74 | $value->$schemaKey = $this->extractNonRecursiveReference($context->setDataPath($key), $value->$schemaKey);
75 | }
76 |
77 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
78 | }
79 |
80 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
81 | }
82 |
83 | public function validate(\SwaggerValidator\Common\Context $context)
84 | {
85 | $check = true;
86 |
87 | $keyHeaders = \SwaggerValidator\Common\FactorySwagger::KEY_HEADERS;
88 |
89 | if ($this->has($keyHeaders) && is_object($this->$keyHeaders) && $this->$keyHeaders instanceof \SwaggerValidator\Object\Headers) {
90 | $check = $check && $this->$keyHeaders->validate($context->setDataPath($keyHeaders)->setLocation(\SwaggerValidator\Common\FactorySwagger::LOCATION_HEADER));
91 | }
92 |
93 | $keySchema = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
94 |
95 | if ($this->has($keySchema) && is_object($this->$keySchema) && $this->$keySchema instanceof \SwaggerValidator\Common\CollectionSwagger) {
96 |
97 | $ctx = $context->setDataPath(\SwaggerValidator\Common\FactorySwagger::LOCATION_BODY)->setLocation(\SwaggerValidator\Common\FactorySwagger::LOCATION_BODY);
98 | $ctx->dataLoad();
99 |
100 | $check = $check && $this->$keySchema->validate($ctx->setSandBox());
101 | }
102 |
103 | return $check;
104 | }
105 |
106 | public function getModel(\SwaggerValidator\Common\Context $context, $globalResponse = array())
107 | {
108 | $headersKey = \SwaggerValidator\Common\FactorySwagger::KEY_HEADERS;
109 | $schemaKey = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
110 |
111 | if (!array_key_exists($headersKey, $globalResponse)) {
112 | $globalResponse[$headersKey] = array();
113 | }
114 |
115 | if (!array_key_exists($schemaKey, $globalResponse)) {
116 | $globalResponse[$schemaKey] = null;
117 | }
118 |
119 | if (isset($this->$headersKey) && is_object($this->$headersKey) && ($this->$headersKey instanceof \SwaggerValidator\Object\Headers)) {
120 | $globalResponse[$headersKey] = $this->$headersKey->getModel($context->setDataPath($headersKey), $globalResponse[$headersKey]);
121 | }
122 |
123 | if (isset($this->$schemaKey) && is_object($this->$schemaKey) && method_exists($this->$schemaKey, 'getModel')) {
124 | $globalResponse[$schemaKey] = $this->$schemaKey->getModel($context->setDataPath($schemaKey)->setType(\SwaggerValidator\Common\Context::TYPE_RESPONSE));
125 | }
126 |
127 | if (empty($globalResponse[$headersKey])) {
128 | unset($globalResponse[$headersKey]);
129 | }
130 |
131 | if (empty($globalResponse[$schemaKey])) {
132 | unset($globalResponse[$schemaKey]);
133 | }
134 |
135 | $context->logModel(__METHOD__, __LINE__);
136 | return $globalResponse;
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Common-ReferenceFile.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Common\ReferenceFile
2 | ===============
3 |
4 | Description of ReferenceFile
5 |
6 |
7 |
8 |
9 | * Class name: ReferenceFile
10 | * Namespace: SwaggerValidator\Common
11 |
12 |
13 |
14 | Constants
15 | ----------
16 |
17 |
18 | ### PATH_TYPE_URL
19 |
20 | const PATH_TYPE_URL = 1
21 |
22 |
23 |
24 |
25 |
26 | ### PATH_TYPE_FILE
27 |
28 | const PATH_TYPE_FILE = 2
29 |
30 |
31 |
32 |
33 |
34 | Properties
35 | ----------
36 |
37 |
38 | ### $fileUri
39 |
40 | private mixed $fileUri
41 |
42 |
43 |
44 |
45 |
46 | * Visibility: **private**
47 |
48 |
49 | ### $fileObj
50 |
51 | private mixed $fileObj
52 |
53 |
54 |
55 |
56 |
57 | * Visibility: **private**
58 |
59 |
60 | ### $fileTime
61 |
62 | private mixed $fileTime
63 |
64 |
65 |
66 |
67 |
68 | * Visibility: **private**
69 |
70 |
71 | ### $fileHash
72 |
73 | private mixed $fileHash
74 |
75 |
76 |
77 |
78 |
79 | * Visibility: **private**
80 |
81 |
82 | ### $basePath
83 |
84 | private mixed $basePath
85 |
86 |
87 |
88 |
89 |
90 | * Visibility: **private**
91 |
92 |
93 | ### $baseType
94 |
95 | private mixed $baseType
96 |
97 |
98 |
99 |
100 |
101 | * Visibility: **private**
102 |
103 |
104 | Methods
105 | -------
106 |
107 |
108 | ### __construct
109 |
110 | mixed SwaggerValidator\Common\ReferenceFile::__construct(\SwaggerValidator\Common\Context $context, $filepath)
111 |
112 |
113 |
114 |
115 |
116 | * Visibility: **public**
117 |
118 |
119 | #### Arguments
120 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
121 | * $filepath **mixed**
122 |
123 |
124 |
125 | ### __get
126 |
127 | mixed SwaggerValidator\Common\ReferenceFile::__get($name)
128 |
129 |
130 |
131 |
132 |
133 | * Visibility: **public**
134 |
135 |
136 | #### Arguments
137 | * $name **mixed**
138 |
139 |
140 |
141 | ### __storeData
142 |
143 | mixed SwaggerValidator\Common\ReferenceFile::__storeData($key, $value)
144 |
145 | Var Export Method
146 |
147 |
148 |
149 | * Visibility: **protected**
150 |
151 |
152 | #### Arguments
153 | * $key **mixed**
154 | * $value **mixed**
155 |
156 |
157 |
158 | ### __set_state
159 |
160 | mixed SwaggerValidator\Common\ReferenceFile::__set_state(array $properties)
161 |
162 |
163 |
164 |
165 |
166 | * Visibility: **public**
167 | * This method is **static**.
168 |
169 |
170 | #### Arguments
171 | * $properties **array**
172 |
173 |
174 |
175 | ### getFileTime
176 |
177 | mixed SwaggerValidator\Common\ReferenceFile::getFileTime(\SwaggerValidator\Common\Context $context)
178 |
179 |
180 |
181 |
182 |
183 | * Visibility: **public**
184 |
185 |
186 | #### Arguments
187 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
188 |
189 |
190 |
191 | ### getReference
192 |
193 | mixed SwaggerValidator\Common\ReferenceFile::getReference(\SwaggerValidator\Common\Context $context, $ref)
194 |
195 |
196 |
197 |
198 |
199 | * Visibility: **public**
200 |
201 |
202 | #### Arguments
203 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
204 | * $ref **mixed**
205 |
206 |
207 |
208 | ### extractAllReference
209 |
210 | mixed SwaggerValidator\Common\ReferenceFile::extractAllReference(\SwaggerValidator\Common\Context $context)
211 |
212 |
213 |
214 |
215 |
216 | * Visibility: **public**
217 |
218 |
219 | #### Arguments
220 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
221 |
222 |
223 |
224 | ### extractReferenceArray
225 |
226 | mixed SwaggerValidator\Common\ReferenceFile::extractReferenceArray(\SwaggerValidator\Common\Context $context, array $array)
227 |
228 |
229 |
230 |
231 |
232 | * Visibility: **private**
233 |
234 |
235 | #### Arguments
236 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
237 | * $array **array**
238 |
239 |
240 |
241 | ### extractReferenceObject
242 |
243 | mixed SwaggerValidator\Common\ReferenceFile::extractReferenceObject(\SwaggerValidator\Common\Context $context, \stdClass $stdClass)
244 |
245 |
246 |
247 |
248 |
249 | * Visibility: **private**
250 |
251 |
252 | #### Arguments
253 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
254 | * $stdClass **stdClass**
255 |
256 |
257 |
258 | ### getCanonical
259 |
260 | mixed SwaggerValidator\Common\ReferenceFile::getCanonical(\SwaggerValidator\Common\Context $context, $fullRef)
261 |
262 |
263 |
264 |
265 |
266 | * Visibility: **public**
267 |
268 |
269 | #### Arguments
270 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
271 | * $fullRef **mixed**
272 |
273 |
274 |
275 | ### getFileLink
276 |
277 | mixed SwaggerValidator\Common\ReferenceFile::getFileLink(\SwaggerValidator\Common\Context $context, $uri)
278 |
279 |
280 |
281 |
282 |
283 | * Visibility: **private**
284 |
285 |
286 | #### Arguments
287 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
288 | * $uri **mixed**
289 |
290 |
291 |
292 | ### getFilePath
293 |
294 | mixed SwaggerValidator\Common\ReferenceFile::getFilePath(\SwaggerValidator\Common\Context $context, $filepath)
295 |
296 |
297 |
298 |
299 |
300 | * Visibility: **private**
301 |
302 |
303 | #### Arguments
304 | * $context **[SwaggerValidator\Common\Context](SwaggerValidator-Common-Context.md)**
305 | * $filepath **mixed**
306 |
307 |
308 |
309 | ### getUrlLink
310 |
311 | mixed SwaggerValidator\Common\ReferenceFile::getUrlLink($url)
312 |
313 |
314 |
315 |
316 |
317 | * Visibility: **private**
318 |
319 |
320 | #### Arguments
321 | * $url **mixed**
322 |
323 |
324 |
--------------------------------------------------------------------------------
/src/Object/Parameters.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Object;
20 |
21 | /**
22 | * Description of Parameters
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Parameters extends \SwaggerValidator\Common\CollectionSwagger
28 | {
29 |
30 | public function __construct()
31 | {
32 |
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
60 | {
61 | $this->checkJsonObjectOrArray($context, $jsonData);
62 |
63 | if (is_object($jsonData)) {
64 | $jsonData = get_object_vars($jsonData);
65 | }
66 |
67 | $keyIn = \SwaggerValidator\Common\FactorySwagger::KEY_IN;
68 |
69 | foreach ($jsonData as $key => $value) {
70 | $value = $this->extractNonRecursiveReference($context, $value);
71 |
72 | if (!property_exists($value, $keyIn)) {
73 | $context->throwException('Parameters "' . $key . '" is not well defined !', __METHOD__, __LINE__);
74 | }
75 |
76 | $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
77 | }
78 |
79 | $context->logDecode(get_class($this), __METHOD__, __LINE__);
80 | }
81 |
82 | public function validate(\SwaggerValidator\Common\Context $context)
83 | {
84 | if ($context->getType() !== \SwaggerValidator\Common\Context::TYPE_REQUEST) {
85 | return true;
86 | }
87 |
88 | $check = true;
89 |
90 | foreach ($this->keys() as $key) {
91 | if (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\Object\ParameterBody)) {
92 | $check = $check && $this->checkExistsEmptyValidate($context->setDataPath(\SwaggerValidator\Common\FactorySwagger::LOCATION_BODY)->setLocation(\SwaggerValidator\Common\FactorySwagger::LOCATION_BODY)->setSandBox(), $key);
93 | }
94 | elseif (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\DataType\TypeCommon)) {
95 | $check = $check && $this->checkExistsEmptyValidate($context->setDataPath($this->$key->name)->setLocation($this->$key->in)->setSandBox(), $key);
96 | }
97 | }
98 |
99 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
100 | return true;
101 | }
102 |
103 | protected function checkExistsEmptyValidate(\SwaggerValidator\Common\Context $context, $key)
104 | {
105 | $context->dataLoad();
106 | $keyRequired = \SwaggerValidator\Common\FactorySwagger::KEY_REQUIRED;
107 |
108 | if ($this->$key->isRequired() == true && !$context->isDataExists()) {
109 | $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_NOTFOUND, $context->getDataPath() . ' is not found', __METHOD__, __LINE__);
110 | }
111 | elseif (!$context->isDataExists()) {
112 | return true;
113 | }
114 |
115 | return $this->$key->validate($context);
116 | }
117 |
118 | function getModel(\SwaggerValidator\Common\Context $context, $listParameters)
119 | {
120 | foreach ($this->keys() as $key) {
121 | $model = null;
122 | $in = null;
123 | $name = null;
124 |
125 | if (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\Object\ParameterBody)) {
126 | $name = \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY;
127 | $in = \SwaggerValidator\Common\FactorySwagger::LOCATION_BODY;
128 | $model = $this->$key->getModel($context->setDataPath($key));
129 | }
130 | elseif (is_object($this->$key) && ($this->$key instanceof \SwaggerValidator\DataType\TypeCommon)) {
131 | $name = $this->$key->name;
132 | $in = $this->$key->in;
133 | $model = $this->$key->getModel($context->setDataPath($key));
134 | }
135 |
136 | if (!array_key_exists($in, $listParameters) || !is_array($listParameters[$in])) {
137 | $listParameters[$in] = array();
138 | }
139 |
140 | $listParameters[$in][$name] = $model;
141 | }
142 |
143 | $context->logModel(__METHOD__, __LINE__);
144 | return $listParameters;
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/doc/SwaggerValidator-Common-Collection.md:
--------------------------------------------------------------------------------
1 | SwaggerValidator\Common\Collection
2 | ===============
3 |
4 | Description of Collection
5 |
6 |
7 |
8 |
9 | * Class name: Collection
10 | * Namespace: SwaggerValidator\Common
11 | * This class implements: Countable, IteratorAggregate, ArrayAccess, Serializable, [JsonSerializable](JsonSerializable.md)
12 |
13 |
14 |
15 |
16 | Properties
17 | ----------
18 |
19 |
20 | ### $collection
21 |
22 | private array $collection = array()
23 |
24 |
25 |
26 |
27 |
28 | * Visibility: **private**
29 |
30 |
31 | ### $originTypeArray
32 |
33 | protected boolean $originTypeArray = false
34 |
35 |
36 |
37 |
38 |
39 | * Visibility: **protected**
40 |
41 |
42 | Methods
43 | -------
44 |
45 |
46 | ### __isset
47 |
48 | mixed SwaggerValidator\Common\Collection::__isset($key)
49 |
50 | Property Overloading
51 |
52 |
53 |
54 | * Visibility: **public**
55 |
56 |
57 | #### Arguments
58 | * $key **mixed**
59 |
60 |
61 |
62 | ### __get
63 |
64 | mixed SwaggerValidator\Common\Collection::__get($key)
65 |
66 |
67 |
68 |
69 |
70 | * Visibility: **public**
71 |
72 |
73 | #### Arguments
74 | * $key **mixed**
75 |
76 |
77 |
78 | ### __set
79 |
80 | mixed SwaggerValidator\Common\Collection::__set($key, $value)
81 |
82 |
83 |
84 |
85 |
86 | * Visibility: **public**
87 |
88 |
89 | #### Arguments
90 | * $key **mixed**
91 | * $value **mixed**
92 |
93 |
94 |
95 | ### __unset
96 |
97 | mixed SwaggerValidator\Common\Collection::__unset($key)
98 |
99 |
100 |
101 |
102 |
103 | * Visibility: **public**
104 |
105 |
106 | #### Arguments
107 | * $key **mixed**
108 |
109 |
110 |
111 | ### __storeData
112 |
113 | mixed SwaggerValidator\Common\Collection::__storeData($key, $value)
114 |
115 | Var Export Method
116 |
117 |
118 |
119 | * Visibility: **protected**
120 |
121 |
122 | #### Arguments
123 | * $key **mixed**
124 | * $value **mixed**
125 |
126 |
127 |
128 | ### __set_state
129 |
130 | mixed SwaggerValidator\Common\Collection::__set_state(array $properties)
131 |
132 |
133 |
134 |
135 |
136 | * Visibility: **public**
137 | * This method is **static**.
138 |
139 |
140 | #### Arguments
141 | * $properties **array**
142 |
143 |
144 |
145 | ### offsetSet
146 |
147 | mixed SwaggerValidator\Common\Collection::offsetSet($key, $value)
148 |
149 | Array Access
150 |
151 |
152 |
153 | * Visibility: **public**
154 |
155 |
156 | #### Arguments
157 | * $key **mixed**
158 | * $value **mixed**
159 |
160 |
161 |
162 | ### offsetExists
163 |
164 | mixed SwaggerValidator\Common\Collection::offsetExists($key)
165 |
166 |
167 |
168 |
169 |
170 | * Visibility: **public**
171 |
172 |
173 | #### Arguments
174 | * $key **mixed**
175 |
176 |
177 |
178 | ### offsetUnset
179 |
180 | mixed SwaggerValidator\Common\Collection::offsetUnset($key)
181 |
182 |
183 |
184 |
185 |
186 | * Visibility: **public**
187 |
188 |
189 | #### Arguments
190 | * $key **mixed**
191 |
192 |
193 |
194 | ### offsetGet
195 |
196 | mixed SwaggerValidator\Common\Collection::offsetGet($key)
197 |
198 |
199 |
200 |
201 |
202 | * Visibility: **public**
203 |
204 |
205 | #### Arguments
206 | * $key **mixed**
207 |
208 |
209 |
210 | ### getIterator
211 |
212 | mixed SwaggerValidator\Common\Collection::getIterator()
213 |
214 | IteratorAggregate
215 |
216 |
217 |
218 | * Visibility: **public**
219 |
220 |
221 |
222 |
223 | ### count
224 |
225 | mixed SwaggerValidator\Common\Collection::count()
226 |
227 | Countable
228 |
229 |
230 |
231 | * Visibility: **public**
232 |
233 |
234 |
235 |
236 | ### setJSONIsArray
237 |
238 | mixed SwaggerValidator\Common\Collection::setJSONIsArray()
239 |
240 |
241 |
242 |
243 |
244 | * Visibility: **protected**
245 |
246 |
247 |
248 |
249 | ### jsonSerialize
250 |
251 | mixed SwaggerValidator\Common\Collection::jsonSerialize()
252 |
253 |
254 |
255 |
256 |
257 | * Visibility: **public**
258 |
259 |
260 |
261 |
262 | ### serialize
263 |
264 | mixed SwaggerValidator\Common\Collection::serialize()
265 |
266 |
267 |
268 |
269 |
270 | * Visibility: **public**
271 |
272 |
273 |
274 |
275 | ### unserialize
276 |
277 | mixed SwaggerValidator\Common\Collection::unserialize($data)
278 |
279 |
280 |
281 |
282 |
283 | * Visibility: **public**
284 |
285 |
286 | #### Arguments
287 | * $data **mixed**
288 |
289 |
290 |
291 | ### all
292 |
293 | array SwaggerValidator\Common\Collection::all()
294 |
295 | Fetch set data
296 |
297 |
298 |
299 | * Visibility: **public**
300 |
301 |
302 |
303 |
304 | ### keys
305 |
306 | array SwaggerValidator\Common\Collection::keys()
307 |
308 | Fetch set data keys
309 |
310 |
311 |
312 | * Visibility: **public**
313 |
314 |
315 |
316 |
317 | ### has
318 |
319 | boolean SwaggerValidator\Common\Collection::has(string $key)
320 |
321 | Does this set contain a key?
322 |
323 |
324 |
325 | * Visibility: **public**
326 |
327 |
328 | #### Arguments
329 | * $key **string** - <p>The data key</p>
330 |
331 |
332 |
333 | ### remove
334 |
335 | mixed SwaggerValidator\Common\Collection::remove(string $key)
336 |
337 | Remove value with key from this set
338 |
339 |
340 |
341 | * Visibility: **public**
342 |
343 |
344 | #### Arguments
345 | * $key **string** - <p>The data key</p>
346 |
347 |
348 |
349 | ### clear
350 |
351 | mixed SwaggerValidator\Common\Collection::clear()
352 |
353 | Clear all values
354 |
355 |
356 |
357 | * Visibility: **public**
358 |
359 |
360 |
361 |
362 | ### jsonEncode
363 |
364 | mixed SwaggerValidator\Common\Collection::jsonEncode($mixed)
365 |
366 |
367 |
368 |
369 |
370 | * Visibility: **public**
371 | * This method is **static**.
372 |
373 |
374 | #### Arguments
375 | * $mixed **mixed**
376 |
377 |
378 |
379 | ### jsonEncodePretty
380 |
381 | mixed SwaggerValidator\Common\Collection::jsonEncodePretty($mixed)
382 |
383 |
384 |
385 |
386 |
387 | * Visibility: **public**
388 | * This method is **static**.
389 |
390 |
391 | #### Arguments
392 | * $mixed **mixed**
393 |
394 |
395 |
--------------------------------------------------------------------------------
/src/Common/ReferenceItem.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Common;
20 |
21 | /**
22 | * Description of ReferenceItem
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class ReferenceItem
28 | {
29 |
30 | private $contents;
31 | private $object;
32 |
33 | public function __construct()
34 | {
35 |
36 | }
37 |
38 | public function setJsonData($jsonData)
39 | {
40 | $this->contents = $jsonData;
41 | }
42 |
43 | public function __get($name)
44 | {
45 | if (property_exists($this, $name)) {
46 | return $this->$name;
47 | }
48 |
49 | return null;
50 | }
51 |
52 | /**
53 | * Var Export Method
54 | */
55 | protected function __storeData($key, $value = null)
56 | {
57 | if (property_exists($this, $key)) {
58 | $this->$key = $value;
59 | }
60 | }
61 |
62 | public static function __set_state(array $properties)
63 | {
64 | $obj = new static;
65 |
66 | foreach ($properties as $key => $value) {
67 | $obj->__storeData($key, $value);
68 | }
69 |
70 | return $obj;
71 | }
72 |
73 | public function extractAllReferences(\SwaggerValidator\Common\Context $context)
74 | {
75 | $refList = array();
76 |
77 | if (is_object($this->contents)) {
78 | $refList = $this->extractReferenceObject($context, $this->contents);
79 | }
80 | elseif (is_array($this->contents)) {
81 | $refList = $this->extractReferenceArray($context, $this->contents);
82 | }
83 |
84 | return array_unique($refList);
85 | }
86 |
87 | private function extractReferenceArray(\SwaggerValidator\Common\Context $context, array &$array)
88 | {
89 | $refList = array();
90 |
91 | foreach ($array as $key => $value) {
92 |
93 | if ($key === \SwaggerValidator\Common\FactorySwagger::KEY_REFERENCE) {
94 | $oldRef = $value;
95 | $value = \SwaggerValidator\Common\CollectionReference::getIdFromRef($context, $value);
96 | $context->logReference('replace', $value, $oldRef, __METHOD__, __LINE__);
97 | $refList[] = $value;
98 | }
99 | elseif (is_array($value)) {
100 | $refList = $refList + $this->extractReferenceArray($context->setDataPath($key), $value);
101 | }
102 | elseif (is_object($value)) {
103 | $refList = $refList + $this->extractReferenceObject($context->setDataPath($key), $value);
104 | }
105 | else {
106 | continue;
107 | }
108 |
109 | $array[$key] = $value;
110 | }
111 |
112 | return $refList;
113 | }
114 |
115 | private function extractReferenceObject(\SwaggerValidator\Common\Context $context, \stdClass &$stdClass)
116 | {
117 | $refList = array();
118 |
119 | foreach (get_object_vars($stdClass) as $key => $value) {
120 |
121 | if ($key === \SwaggerValidator\Common\FactorySwagger::KEY_REFERENCE) {
122 | $oldRef = $value;
123 | $value = \SwaggerValidator\Common\CollectionReference::getIdFromRef($context, $value);
124 | $context->logReference('replace', $value, $oldRef, __METHOD__, __LINE__);
125 | $refList[] = $value;
126 | }
127 | elseif (is_array($value)) {
128 | $refList = $refList + $this->extractReferenceArray($context->setDataPath($key), $value);
129 | }
130 | elseif (is_object($value)) {
131 | $refList = $refList + $this->extractReferenceObject($context->setDataPath($key), $value);
132 | }
133 | else {
134 | continue;
135 | }
136 |
137 | $stdClass->$key = $value;
138 | }
139 |
140 | return $refList;
141 | }
142 |
143 | public function getJson(\SwaggerValidator\Common\Context $context)
144 | {
145 | return $this->contents;
146 | }
147 |
148 | public function getObject(\SwaggerValidator\Common\Context $context)
149 | {
150 | if (!is_object($this->object)) {
151 | $this->jsonUnSerialize($context, true);
152 | $this->contents = null;
153 | }
154 |
155 | return $this->object;
156 | }
157 |
158 | protected function getCleanClass($class)
159 | {
160 | $classPart = explode('\\', $class);
161 | return array_pop($classPart);
162 | }
163 |
164 | public function jsonUnSerialize(\SwaggerValidator\Common\Context $context)
165 | {
166 | if (is_object($this->contents) && ($this->contents instanceof \stdClass) && property_exists($this->contents, \SwaggerValidator\Common\FactorySwagger::KEY_TYPE)) {
167 | $this->object = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context, $this->getCleanClass(__CLASS__), \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA, $this->contents);
168 | }
169 | else {
170 | $this->object = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context, null, null, $this->contents);
171 | }
172 | }
173 |
174 | }
175 |
--------------------------------------------------------------------------------
/src/Common/Factory.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Common;
20 |
21 | /**
22 | * Description of Factory
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class Factory extends \SwaggerValidator\Common\Collection
28 | {
29 |
30 | /**
31 | *
32 | * @var \SwaggerValidator\Common\Factory
33 | */
34 | private static $instance;
35 |
36 | /**
37 | * Private construct for singleton
38 | */
39 | private function __construct()
40 | {
41 |
42 | }
43 |
44 | /**
45 | * get the singleton of this collection
46 | * @return \SwaggerValidator\Common\Factory
47 | */
48 | public static function getInstance()
49 | {
50 | if (empty(self::$instance)) {
51 | self::$instance = new static();
52 | }
53 |
54 | return self::$instance;
55 | }
56 |
57 | /**
58 | * replace the singleton of this collection
59 | */
60 | public static function setInstance(\SwaggerValidator\Common\Factory $instance)
61 | {
62 | self::$instance = $instance;
63 | }
64 |
65 | /**
66 | * prune the singleton of this collection
67 | */
68 | public static function pruneInstance()
69 | {
70 | self::$instance = null;
71 | }
72 |
73 | /**
74 | * Var Export Method
75 | */
76 | protected function __storeData($key, $value = null)
77 | {
78 | if (property_exists($this, $key)) {
79 | $this->$key = $value;
80 | }
81 | else {
82 | parent::__storeData($key, $value);
83 | }
84 | }
85 |
86 | public static function __set_state(array $properties)
87 | {
88 | self::getInstance();
89 |
90 | foreach ($properties as $key => $value) {
91 | self::$instance->__storeData($key, $value);
92 | }
93 |
94 | return self::getInstance();
95 | }
96 |
97 | /**
98 | * Check if the type is defined and return his callable string
99 | * @param callable $type
100 | * @throws Exception
101 | */
102 | private function getClass($type)
103 | {
104 | $collType = \SwaggerValidator\Common\CollectionType::getInstance();
105 | $class = $collType->get($type);
106 |
107 | if (empty($class)) {
108 | $e = new \SwaggerValidator\Exception('Cannot retrieve the callable for this type : ' . $type);
109 | $e->setFile(__METHOD__);
110 | $e->setLine(__LINE__);
111 | throw $e;
112 | }
113 |
114 | return $class;
115 | }
116 |
117 | /**
118 | * return an instance of the given type
119 | * @param string $type
120 | * @return object
121 | */
122 | public function __get($type)
123 | {
124 | $class = $this->getClass($type);
125 | $name = $this->normalizeType($type);
126 |
127 | if (parent::__isset($name)) {
128 | $instance = parent::__get($name);
129 | }
130 | else {
131 | $instance = $this->invoke($type);
132 | }
133 |
134 | return clone $instance;
135 | }
136 |
137 | /**
138 | * Start new instance of the object type
139 | * @param string $type the name of the object type for the new instance
140 | * @param type $parameters [optional] the parameters to the constructor
141 | * @return object
142 | * @throws Exception
143 | */
144 | public function invoke($type, $parameters = null)
145 | {
146 | $class = $this->getClass($type);
147 | $name = $this->normalizeType($type);
148 |
149 | $params = func_get_args();
150 | array_shift($params);
151 |
152 | $reflector = new \ReflectionClass($class);
153 | $instance = $reflector->newInstanceArgs($params);
154 |
155 | if (empty($params)) {
156 | parent::__set($name, $instance);
157 | }
158 |
159 | return (clone $instance);
160 | }
161 |
162 | /**
163 | * Register the base instance to be clone when a new instance is call
164 | * @param string $type
165 | * @param object|\Closure $object
166 | */
167 | public function __set($type, $object)
168 | {
169 |
170 | }
171 |
172 | public function jsonSerialize()
173 | {
174 |
175 | }
176 |
177 | public function serialize()
178 | {
179 |
180 | }
181 |
182 | public function unserialize($data)
183 | {
184 |
185 | }
186 |
187 | /**
188 | * return an instance of the given type
189 | * @param string $type
190 | * @return object
191 | */
192 | public function get($type)
193 | {
194 | return $this->__get($type);
195 | }
196 |
197 | /**
198 | * Register the base instance to be clone when a new instance is call
199 | * @param string $type
200 | * @param object|\Closure $object
201 | */
202 | public function registerClosure($type, $object)
203 | {
204 | $class = $this->getClass($type);
205 | $name = $this->normalizeType($type);
206 |
207 | if (is_object($object) || ($object instanceof \Closure)) {
208 | parent::__set($name, $object);
209 | return true;
210 | }
211 |
212 | return false;
213 | }
214 |
215 | public function normalizeType($type)
216 | {
217 | return \SwaggerValidator\Common\CollectionType::getInstance()->normalizeType($type);
218 | }
219 |
220 | }
221 |
--------------------------------------------------------------------------------
/src/Common/Sandbox.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Common;
20 |
21 | /**
22 | * Description of Sandbox
23 | *
24 | * @author Nicolas JUHEL
25 | */
26 | class Sandbox
27 | {
28 |
29 | /**
30 | *
31 | * @var string
32 | */
33 | private $body;
34 |
35 | /**
36 | *
37 | * @var \SwaggerValidator\Common\SandBoxItem
38 | */
39 | private $form;
40 |
41 | /**
42 | *
43 | * @var \SwaggerValidator\Common\SandBoxItem
44 | */
45 | private $header;
46 |
47 | /**
48 | *
49 | * @var \SwaggerValidator\Common\SandBoxItem
50 | */
51 | private $query;
52 |
53 | /**
54 | *
55 | * @var \SwaggerValidator\Common\SandBoxItem
56 | */
57 | private $path;
58 |
59 | /**
60 | *
61 | * @var \SwaggerValidator\Common\Sandbox
62 | */
63 | private static $instance;
64 |
65 | /**
66 | * Private construct for singleton
67 | */
68 | private function __construct()
69 | {
70 | $this->body = null;
71 | $this->form = new \SwaggerValidator\Common\SandBoxItem();
72 | $this->header = new \SwaggerValidator\Common\SandBoxItem();
73 | $this->path = new \SwaggerValidator\Common\SandBoxItem();
74 | $this->query = new \SwaggerValidator\Common\SandBoxItem();
75 | }
76 |
77 | /**
78 | *
79 | * @return \SwaggerValidator\Common\Sandbox
80 | */
81 | public static function getInstance()
82 | {
83 | if (empty(self::$instance)) {
84 | self::$instance = new static();
85 | }
86 |
87 | return self::$instance;
88 | }
89 |
90 | /**
91 | * replace the singleton of this collection
92 | */
93 | public static function setInstance(\SwaggerValidator\Common\Sandbox $instance)
94 | {
95 | self::$instance = $instance;
96 | }
97 |
98 | public static function pruneInstance()
99 | {
100 | self::$instance = null;
101 | }
102 |
103 | public function __isset($name)
104 | {
105 | return false;
106 | }
107 |
108 | public function __unset($name)
109 | {
110 | return false;
111 | }
112 |
113 | /**
114 | * Var Export Method
115 | */
116 | protected function __storeData($key, $value = null)
117 | {
118 | if (property_exists($this, $key)) {
119 | $this->$key = $value;
120 | }
121 | else {
122 | parent::__storeData($key, $value);
123 | }
124 | }
125 |
126 | public static function __set_state(array $properties)
127 | {
128 | $obj = new static;
129 |
130 | foreach ($properties as $key => $value) {
131 | $obj->__storeData($key, $value);
132 | }
133 |
134 | return $obj;
135 | }
136 |
137 | /**
138 | * Return the content of the reference as object or mixed data
139 | * @param string $fileLink
140 | * @return \SwaggerValidator\Common\ReferenceFile
141 | * @throws \SwaggerValidator\Exception
142 | */
143 | public function __get($name)
144 | {
145 | return false;
146 | }
147 |
148 | public function __set($name, $value = null)
149 | {
150 | return false;
151 | }
152 |
153 | public function jsonSerialize()
154 | {
155 |
156 | }
157 |
158 | public function serialize()
159 | {
160 |
161 | }
162 |
163 | public function unserialize($data)
164 | {
165 |
166 | }
167 |
168 | public function hasBody()
169 | {
170 | return ($this->body !== null);
171 | }
172 |
173 | public function getBody()
174 | {
175 | return $this->body;
176 | }
177 |
178 | public function setBody($value = null)
179 | {
180 | return $this->body = $value;
181 | }
182 |
183 | public function hasForm($name)
184 | {
185 | return $this->form->has($name);
186 | }
187 |
188 | public function keysForm()
189 | {
190 | return $this->form->keys();
191 | }
192 |
193 | public function getForm($name)
194 | {
195 | return $this->form->get($name);
196 | }
197 |
198 | public function setForm($name, $value = null)
199 | {
200 | return $this->form->set($name, $value);
201 | }
202 |
203 | public function hasHeader($name)
204 | {
205 | return $this->header->has($name);
206 | }
207 |
208 | public function keysHeader()
209 | {
210 | return $this->header->keys();
211 | }
212 |
213 | public function getHeader($name)
214 | {
215 | return $this->header->get($name);
216 | }
217 |
218 | public function setHeader($name, $value = null)
219 | {
220 | return $this->header->set($name, $value);
221 | }
222 |
223 | public function hasPath($name)
224 | {
225 | return $this->path->has($name);
226 | }
227 |
228 | public function keysPath()
229 | {
230 | return $this->path->keys();
231 | }
232 |
233 | public function getPath($name)
234 | {
235 | return $this->path->get($name);
236 | }
237 |
238 | public function setPath($name, $value = null)
239 | {
240 | return $this->path->set($name, $value);
241 | }
242 |
243 | public function hasQueryString($name)
244 | {
245 | return $this->query->has($name);
246 | }
247 |
248 | public function keysQueryString()
249 | {
250 | return $this->query->keys();
251 | }
252 |
253 | public function getQueryString($name)
254 | {
255 | return $this->query->get($name);
256 | }
257 |
258 | public function setQueryString($name, $value = null)
259 | {
260 | return $this->query->set($name, $value);
261 | }
262 |
263 | }
264 |
--------------------------------------------------------------------------------
/src/Common/CollectionFile.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\Common;
20 |
21 | /**
22 | * Description of ReferenceCollection
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class CollectionFile extends \SwaggerValidator\Common\Collection
28 | {
29 |
30 | const ID_PREFIX = 'file:';
31 |
32 | /**
33 | *
34 | * @var \SwaggerValidator\Common\CollectionFile
35 | */
36 | private static $instance;
37 |
38 | /**
39 | *
40 | * @var array
41 | */
42 | private static $fileIdList = array();
43 |
44 | /**
45 | * Private construct for singleton
46 | */
47 | private function __construct()
48 | {
49 |
50 | }
51 |
52 | /**
53 | *
54 | * @return \SwaggerValidator\Common\CollectionFile
55 | */
56 | public static function getInstance()
57 | {
58 | if (empty(self::$instance)) {
59 | self::$instance = new static();
60 | }
61 |
62 | return self::$instance;
63 | }
64 |
65 | /**
66 | * replace the singleton of this collection
67 | */
68 | public static function setInstance(\SwaggerValidator\Common\CollectionFile $instance)
69 | {
70 | self::$instance = $instance;
71 | self::$fileIdList = array();
72 | }
73 |
74 | public static function pruneInstance()
75 | {
76 | self::$instance = null;
77 | self::$fileIdList = array();
78 | }
79 |
80 | public function __isset($ref)
81 | {
82 | parent::__isset(self::getIdFromRef($ref));
83 | }
84 |
85 | public function __unset($ref)
86 | {
87 | parent::__unset(self::getIdFromRef($ref));
88 | }
89 |
90 | /**
91 | * Return the content of the reference as object or mixed data
92 | * @param string $fileLink
93 | * @return \SwaggerValidator\Common\ReferenceFile
94 | * @throws \SwaggerValidator\Exception
95 | */
96 | public function __get($fileLink)
97 | {
98 |
99 | }
100 |
101 | public function __set($ref, $value = null)
102 | {
103 |
104 | }
105 |
106 | /**
107 | * Var Export Method
108 | */
109 | protected function __storeData($key, $value = null)
110 | {
111 | if (property_exists($this, $key)) {
112 | $this->$key = $value;
113 | }
114 | else {
115 | parent::__storeData($key, $value);
116 | }
117 | }
118 |
119 | public static function __set_state(array $properties)
120 | {
121 | self::getInstance();
122 |
123 | foreach ($properties as $key => $value) {
124 | self::$instance->__storeData($key, $value);
125 | }
126 |
127 | return self::getInstance();
128 | }
129 |
130 | public function jsonSerialize()
131 | {
132 | return null;
133 | }
134 |
135 | public function serialize()
136 | {
137 | return null;
138 | }
139 |
140 | public function unserialize($data)
141 | {
142 | return null;
143 | }
144 |
145 | /**
146 | * Return the content of the reference as object or mixed data
147 | * @param string $fileLink
148 | * @return \SwaggerValidator\Common\ReferenceFile
149 | * @throws \SwaggerValidator\Exception
150 | */
151 | public function get(\SwaggerValidator\Common\Context $context, $fileLink)
152 | {
153 | if (empty($fileLink)) {
154 | $context->throwException('Cannot find file link from ref : ' . $fileLink, __FILE__, __LINE__);
155 | }
156 |
157 | $id = self::getIdFromRef($fileLink);
158 |
159 | if (!is_object(parent::__get($id))) {
160 | $this->set($context, $fileLink);
161 | }
162 |
163 | $context->logLoadFile(self::getRefFromId($id), __METHOD__, __LINE__);
164 |
165 | return parent::__get($id);
166 | }
167 |
168 | public function set(\SwaggerValidator\Common\Context $context, $ref, $value = null)
169 | {
170 | $id = self::getIdFromRef($ref);
171 |
172 | if ($id == $ref) {
173 | $ref = self::getRefFromId($id);
174 | }
175 |
176 | if (!is_object($value) || !($value instanceof \SwaggerValidator\Common\ReferenceFile)) {
177 | $value = new \SwaggerValidator\Common\ReferenceFile($context, $ref);
178 | }
179 |
180 | if (is_object($value) && ($value instanceof \SwaggerValidator\Common\ReferenceFile)) {
181 | $value->extractAllReference($context);
182 | return parent::__set($id, $value);
183 | }
184 |
185 | $context->throwException('Cannot register file from ref : ' . $ref, __FILE__, __LINE__);
186 | }
187 |
188 | public static function getReferenceFileLink($ref)
189 | {
190 | if (strpos($ref, '#') === false) {
191 | return $ref;
192 | }
193 |
194 | $fileLink = explode('#', $ref);
195 | array_pop($fileLink);
196 | return implode('#', $fileLink);
197 | }
198 |
199 | public static function getReferenceInnerPath($ref)
200 | {
201 | if (strpos($ref, '#') === false) {
202 | return;
203 | }
204 |
205 | $fileLink = explode('#', $ref);
206 | return array_pop($fileLink);
207 | }
208 |
209 | public static function getIdFromRef($fullRef)
210 | {
211 | if (substr($fullRef, 0, 3) === self::ID_PREFIX) {
212 | return $fullRef;
213 | }
214 |
215 | if (!is_array(self::$fileIdList)) {
216 | self::$fileIdList = array();
217 | }
218 |
219 | if (!array_key_exists($fullRef, self::$fileIdList)) {
220 | //self::$fileIdList[$fullRef] = uniqid(self::ID_PREFIX);
221 | self::$fileIdList[$fullRef] = self::ID_PREFIX . hash('sha256', $fullRef, false);
222 | }
223 |
224 | return self::$fileIdList[$fullRef];
225 | }
226 |
227 | public static function getRefFromId($id)
228 | {
229 | if (substr($id, 0, 3) !== self::ID_PREFIX) {
230 | return $id;
231 | }
232 |
233 | if (!is_array(self::$fileIdList)) {
234 | self::$fileIdList = array();
235 | }
236 |
237 | if (!in_array($id, self::$fileIdList)) {
238 | return null;
239 | }
240 |
241 | return array_search($id, self::$fileIdList);
242 | }
243 |
244 | }
245 |
--------------------------------------------------------------------------------
/src/DataType/TypeInteger.php:
--------------------------------------------------------------------------------
1 | .
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | namespace SwaggerValidator\DataType;
20 |
21 | /**
22 | * Description of Integer
23 | *
24 | * @author Nicolas JUHEL
25 | * @version 1.0.0
26 | */
27 | class TypeInteger extends \SwaggerValidator\DataType\TypeCommon
28 | {
29 |
30 | public function __construct()
31 | {
32 | parent::registerMandatoryKey('type');
33 | }
34 |
35 | /**
36 | * Var Export Method
37 | */
38 | protected function __storeData($key, $value = null)
39 | {
40 | if (property_exists($this, $key)) {
41 | $this->$key = $value;
42 | }
43 | else {
44 | parent::__storeData($key, $value);
45 | }
46 | }
47 |
48 | public static function __set_state(array $properties)
49 | {
50 | $obj = new static;
51 |
52 | foreach ($properties as $key => $value) {
53 | $obj->__storeData($key, $value);
54 | }
55 |
56 | return $obj;
57 | }
58 |
59 | public function validate(\SwaggerValidator\Common\Context $context)
60 | {
61 | if (!isset($this->type)) {
62 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
63 | }
64 |
65 | if (!isset($this->minimum) || $this->minimum < 1) {
66 | if ((!isset($this->exclusiveMinimum) || $this->exclusiveMinimum !== true) && $context->isDataEmpty()) {
67 | return true;
68 | }
69 | }
70 |
71 | if ($this->type != \SwaggerValidator\Common\FactorySwagger::TYPE_INTEGER) {
72 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_SWAGGER_ERROR, null, __METHOD__, __LINE__);
73 | }
74 |
75 | if (!$this->minimum($context, $context->getDataValue())) {
76 | return $context->setDataCheck('minimum')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATASIZE, null, __METHOD__, __LINE__);
77 | }
78 |
79 | if (!$this->maximum($context, $context->getDataValue())) {
80 | return $context->setDataCheck('maximum')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATASIZE, null, __METHOD__, __LINE__);
81 | }
82 |
83 | if (preg_match('/^\d+\.\d+[eE][+-]?\d+$/', $context->getDataValue())) {
84 | $context->setDataValue(bcsub(bcadd($context->getDataValue(), 1), 1));
85 | }
86 |
87 | if (!$this->type($context, $context->getDataValue())) {
88 | return $context->setDataCheck('type')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATATYPE, null, __METHOD__, __LINE__);
89 | }
90 |
91 | if (!$this->pattern($context, $context->getDataValue())) {
92 | return $context->setDataCheck('pattern')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_PATTERN, null, __METHOD__, __LINE__);
93 | }
94 |
95 | if (!$this->format($context, $context->getDataValue())) {
96 | return false;
97 | }
98 |
99 | if (!$this->enum($context, $context->getDataValue())) {
100 | return $context->setDataCheck('enum')->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATAVALUE, null, __METHOD__, __LINE__);
101 | }
102 |
103 | // completer les test integer
104 | $context->logValidate(get_class($this), __METHOD__, __LINE__);
105 | return true;
106 | }
107 |
108 | protected function type(\SwaggerValidator\Common\Context $context, $valueParams)
109 | {
110 | if (is_int($valueParams)) {
111 | return true;
112 | }
113 |
114 | $valueCheck = trim($valueParams);
115 |
116 | if (substr($valueCheck, 0, 1) == '-') {
117 | $valueCheck = substr($valueCheck, 1);
118 | }
119 |
120 | if (ctype_digit($valueCheck)) {
121 | return true;
122 | }
123 | else
124 | return false;
125 | }
126 |
127 | protected function format(\SwaggerValidator\Common\Context $context, $valueParams)
128 | {
129 | if (!isset($this->format)) {
130 | return true;
131 | }
132 |
133 | $valueCheck = trim($valueParams);
134 | $valueInt32 = bcpow(2, 31);
135 | $valueInt64 = bcpow(2, 63);
136 |
137 | if (substr($valueCheck, 0, 1) == '-') {
138 | $valueCheck = substr($valueCheck, 1);
139 | }
140 |
141 | $valueFloat = floatval($valueCheck);
142 |
143 | if ($this->format == 'int32' && ctype_digit($valueCheck) && $valueFloat < $valueInt32) {
144 | return true;
145 | }
146 |
147 | if ($this->format == 'int32' && ctype_digit($valueCheck) && $valueCheck < $valueInt32) {
148 | return true;
149 | }
150 |
151 | if ($this->format == 'int64' && ctype_digit($valueCheck) && $valueFloat < $valueInt64) {
152 | return true;
153 | }
154 |
155 | if ($this->format == 'int64' && ctype_digit($valueCheck) && $valueCheck < $valueInt64) {
156 | return true;
157 | }
158 |
159 | return $context->setValidationError(\SwaggerValidator\Common\Context::VALIDATION_TYPE_DATATYPE, 'The format does not match with registred patterns', __METHOD__, __LINE__);
160 | }
161 |
162 | protected function getExampleFormat(\SwaggerValidator\Common\Context $context)
163 | {
164 | $valueInt32 = bcsub(bcpow(2, 31), 1);
165 | $valueInt64 = bcsub(bcpow(2, 63), 1);
166 | $sign = (random_int(0, 1) > 0.5) ? '' : '-';
167 |
168 | if ($this->format == 'int32') {
169 | $context->logModel(__METHOD__, __LINE__);
170 | return $sign . random_int(0, (int) $valueInt32);
171 | }
172 |
173 | if ($this->format == 'int64') {
174 | $context->logModel(__METHOD__, __LINE__);
175 | return $sign . bcadd(random_int(0, (int) $valueInt32), random_int(0, (int) $valueInt32));
176 | }
177 |
178 | return $this->getExampleType($context);
179 | }
180 |
181 | protected function getExampleType(\SwaggerValidator\Common\Context $context)
182 | {
183 | $sign = (random_int(0, 1) > 0.5) ? '' : '-';
184 |
185 | $context->logModel(__METHOD__, __LINE__);
186 | return $sign . random_int(0, (int) bcsub(bcpow(2, 31), 1));
187 | }
188 |
189 | }
190 |
--------------------------------------------------------------------------------