@@ -6,128 +6,128 @@ |
||
| 6 | 6 | class Issue0005Test extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @covers \SwaggerGen\Swagger\Swagger::__construct |
|
| 11 | - */ |
|
| 12 | - public function testHandleCommand_Model_Property() |
|
| 13 | - { |
|
| 14 | - $object = new \SwaggerGen\Swagger\Swagger; |
|
| 15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 16 | - |
|
| 17 | - $schema = $object->handleCommand('model', 'foo'); |
|
| 18 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
| 19 | - |
|
| 20 | - $schema->handleCommand('property', 'string bar Some words here'); |
|
| 21 | - |
|
| 22 | - $path = $object->handleCommand('endpoint'); |
|
| 23 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
| 24 | - |
|
| 25 | - $this->assertSame(array( |
|
| 26 | - 'swagger' => '2.0', |
|
| 27 | - 'info' => array( |
|
| 28 | - 'title' => 'undefined', |
|
| 29 | - 'version' => '0', |
|
| 30 | - ), |
|
| 31 | - 'paths' => array( |
|
| 32 | - '/' => array(), |
|
| 33 | - ), |
|
| 34 | - 'definitions' => array( |
|
| 35 | - 'foo' => array( |
|
| 36 | - 'type' => 'object', |
|
| 37 | - 'required' => array( |
|
| 38 | - 'bar', |
|
| 39 | - ), |
|
| 40 | - 'properties' => array( |
|
| 41 | - 'bar' => array( |
|
| 42 | - 'type' => 'string', |
|
| 43 | - 'description' => 'Some words here', |
|
| 44 | - ), |
|
| 45 | - ), |
|
| 46 | - ), |
|
| 47 | - ), |
|
| 48 | - ), $object->toArray()); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @covers \SwaggerGen\Swagger\Swagger::__construct |
|
| 53 | - */ |
|
| 54 | - public function testHandleCommand_Model_DuplicateProperties() |
|
| 55 | - { |
|
| 56 | - $object = new \SwaggerGen\Swagger\Swagger(); |
|
| 57 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 58 | - |
|
| 59 | - $schema = $object->handleCommand('model', 'foo'); |
|
| 60 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
| 61 | - |
|
| 62 | - $schema->handleCommand('property', 'string bar Some words here'); |
|
| 63 | - $schema->handleCommand('property', 'integer bar Some other words'); |
|
| 64 | - |
|
| 65 | - $path = $object->handleCommand('endpoint'); |
|
| 66 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
| 67 | - |
|
| 68 | - $this->assertSame(array( |
|
| 69 | - 'swagger' => '2.0', |
|
| 70 | - 'info' => array( |
|
| 71 | - 'title' => 'undefined', |
|
| 72 | - 'version' => '0', |
|
| 73 | - ), |
|
| 74 | - 'paths' => array( |
|
| 75 | - '/' => array(), |
|
| 76 | - ), |
|
| 77 | - 'definitions' => array( |
|
| 78 | - 'foo' => array( |
|
| 79 | - 'type' => 'object', |
|
| 80 | - 'required' => array( |
|
| 81 | - 'bar', |
|
| 82 | - ), |
|
| 83 | - 'properties' => array( |
|
| 84 | - 'bar' => array( |
|
| 85 | - 'type' => 'integer', |
|
| 86 | - 'format' => 'int32', |
|
| 87 | - 'description' => 'Some other words', |
|
| 88 | - ), |
|
| 89 | - ), |
|
| 90 | - ), |
|
| 91 | - ), |
|
| 92 | - ), $object->toArray()); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @covers \SwaggerGen\Swagger\Operation::handleCommand |
|
| 97 | - */ |
|
| 98 | - public function testHandleCommand_Query_Duplicate() |
|
| 99 | - { |
|
| 100 | - $object = new \SwaggerGen\Swagger\Swagger; |
|
| 101 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 102 | - |
|
| 103 | - $operation = new \SwaggerGen\Swagger\Operation($object); |
|
| 104 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
|
| 105 | - |
|
| 106 | - $parameter = $operation->handleCommand('query', 'int foo Some text'); |
|
| 107 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
| 108 | - |
|
| 109 | - $parameter = $operation->handleCommand('query', 'string foo Other text'); |
|
| 110 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
| 111 | - |
|
| 112 | - $response = $operation->handleCommand('response', '200'); |
|
| 113 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Response', $response); |
|
| 114 | - |
|
| 115 | - $this->assertSame(array( |
|
| 116 | - 'parameters' => array( |
|
| 117 | - array( |
|
| 118 | - 'name' => 'foo', |
|
| 119 | - 'in' => 'query', |
|
| 120 | - 'description' => 'Other text', |
|
| 121 | - 'required' => true, |
|
| 122 | - 'type' => 'string', |
|
| 123 | - ), |
|
| 124 | - ), |
|
| 125 | - 'responses' => array( |
|
| 126 | - 200 => array( |
|
| 127 | - 'description' => 'OK', |
|
| 128 | - ), |
|
| 129 | - ), |
|
| 130 | - ), $operation->toArray()); |
|
| 131 | - } |
|
| 9 | + /** |
|
| 10 | + * @covers \SwaggerGen\Swagger\Swagger::__construct |
|
| 11 | + */ |
|
| 12 | + public function testHandleCommand_Model_Property() |
|
| 13 | + { |
|
| 14 | + $object = new \SwaggerGen\Swagger\Swagger; |
|
| 15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 16 | + |
|
| 17 | + $schema = $object->handleCommand('model', 'foo'); |
|
| 18 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
| 19 | + |
|
| 20 | + $schema->handleCommand('property', 'string bar Some words here'); |
|
| 21 | + |
|
| 22 | + $path = $object->handleCommand('endpoint'); |
|
| 23 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
| 24 | + |
|
| 25 | + $this->assertSame(array( |
|
| 26 | + 'swagger' => '2.0', |
|
| 27 | + 'info' => array( |
|
| 28 | + 'title' => 'undefined', |
|
| 29 | + 'version' => '0', |
|
| 30 | + ), |
|
| 31 | + 'paths' => array( |
|
| 32 | + '/' => array(), |
|
| 33 | + ), |
|
| 34 | + 'definitions' => array( |
|
| 35 | + 'foo' => array( |
|
| 36 | + 'type' => 'object', |
|
| 37 | + 'required' => array( |
|
| 38 | + 'bar', |
|
| 39 | + ), |
|
| 40 | + 'properties' => array( |
|
| 41 | + 'bar' => array( |
|
| 42 | + 'type' => 'string', |
|
| 43 | + 'description' => 'Some words here', |
|
| 44 | + ), |
|
| 45 | + ), |
|
| 46 | + ), |
|
| 47 | + ), |
|
| 48 | + ), $object->toArray()); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @covers \SwaggerGen\Swagger\Swagger::__construct |
|
| 53 | + */ |
|
| 54 | + public function testHandleCommand_Model_DuplicateProperties() |
|
| 55 | + { |
|
| 56 | + $object = new \SwaggerGen\Swagger\Swagger(); |
|
| 57 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 58 | + |
|
| 59 | + $schema = $object->handleCommand('model', 'foo'); |
|
| 60 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
| 61 | + |
|
| 62 | + $schema->handleCommand('property', 'string bar Some words here'); |
|
| 63 | + $schema->handleCommand('property', 'integer bar Some other words'); |
|
| 64 | + |
|
| 65 | + $path = $object->handleCommand('endpoint'); |
|
| 66 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
| 67 | + |
|
| 68 | + $this->assertSame(array( |
|
| 69 | + 'swagger' => '2.0', |
|
| 70 | + 'info' => array( |
|
| 71 | + 'title' => 'undefined', |
|
| 72 | + 'version' => '0', |
|
| 73 | + ), |
|
| 74 | + 'paths' => array( |
|
| 75 | + '/' => array(), |
|
| 76 | + ), |
|
| 77 | + 'definitions' => array( |
|
| 78 | + 'foo' => array( |
|
| 79 | + 'type' => 'object', |
|
| 80 | + 'required' => array( |
|
| 81 | + 'bar', |
|
| 82 | + ), |
|
| 83 | + 'properties' => array( |
|
| 84 | + 'bar' => array( |
|
| 85 | + 'type' => 'integer', |
|
| 86 | + 'format' => 'int32', |
|
| 87 | + 'description' => 'Some other words', |
|
| 88 | + ), |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 91 | + ), |
|
| 92 | + ), $object->toArray()); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @covers \SwaggerGen\Swagger\Operation::handleCommand |
|
| 97 | + */ |
|
| 98 | + public function testHandleCommand_Query_Duplicate() |
|
| 99 | + { |
|
| 100 | + $object = new \SwaggerGen\Swagger\Swagger; |
|
| 101 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
| 102 | + |
|
| 103 | + $operation = new \SwaggerGen\Swagger\Operation($object); |
|
| 104 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
|
| 105 | + |
|
| 106 | + $parameter = $operation->handleCommand('query', 'int foo Some text'); |
|
| 107 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
| 108 | + |
|
| 109 | + $parameter = $operation->handleCommand('query', 'string foo Other text'); |
|
| 110 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
| 111 | + |
|
| 112 | + $response = $operation->handleCommand('response', '200'); |
|
| 113 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Response', $response); |
|
| 114 | + |
|
| 115 | + $this->assertSame(array( |
|
| 116 | + 'parameters' => array( |
|
| 117 | + array( |
|
| 118 | + 'name' => 'foo', |
|
| 119 | + 'in' => 'query', |
|
| 120 | + 'description' => 'Other text', |
|
| 121 | + 'required' => true, |
|
| 122 | + 'type' => 'string', |
|
| 123 | + ), |
|
| 124 | + ), |
|
| 125 | + 'responses' => array( |
|
| 126 | + 200 => array( |
|
| 127 | + 'description' => 'OK', |
|
| 128 | + ), |
|
| 129 | + ), |
|
| 130 | + ), $operation->toArray()); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | } |
@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | class Issue0015Test extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Tests issue 15; Allow enumeration of property values |
|
| 11 | - * https://github.com/vanderlee/PHPSwaggerGen/issues/15 |
|
| 12 | - */ |
|
| 13 | - public function testPropertyEnumeration() |
|
| 14 | - { |
|
| 15 | - $object = new \SwaggerGen\SwaggerGen(); |
|
| 16 | - $array = $object->getSwagger(array(' |
|
| 9 | + /** |
|
| 10 | + * Tests issue 15; Allow enumeration of property values |
|
| 11 | + * https://github.com/vanderlee/PHPSwaggerGen/issues/15 |
|
| 12 | + */ |
|
| 13 | + public function testPropertyEnumeration() |
|
| 14 | + { |
|
| 15 | + $object = new \SwaggerGen\SwaggerGen(); |
|
| 16 | + $array = $object->getSwagger(array(' |
|
| 17 | 17 | api Test |
| 18 | 18 | definition ClassName |
| 19 | 19 | title ClassName |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | response 204 |
| 27 | 27 | ')); |
| 28 | 28 | |
| 29 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 30 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"204":{"description":"No Content"}}}}}' |
|
| 31 | - . ',"definitions":{"ClassName":{"type":"object","required":["type","meaningOfLifeTheUniverseAndEverything"],"properties":{"type":{"type":"string","enum":["ClassName"]},"meaningOfLifeTheUniverseAndEverything":{"type":"integer","format":"int32","enum":[42]}},"title":"ClassName"}}' |
|
| 32 | - . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 33 | - } |
|
| 29 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 30 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"204":{"description":"No Content"}}}}}' |
|
| 31 | + . ',"definitions":{"ClassName":{"type":"object","required":["type","meaningOfLifeTheUniverseAndEverything"],"properties":{"type":{"type":"string","enum":["ClassName"]},"meaningOfLifeTheUniverseAndEverything":{"type":"integer","format":"int32","enum":[42]}},"title":"ClassName"}}' |
|
| 32 | + . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | } |
@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | class Issue0002Test extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Tests issue 2; @rest/require should create object on each item |
|
| 11 | - * https://github.com/vanderlee/PHPSwaggerGen/issues/2 |
|
| 12 | - */ |
|
| 13 | - public function testRequireMustBeObject() |
|
| 14 | - { |
|
| 15 | - $object = new \SwaggerGen\SwaggerGen(); |
|
| 16 | - $array = $object->getSwagger(array(' |
|
| 9 | + /** |
|
| 10 | + * Tests issue 2; @rest/require should create object on each item |
|
| 11 | + * https://github.com/vanderlee/PHPSwaggerGen/issues/2 |
|
| 12 | + */ |
|
| 13 | + public function testRequireMustBeObject() |
|
| 14 | + { |
|
| 15 | + $object = new \SwaggerGen\SwaggerGen(); |
|
| 16 | + $array = $object->getSwagger(array(' |
|
| 17 | 17 | security api_key apikey X-Api-Authentication header |
| 18 | 18 | require api_key |
| 19 | 19 | api Test |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | response 202 |
| 24 | 24 | ')); |
| 25 | 25 | |
| 26 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 27 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' |
|
| 28 | - . ',"security":[{"api_key":[]}]}}},"securityDefinitions":{"api_key":{"type":"apiKey","name":"X-Api-Authentication","in":"header"}}' |
|
| 29 | - . ',"security":[{"api_key":[]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 30 | - } |
|
| 26 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 27 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' |
|
| 28 | + . ',"security":[{"api_key":[]}]}}},"securityDefinitions":{"api_key":{"type":"apiKey","name":"X-Api-Authentication","in":"header"}}' |
|
| 29 | + . ',"security":[{"api_key":[]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function testRequireAsObjectWithScopes() |
|
| 33 | - { |
|
| 34 | - $object = new \SwaggerGen\SwaggerGen(); |
|
| 35 | - $array = $object->getSwagger(array(' |
|
| 32 | + public function testRequireAsObjectWithScopes() |
|
| 33 | + { |
|
| 34 | + $object = new \SwaggerGen\SwaggerGen(); |
|
| 35 | + $array = $object->getSwagger(array(' |
|
| 36 | 36 | security oauth oauth2 implicit http://www.test |
| 37 | 37 | require oauth user:name |
| 38 | 38 | api Test |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | response 202 |
| 43 | 43 | ')); |
| 44 | 44 | |
| 45 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 46 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' |
|
| 47 | - . ',"security":[{"oauth":["user:name"]}]}}},"securityDefinitions":{"oauth":{"type":"oauth2","flow":"implicit","authorizationUrl":"http:\/\/www.test"}}' |
|
| 48 | - . ',"security":[{"oauth":["user:name"]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 49 | - } |
|
| 45 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
| 46 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' |
|
| 47 | + . ',"security":[{"oauth":["user:name"]}]}}},"securityDefinitions":{"oauth":{"type":"oauth2","flow":"implicit","authorizationUrl":"http:\/\/www.test"}}' |
|
| 48 | + . ',"security":[{"oauth":["user:name"]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -7,57 +7,57 @@ |
||
| 7 | 7 | class OutputTest extends TestCase |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @covers \SwaggerGen\Exception::__construct |
|
| 12 | - * @dataProvider provideAllCases |
|
| 13 | - */ |
|
| 14 | - public function testAllCases($name, $files, $expected) |
|
| 15 | - { |
|
| 16 | - $SwaggerGen = new SwaggerGen('example.com', '/base'); |
|
| 17 | - $actual = $SwaggerGen->getSwagger($files, array(), SwaggerGen::FORMAT_JSON); |
|
| 18 | - $this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Normalizes and pretty-prints json (whitespace mostly) |
|
| 23 | - * |
|
| 24 | - * This is useful to get better diff results when assertions fail. |
|
| 25 | - * |
|
| 26 | - * @param string $json |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - private function normalizeJson($json) |
|
| 30 | - { |
|
| 31 | - return json_encode( |
|
| 32 | - json_decode($json), |
|
| 33 | - PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0 |
|
| 34 | - ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function provideAllCases() |
|
| 38 | - { |
|
| 39 | - $cases = array(); |
|
| 40 | - |
|
| 41 | - foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) { |
|
| 42 | - $path = realpath($dir); |
|
| 43 | - $json = $this->normalizeJson(file_get_contents($path . '/expected.json')); |
|
| 44 | - |
|
| 45 | - $files = array(); |
|
| 46 | - if (file_exists($path . '/source.php')) { |
|
| 47 | - $files[] = $path . '/source.php'; |
|
| 48 | - } |
|
| 49 | - if (file_exists($path . '/source.txt')) { |
|
| 50 | - $files[] = $path . '/source.txt'; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - $cases[] = array( |
|
| 54 | - basename($dir), |
|
| 55 | - $files, |
|
| 56 | - $json |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $cases; |
|
| 61 | - } |
|
| 10 | + /** |
|
| 11 | + * @covers \SwaggerGen\Exception::__construct |
|
| 12 | + * @dataProvider provideAllCases |
|
| 13 | + */ |
|
| 14 | + public function testAllCases($name, $files, $expected) |
|
| 15 | + { |
|
| 16 | + $SwaggerGen = new SwaggerGen('example.com', '/base'); |
|
| 17 | + $actual = $SwaggerGen->getSwagger($files, array(), SwaggerGen::FORMAT_JSON); |
|
| 18 | + $this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Normalizes and pretty-prints json (whitespace mostly) |
|
| 23 | + * |
|
| 24 | + * This is useful to get better diff results when assertions fail. |
|
| 25 | + * |
|
| 26 | + * @param string $json |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + private function normalizeJson($json) |
|
| 30 | + { |
|
| 31 | + return json_encode( |
|
| 32 | + json_decode($json), |
|
| 33 | + PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0 |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function provideAllCases() |
|
| 38 | + { |
|
| 39 | + $cases = array(); |
|
| 40 | + |
|
| 41 | + foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) { |
|
| 42 | + $path = realpath($dir); |
|
| 43 | + $json = $this->normalizeJson(file_get_contents($path . '/expected.json')); |
|
| 44 | + |
|
| 45 | + $files = array(); |
|
| 46 | + if (file_exists($path . '/source.php')) { |
|
| 47 | + $files[] = $path . '/source.php'; |
|
| 48 | + } |
|
| 49 | + if (file_exists($path . '/source.txt')) { |
|
| 50 | + $files[] = $path . '/source.txt'; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + $cases[] = array( |
|
| 54 | + basename($dir), |
|
| 55 | + $files, |
|
| 56 | + $json |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $cases; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
@@ -6,29 +6,29 @@ |
||
| 6 | 6 | class StatementTest extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @covers \SwaggerGen\Statement::__construct |
|
| 11 | - */ |
|
| 12 | - public function testConstructor() |
|
| 13 | - { |
|
| 14 | - $object = new \SwaggerGen\Statement('command', 'some data'); |
|
| 9 | + /** |
|
| 10 | + * @covers \SwaggerGen\Statement::__construct |
|
| 11 | + */ |
|
| 12 | + public function testConstructor() |
|
| 13 | + { |
|
| 14 | + $object = new \SwaggerGen\Statement('command', 'some data'); |
|
| 15 | 15 | |
| 16 | - $this->assertInstanceOf('\SwaggerGen\Statement', $object); |
|
| 17 | - $this->assertSame('command', $object->getCommand()); |
|
| 18 | - $this->assertSame('some data', $object->getData()); |
|
| 19 | - } |
|
| 16 | + $this->assertInstanceOf('\SwaggerGen\Statement', $object); |
|
| 17 | + $this->assertSame('command', $object->getCommand()); |
|
| 18 | + $this->assertSame('some data', $object->getData()); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @covers \SwaggerGen\Statement::__construct |
|
| 23 | - */ |
|
| 24 | - public function testConstructor_File() |
|
| 25 | - { |
|
| 26 | - $object = new \SwaggerGen\Statement('command', 'some data', 'file', 123); |
|
| 27 | - $this->assertInstanceOf('\SwaggerGen\Statement', $object); |
|
| 21 | + /** |
|
| 22 | + * @covers \SwaggerGen\Statement::__construct |
|
| 23 | + */ |
|
| 24 | + public function testConstructor_File() |
|
| 25 | + { |
|
| 26 | + $object = new \SwaggerGen\Statement('command', 'some data', 'file', 123); |
|
| 27 | + $this->assertInstanceOf('\SwaggerGen\Statement', $object); |
|
| 28 | 28 | |
| 29 | - $this->assertSame('command', $object->getCommand()); |
|
| 30 | - $this->assertSame('some data', $object->getData()); |
|
| 31 | - $this->assertSame('file', $object->getFile()); |
|
| 32 | - $this->assertSame(123, $object->getLine()); |
|
| 33 | - } |
|
| 29 | + $this->assertSame('command', $object->getCommand()); |
|
| 30 | + $this->assertSame('some data', $object->getData()); |
|
| 31 | + $this->assertSame('file', $object->getFile()); |
|
| 32 | + $this->assertSame(123, $object->getLine()); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -6,34 +6,34 @@ |
||
| 6 | 6 | class ExceptionTest extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @covers \SwaggerGen\Exception::__construct |
|
| 11 | - */ |
|
| 12 | - public function testConstructor0() |
|
| 13 | - { |
|
| 14 | - $this->expectException('\SwaggerGen\Exception'); |
|
| 15 | - |
|
| 16 | - throw new \SwaggerGen\Exception('', 0); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @covers \SwaggerGen\Exception::__construct |
|
| 21 | - */ |
|
| 22 | - public function testConstructor1() |
|
| 23 | - { |
|
| 24 | - $this->expectException('\SwaggerGen\Exception', 'This is a message'); |
|
| 25 | - |
|
| 26 | - throw new \SwaggerGen\Exception('This is a message', 0); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @covers \SwaggerGen\Exception::__construct |
|
| 31 | - */ |
|
| 32 | - public function testConstructor2() |
|
| 33 | - { |
|
| 34 | - $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234); |
|
| 35 | - |
|
| 36 | - throw new \SwaggerGen\Exception('This is a message', 1234); |
|
| 37 | - } |
|
| 9 | + /** |
|
| 10 | + * @covers \SwaggerGen\Exception::__construct |
|
| 11 | + */ |
|
| 12 | + public function testConstructor0() |
|
| 13 | + { |
|
| 14 | + $this->expectException('\SwaggerGen\Exception'); |
|
| 15 | + |
|
| 16 | + throw new \SwaggerGen\Exception('', 0); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @covers \SwaggerGen\Exception::__construct |
|
| 21 | + */ |
|
| 22 | + public function testConstructor1() |
|
| 23 | + { |
|
| 24 | + $this->expectException('\SwaggerGen\Exception', 'This is a message'); |
|
| 25 | + |
|
| 26 | + throw new \SwaggerGen\Exception('This is a message', 0); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @covers \SwaggerGen\Exception::__construct |
|
| 31 | + */ |
|
| 32 | + public function testConstructor2() |
|
| 33 | + { |
|
| 34 | + $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234); |
|
| 35 | + |
|
| 36 | + throw new \SwaggerGen\Exception('This is a message', 1234); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | } |
@@ -5,94 +5,94 @@ discard block |
||
| 5 | 5 | class SwaggerGenTest extends \PHPUnit\Framework\TestCase |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @covers \SwaggerGen\SwaggerGen::__construct |
|
| 10 | - */ |
|
| 11 | - public function testConstructor_Empty() |
|
| 12 | - { |
|
| 13 | - $object = new SwaggerGen(); |
|
| 14 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 15 | - |
|
| 16 | - $this->expectException('\SwaggerGen\Exception', 'No path defined'); |
|
| 17 | - $object->getSwagger(array()); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 22 | - */ |
|
| 23 | - public function testGetSwagger_ShortestPossible() |
|
| 24 | - { |
|
| 25 | - $object = new SwaggerGen(); |
|
| 26 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 27 | - |
|
| 28 | - $array = $object->getSwagger(array(' |
|
| 8 | + /** |
|
| 9 | + * @covers \SwaggerGen\SwaggerGen::__construct |
|
| 10 | + */ |
|
| 11 | + public function testConstructor_Empty() |
|
| 12 | + { |
|
| 13 | + $object = new SwaggerGen(); |
|
| 14 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 15 | + |
|
| 16 | + $this->expectException('\SwaggerGen\Exception', 'No path defined'); |
|
| 17 | + $object->getSwagger(array()); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 22 | + */ |
|
| 23 | + public function testGetSwagger_ShortestPossible() |
|
| 24 | + { |
|
| 25 | + $object = new SwaggerGen(); |
|
| 26 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 27 | + |
|
| 28 | + $array = $object->getSwagger(array(' |
|
| 29 | 29 | endpoint |
| 30 | 30 | method GET |
| 31 | 31 | response 202 |
| 32 | 32 | ')); |
| 33 | 33 | |
| 34 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0},"paths":{"\/":{"get":{"responses":{"202":{"description":"Accepted"}}}}}}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 35 | - } |
|
| 34 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0},"paths":{"\/":{"get":{"responses":{"202":{"description":"Accepted"}}}}}}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @covers \SwaggerGen\SwaggerGen::__construct |
|
| 39 | + */ |
|
| 40 | + public function testConstructor_BadContext() |
|
| 41 | + { |
|
| 42 | + $object = new SwaggerGen(); |
|
| 43 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 36 | 44 | |
| 37 | - /** |
|
| 38 | - * @covers \SwaggerGen\SwaggerGen::__construct |
|
| 39 | - */ |
|
| 40 | - public function testConstructor_BadContext() |
|
| 41 | - { |
|
| 42 | - $object = new SwaggerGen(); |
|
| 43 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 44 | - |
|
| 45 | - $this->expectException('\SwaggerGen\StatementException', 'Invalid error code: \'\''); |
|
| 46 | - try { |
|
| 47 | - $object->getSwagger(array(' |
|
| 45 | + $this->expectException('\SwaggerGen\StatementException', 'Invalid error code: \'\''); |
|
| 46 | + try { |
|
| 47 | + $object->getSwagger(array(' |
|
| 48 | 48 | endpoint |
| 49 | 49 | method GET |
| 50 | 50 | error |
| 51 | 51 | ')); |
| 52 | - } catch (\SwaggerGen\StatementException $e) { |
|
| 53 | - $this->assertSame("Invalid error code: ''", $e->getMessage()); |
|
| 54 | - $this->assertSame(3, $e->getStatement()->getLine()); |
|
| 55 | - |
|
| 56 | - throw $e; // rethrow to satisfy expected exception check |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 62 | - */ |
|
| 63 | - public function testGetSwagger_JSON() |
|
| 64 | - { |
|
| 65 | - $object = new SwaggerGen(); |
|
| 66 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 67 | - |
|
| 68 | - $output = $object->getSwagger(array(' |
|
| 52 | + } catch (\SwaggerGen\StatementException $e) { |
|
| 53 | + $this->assertSame("Invalid error code: ''", $e->getMessage()); |
|
| 54 | + $this->assertSame(3, $e->getStatement()->getLine()); |
|
| 55 | + |
|
| 56 | + throw $e; // rethrow to satisfy expected exception check |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 62 | + */ |
|
| 63 | + public function testGetSwagger_JSON() |
|
| 64 | + { |
|
| 65 | + $object = new SwaggerGen(); |
|
| 66 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 67 | + |
|
| 68 | + $output = $object->getSwagger(array(' |
|
| 69 | 69 | endpoint |
| 70 | 70 | method GET |
| 71 | 71 | response 202 |
| 72 | 72 | '), array(), SwaggerGen::FORMAT_JSON); |
| 73 | 73 | |
| 74 | - $this->assertSame('{"swagger":"2.0","info":{"title":"undefined","version":"0"},"paths":{"\/":{"get":{"responses":{"202":{"description":"Accepted"}}}}}}', $output); |
|
| 75 | - } |
|
| 74 | + $this->assertSame('{"swagger":"2.0","info":{"title":"undefined","version":"0"},"paths":{"\/":{"get":{"responses":{"202":{"description":"Accepted"}}}}}}', $output); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 79 | - */ |
|
| 80 | - public function testGetSwagger_JSON_Pretty() |
|
| 81 | - { |
|
| 82 | - if (!defined('JSON_PRETTY_PRINT')) { |
|
| 83 | - $this->markTestSkipped('JSON_PRETTY_PRINT available since PHP 5.4.0'); |
|
| 84 | - } |
|
| 77 | + /** |
|
| 78 | + * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 79 | + */ |
|
| 80 | + public function testGetSwagger_JSON_Pretty() |
|
| 81 | + { |
|
| 82 | + if (!defined('JSON_PRETTY_PRINT')) { |
|
| 83 | + $this->markTestSkipped('JSON_PRETTY_PRINT available since PHP 5.4.0'); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $object = new SwaggerGen(); |
|
| 87 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 86 | + $object = new SwaggerGen(); |
|
| 87 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 88 | 88 | |
| 89 | - $output = $object->getSwagger(array(' |
|
| 89 | + $output = $object->getSwagger(array(' |
|
| 90 | 90 | endpoint |
| 91 | 91 | method GET |
| 92 | 92 | response 202 |
| 93 | 93 | '), array(), SwaggerGen::FORMAT_JSON_PRETTY); |
| 94 | 94 | |
| 95 | - $this->assertStringEqualsStringIgnoringLineEndings(<<<JSON |
|
| 95 | + $this->assertStringEqualsStringIgnoringLineEndings(<<<JSON |
|
| 96 | 96 | { |
| 97 | 97 | "swagger": "2.0", |
| 98 | 98 | "info": { |
@@ -112,26 +112,26 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | JSON, $output); |
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 119 | - */ |
|
| 120 | - public function testGetSwagger_YAML() |
|
| 121 | - { |
|
| 122 | - if (!extension_loaded('yaml')) { |
|
| 123 | - $this->markTestSkipped('The YAML extension is not available.'); |
|
| 124 | - } else { |
|
| 125 | - $object = new SwaggerGen(); |
|
| 126 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 127 | - |
|
| 128 | - $output = $object->getSwagger(array(' |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @covers \SwaggerGen\SwaggerGen::getSwagger |
|
| 119 | + */ |
|
| 120 | + public function testGetSwagger_YAML() |
|
| 121 | + { |
|
| 122 | + if (!extension_loaded('yaml')) { |
|
| 123 | + $this->markTestSkipped('The YAML extension is not available.'); |
|
| 124 | + } else { |
|
| 125 | + $object = new SwaggerGen(); |
|
| 126 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 127 | + |
|
| 128 | + $output = $object->getSwagger(array(' |
|
| 129 | 129 | endpoint |
| 130 | 130 | method GET |
| 131 | 131 | response 202 |
| 132 | 132 | '), array(), SwaggerGen::FORMAT_YAML); |
| 133 | 133 | |
| 134 | - $this->assertSame('--- |
|
| 134 | + $this->assertSame('--- |
|
| 135 | 135 | swagger: "2.0" |
| 136 | 136 | info: |
| 137 | 137 | title: undefined |
@@ -144,18 +144,18 @@ discard block |
||
| 144 | 144 | description: Accepted |
| 145 | 145 | ... |
| 146 | 146 | ', $output); |
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @covers \SwaggerGen\SwaggerGen::define |
|
| 152 | - */ |
|
| 153 | - public function testDefine_NotDefined() |
|
| 154 | - { |
|
| 155 | - $object = new SwaggerGen(); |
|
| 156 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 157 | - |
|
| 158 | - $array = $object->getSwagger(array(' |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @covers \SwaggerGen\SwaggerGen::define |
|
| 152 | + */ |
|
| 153 | + public function testDefine_NotDefined() |
|
| 154 | + { |
|
| 155 | + $object = new SwaggerGen(); |
|
| 156 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 157 | + |
|
| 158 | + $array = $object->getSwagger(array(' |
|
| 159 | 159 | endpoint |
| 160 | 160 | method GET |
| 161 | 161 | if d |
@@ -164,20 +164,20 @@ discard block |
||
| 164 | 164 | response 204 |
| 165 | 165 | endif |
| 166 | 166 | ')); |
| 167 | - $this->assertArrayNotHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 168 | - $this->assertArrayHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @covers \SwaggerGen\SwaggerGen::define |
|
| 173 | - */ |
|
| 174 | - public function testDefine_Defined() |
|
| 175 | - { |
|
| 176 | - $object = new SwaggerGen(); |
|
| 177 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 178 | - |
|
| 179 | - $object->define('d'); |
|
| 180 | - $array = $object->getSwagger(array(' |
|
| 167 | + $this->assertArrayNotHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 168 | + $this->assertArrayHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @covers \SwaggerGen\SwaggerGen::define |
|
| 173 | + */ |
|
| 174 | + public function testDefine_Defined() |
|
| 175 | + { |
|
| 176 | + $object = new SwaggerGen(); |
|
| 177 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 178 | + |
|
| 179 | + $object->define('d'); |
|
| 180 | + $array = $object->getSwagger(array(' |
|
| 181 | 181 | endpoint |
| 182 | 182 | method GET |
| 183 | 183 | if d |
@@ -186,21 +186,21 @@ discard block |
||
| 186 | 186 | response 204 |
| 187 | 187 | endif |
| 188 | 188 | ')); |
| 189 | - $this->assertArrayHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 190 | - $this->assertArrayNotHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @covers \SwaggerGen\SwaggerGen::define |
|
| 195 | - */ |
|
| 196 | - public function testUndefine() |
|
| 197 | - { |
|
| 198 | - $object = new SwaggerGen(); |
|
| 199 | - $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 200 | - |
|
| 201 | - $object->define('d'); |
|
| 202 | - $object->undefine('d'); |
|
| 203 | - $array = $object->getSwagger(array(' |
|
| 189 | + $this->assertArrayHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 190 | + $this->assertArrayNotHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @covers \SwaggerGen\SwaggerGen::define |
|
| 195 | + */ |
|
| 196 | + public function testUndefine() |
|
| 197 | + { |
|
| 198 | + $object = new SwaggerGen(); |
|
| 199 | + $this->assertInstanceof('\SwaggerGen\SwaggerGen', $object); |
|
| 200 | + |
|
| 201 | + $object->define('d'); |
|
| 202 | + $object->undefine('d'); |
|
| 203 | + $array = $object->getSwagger(array(' |
|
| 204 | 204 | endpoint |
| 205 | 205 | method GET |
| 206 | 206 | if d |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | response 204 |
| 210 | 210 | endif |
| 211 | 211 | ')); |
| 212 | - $this->assertArrayNotHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 213 | - $this->assertArrayHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 214 | - } |
|
| 212 | + $this->assertArrayNotHasKey(202, $array['paths']['/']['get']['responses']); |
|
| 213 | + $this->assertArrayHasKey(204, $array['paths']['/']['get']['responses']); |
|
| 214 | + } |
|
| 215 | 215 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | -JSON, $output); |
|
| 114 | +json, $output); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -13,5 +13,5 @@ |
||
| 13 | 13 | interface IParser |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - public function parse($file, array $dirs = []); |
|
| 16 | + public function parse($file, array $dirs = []); |
|
| 17 | 17 | } |
@@ -16,132 +16,132 @@ |
||
| 16 | 16 | class SecurityScheme extends AbstractObject |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * 'basic', 'apikey' or 'oauth2' |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - private $type; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - private $description; |
|
| 29 | - private $name; |
|
| 30 | - private $in; |
|
| 31 | - private $flow; |
|
| 32 | - private $authorizationUrl; |
|
| 33 | - private $tokenUrl; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Map of scope-name => description |
|
| 37 | - * @var [] |
|
| 38 | - */ |
|
| 39 | - private $scopes = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Create a new SecurityScheme object |
|
| 43 | - * @param AbstractObject $parent |
|
| 44 | - * @param string $type |
|
| 45 | - * @param string $data |
|
| 46 | - * @throws Exception |
|
| 47 | - */ |
|
| 48 | - public function __construct(AbstractObject $parent, $type, $data = null) |
|
| 49 | - { |
|
| 50 | - parent::__construct($parent); |
|
| 51 | - |
|
| 52 | - if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) { |
|
| 53 | - throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'"); |
|
| 54 | - } |
|
| 55 | - $this->type = strtolower($type); |
|
| 56 | - |
|
| 57 | - switch ($this->type) { |
|
| 58 | - case 'basic': |
|
| 59 | - $this->description = $data; |
|
| 60 | - break; |
|
| 61 | - |
|
| 62 | - case 'apikey': |
|
| 63 | - $this->name = self::wordShift($data); |
|
| 64 | - |
|
| 65 | - $in = strtolower(self::wordShift($data)); |
|
| 66 | - if (!in_array($in, array('query', 'header'))) { |
|
| 67 | - throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'"); |
|
| 68 | - } |
|
| 69 | - $this->in = $in; |
|
| 70 | - |
|
| 71 | - $this->description = $data; |
|
| 72 | - break; |
|
| 73 | - |
|
| 74 | - case 'oauth2': |
|
| 75 | - $flow = strtolower(self::wordShift($data)); |
|
| 76 | - if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) { |
|
| 77 | - throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'"); |
|
| 78 | - } |
|
| 79 | - $this->flow = $flow; |
|
| 80 | - |
|
| 81 | - if (in_array($flow, array('implicit', 'accesscode'))) { |
|
| 82 | - $authUrl = self::wordShift($data); |
|
| 83 | - if (!filter_var($authUrl, FILTER_VALIDATE_URL)) { |
|
| 84 | - throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'"); |
|
| 85 | - } |
|
| 86 | - $this->authorizationUrl = $authUrl; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if (in_array($flow, array('password', 'application', 'accesscode'))) { |
|
| 90 | - $tokenUrl = self::wordShift($data); |
|
| 91 | - if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) { |
|
| 92 | - throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'"); |
|
| 93 | - } |
|
| 94 | - $this->tokenUrl = $tokenUrl; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $this->description = $data; |
|
| 98 | - break; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $command |
|
| 104 | - * @param string $data |
|
| 105 | - * @return AbstractObject|boolean |
|
| 106 | - * @throws Exception |
|
| 107 | - */ |
|
| 108 | - public function handleCommand($command, $data = null) |
|
| 109 | - { |
|
| 110 | - switch (strtolower($command)) { |
|
| 111 | - case 'description': |
|
| 112 | - $this->description = $data; |
|
| 113 | - return $this; |
|
| 114 | - |
|
| 115 | - case 'scope': |
|
| 116 | - if ($this->type !== 'oauth2') { |
|
| 117 | - throw new Exception("Cannot set scope on type '{$this->type}'"); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $name = self::wordShift($data); |
|
| 121 | - $this->scopes[$name] = $data; |
|
| 122 | - return $this; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return parent::handleCommand($command, $data); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function toArray(): array |
|
| 129 | - { |
|
| 130 | - return self::arrayFilterNull(array_merge(array( |
|
| 131 | - 'type' => $this->type === 'apikey' ? 'apiKey' : $this->type, |
|
| 132 | - 'description' => empty($this->description) ? null : $this->description, |
|
| 133 | - 'name' => $this->name, |
|
| 134 | - 'in' => $this->in, |
|
| 135 | - 'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow, |
|
| 136 | - 'authorizationUrl' => $this->authorizationUrl, |
|
| 137 | - 'tokenUrl' => $this->tokenUrl, |
|
| 138 | - 'scopes' => $this->scopes, |
|
| 139 | - ), parent::toArray())); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function __toString() |
|
| 143 | - { |
|
| 144 | - return __CLASS__ . ' ' . $this->type; |
|
| 145 | - } |
|
| 19 | + /** |
|
| 20 | + * 'basic', 'apikey' or 'oauth2' |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + private $type; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + private $description; |
|
| 29 | + private $name; |
|
| 30 | + private $in; |
|
| 31 | + private $flow; |
|
| 32 | + private $authorizationUrl; |
|
| 33 | + private $tokenUrl; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Map of scope-name => description |
|
| 37 | + * @var [] |
|
| 38 | + */ |
|
| 39 | + private $scopes = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Create a new SecurityScheme object |
|
| 43 | + * @param AbstractObject $parent |
|
| 44 | + * @param string $type |
|
| 45 | + * @param string $data |
|
| 46 | + * @throws Exception |
|
| 47 | + */ |
|
| 48 | + public function __construct(AbstractObject $parent, $type, $data = null) |
|
| 49 | + { |
|
| 50 | + parent::__construct($parent); |
|
| 51 | + |
|
| 52 | + if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) { |
|
| 53 | + throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'"); |
|
| 54 | + } |
|
| 55 | + $this->type = strtolower($type); |
|
| 56 | + |
|
| 57 | + switch ($this->type) { |
|
| 58 | + case 'basic': |
|
| 59 | + $this->description = $data; |
|
| 60 | + break; |
|
| 61 | + |
|
| 62 | + case 'apikey': |
|
| 63 | + $this->name = self::wordShift($data); |
|
| 64 | + |
|
| 65 | + $in = strtolower(self::wordShift($data)); |
|
| 66 | + if (!in_array($in, array('query', 'header'))) { |
|
| 67 | + throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'"); |
|
| 68 | + } |
|
| 69 | + $this->in = $in; |
|
| 70 | + |
|
| 71 | + $this->description = $data; |
|
| 72 | + break; |
|
| 73 | + |
|
| 74 | + case 'oauth2': |
|
| 75 | + $flow = strtolower(self::wordShift($data)); |
|
| 76 | + if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) { |
|
| 77 | + throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'"); |
|
| 78 | + } |
|
| 79 | + $this->flow = $flow; |
|
| 80 | + |
|
| 81 | + if (in_array($flow, array('implicit', 'accesscode'))) { |
|
| 82 | + $authUrl = self::wordShift($data); |
|
| 83 | + if (!filter_var($authUrl, FILTER_VALIDATE_URL)) { |
|
| 84 | + throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'"); |
|
| 85 | + } |
|
| 86 | + $this->authorizationUrl = $authUrl; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if (in_array($flow, array('password', 'application', 'accesscode'))) { |
|
| 90 | + $tokenUrl = self::wordShift($data); |
|
| 91 | + if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) { |
|
| 92 | + throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'"); |
|
| 93 | + } |
|
| 94 | + $this->tokenUrl = $tokenUrl; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $this->description = $data; |
|
| 98 | + break; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $command |
|
| 104 | + * @param string $data |
|
| 105 | + * @return AbstractObject|boolean |
|
| 106 | + * @throws Exception |
|
| 107 | + */ |
|
| 108 | + public function handleCommand($command, $data = null) |
|
| 109 | + { |
|
| 110 | + switch (strtolower($command)) { |
|
| 111 | + case 'description': |
|
| 112 | + $this->description = $data; |
|
| 113 | + return $this; |
|
| 114 | + |
|
| 115 | + case 'scope': |
|
| 116 | + if ($this->type !== 'oauth2') { |
|
| 117 | + throw new Exception("Cannot set scope on type '{$this->type}'"); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $name = self::wordShift($data); |
|
| 121 | + $this->scopes[$name] = $data; |
|
| 122 | + return $this; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return parent::handleCommand($command, $data); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function toArray(): array |
|
| 129 | + { |
|
| 130 | + return self::arrayFilterNull(array_merge(array( |
|
| 131 | + 'type' => $this->type === 'apikey' ? 'apiKey' : $this->type, |
|
| 132 | + 'description' => empty($this->description) ? null : $this->description, |
|
| 133 | + 'name' => $this->name, |
|
| 134 | + 'in' => $this->in, |
|
| 135 | + 'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow, |
|
| 136 | + 'authorizationUrl' => $this->authorizationUrl, |
|
| 137 | + 'tokenUrl' => $this->tokenUrl, |
|
| 138 | + 'scopes' => $this->scopes, |
|
| 139 | + ), parent::toArray())); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function __toString() |
|
| 143 | + { |
|
| 144 | + return __CLASS__ . ' ' . $this->type; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | } |