├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── SwaggerGen ├── Exception.php ├── Parser │ ├── AbstractPreprocessor.php │ ├── IParser.php │ ├── Php │ │ ├── Entity │ │ │ ├── AbstractEntity.php │ │ │ ├── ParserClass.php │ │ │ └── ParserFunction.php │ │ ├── Parser.php │ │ └── Preprocessor.php │ └── Text │ │ ├── Parser.php │ │ └── Preprocessor.php ├── Statement.php ├── StatementException.php ├── Swagger │ ├── AbstractDocumentableObject.php │ ├── AbstractObject.php │ ├── BodyParameter.php │ ├── Contact.php │ ├── Error.php │ ├── ExternalDocumentation.php │ ├── Header.php │ ├── IDefinition.php │ ├── IParameter.php │ ├── Info.php │ ├── License.php │ ├── Operation.php │ ├── Parameter.php │ ├── ParameterReference.php │ ├── Path.php │ ├── Response.php │ ├── ResponseReference.php │ ├── Schema.php │ ├── SecurityScheme.php │ ├── Swagger.php │ ├── Tag.php │ └── Type │ │ ├── AbstractRegexType.php │ │ ├── AbstractType.php │ │ ├── AllOfType.php │ │ ├── ArrayType.php │ │ ├── BooleanType.php │ │ ├── Custom │ │ ├── EmailType.php │ │ ├── ICustomType.php │ │ ├── Ipv4Type.php │ │ ├── Ipv6Type.php │ │ └── MacType.php │ │ ├── DateType.php │ │ ├── FileType.php │ │ ├── IntegerType.php │ │ ├── NumberType.php │ │ ├── ObjectType.php │ │ ├── Property.php │ │ ├── ReferenceObjectType.php │ │ ├── StringType.php │ │ └── StringUuidType.php ├── SwaggerGen.php └── TypeRegistry.php ├── TODO.md ├── composer.json ├── example ├── api │ ├── .htaccess │ ├── Example.class.php │ ├── autoloader.php │ ├── example.json │ ├── example.php │ └── swagger.php └── docs │ ├── css │ ├── print.css │ ├── reset.css │ ├── screen.css │ ├── style.css │ └── typography.css │ ├── fonts │ ├── DroidSans-Bold.ttf │ └── DroidSans.ttf │ ├── images │ ├── explorer_icons.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon.ico │ ├── logo_small.png │ ├── pet_store_api.png │ ├── throbber.gif │ └── wordnik_api.png │ ├── index.html │ ├── lang │ ├── en.js │ ├── es.js │ ├── fr.js │ ├── it.js │ ├── ja.js │ ├── pt.js │ ├── ru.js │ ├── tr.js │ ├── translator.js │ └── zh-cn.js │ ├── lib │ ├── backbone-min.js │ ├── handlebars-2.0.0.js │ ├── highlight.7.3.pack.js │ ├── jquery-1.8.0.min.js │ ├── jquery.ba-bbq.min.js │ ├── jquery.slideto.min.js │ ├── jquery.wiggle.min.js │ ├── marked.js │ ├── swagger-oauth.js │ ├── underscore-min.js │ └── underscore-min.map │ ├── o2c.html │ ├── swagger-ui.js │ └── swagger-ui.min.js ├── index.html ├── phpunit.xml └── tests ├── Base ├── PHPUnit5.php ├── PHPUnit6.php └── PHPUnit7.php ├── ExceptionTest.php ├── Parser ├── Php │ ├── ParserTest.php │ ├── ParserTest │ │ ├── testParse_AfterClass.php │ │ ├── testParse_Autoload.php │ │ ├── testParse_Autoload_Other.php │ │ ├── testParse_CommentsTypes.php │ │ ├── testParse_CurlyBraceFunction.php │ │ ├── testParse_InClass.php │ │ ├── testParse_InMethod.php │ │ ├── testParse_LineContinuation.php │ │ ├── testParse_MethodNonDoc.php │ │ ├── testParse_Minimal.php │ │ ├── testParse_NoMethods.php │ │ ├── testParse_Prefix.php │ │ ├── testParse_PropertyOptional.php │ │ ├── testParse_PropertyReadOnly.php │ │ ├── testParse_SeeClassMethod.php │ │ ├── testParse_SeeFunction.php │ │ ├── testParse_SeeInheritedObjectMethod.php │ │ ├── testParse_SeeInheritedThisMethod.php │ │ ├── testParse_SeeObjectMethod.php │ │ ├── testParse_SeeSelfMethod.php │ │ ├── testParse_SeeThisMethod.php │ │ ├── testParse_StaticMethod.php │ │ ├── testParse_WithMethod.php │ │ └── testParse_XTag.php │ ├── PreprocessorTest.php │ └── PreprocessorTest │ │ └── testPreprocessFile.php └── Text │ ├── ParserTest.php │ ├── ParserTest │ ├── testParse.txt │ └── testParse_Dirs.txt │ └── PreprocessorTest.php ├── StatementTest.php ├── Swagger ├── AbstractDocumentableObjectTest.php ├── AbstractObjectTest.php ├── BodyParameterTest.php ├── ContactTest.php ├── ErrorTest.php ├── ExternalDocumentationTest.php ├── HeaderTest.php ├── InfoTest.php ├── LicenseTest.php ├── OperationTest.php ├── ParameterTest.php ├── PathTest.php ├── ResponseTest.php ├── SchemaTest.php ├── SecuritySchemeTest.php ├── SwaggerTest.php ├── TagTest.php └── Type │ ├── AbstractTypeTest.php │ ├── ArrayTypeTest.php │ ├── BooleanTypeTest.php │ ├── Custom │ ├── EmailTypeTest.php │ ├── Ipv4TypeTest.php │ ├── Ipv6TypeTest.php │ └── MacTypeTest.php │ ├── DateTypeTest.php │ ├── FileTypeTest.php │ ├── IntegerTypeTest.php │ ├── NumberTypeTest.php │ ├── ObjectTypeTest.php │ ├── PropertyTest.php │ ├── ReferenceObjectTypeTest.php │ ├── StringTypeTest.php │ └── StringUuidTypeTest.php ├── SwaggerGenTest.php ├── bootstrap.php ├── issues ├── Issue0002Test.php ├── Issue0005Test.php ├── Issue0012Test.php └── Issue0015Test.php └── output ├── OutputTest.php ├── additionalProperties ├── expected.json └── source.txt ├── allOf in array ├── expected.json └── source.txt ├── allOf in model top level ├── expected.json └── source.txt ├── allOf in property ├── expected.json └── source.txt ├── allOf in response ├── expected.json └── source.txt ├── docblock comment in method ├── expected.json └── source.php ├── global parameter ├── expected.json └── source.php ├── global response ├── expected.json └── source.php ├── preprocessor replace ├── expected.json └── source.php ├── readonly ref property ├── expected.json └── source.txt ├── reference array of models in model ├── expected.json └── source.txt ├── reference model in array of models ├── expected.json └── source.txt ├── reference model in model infinite ├── expected.json └── source.txt ├── reference model in model ├── expected.json └── source.txt ├── unbounded range ├── expected.json └── source.txt └── uuid model overwrite ├── expected.json └── source.php /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject/ 2 | /debug/ 3 | /vendor/ 4 | /composer.lock 5 | /.phpunit.result.cache 6 | /.idea 7 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | filter: 2 | excluded_paths: 3 | - doc/* 4 | - vendor/* 5 | - example/* 6 | - tests/Parser/Php/ParserTest/* 7 | - tests/Parser/Php/PreprocessorTest/* 8 | checks: 9 | php: 10 | duplication: false -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | dist: trusty 3 | php: 4 | - 7.1 5 | - 7.2 6 | - hhvm 7 | matrix: 8 | allow_failures: 9 | - php: hhvm 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## 2.3.22 - 2024-04-11 8 | ### Fixed 9 | - Fixed example case. 10 | - PHP code quality improvements. 11 | 12 | ## 2.3.21 - 2021-01-07 13 | ### Fixed 14 | - PR #47; Fix array access PHP8 by daniol. 15 | - Minor fixes for php-unit. 16 | 17 | ## 2.3.20 - 2019-12-02 18 | ### Fixed 19 | - PR #45 fixes #44; PHP Parser fails when parsing @rest\property! by SteenSchutt 20 | - PR #42; `example` command: support for input containing special chars by sserbin. 21 | 22 | ## 2.3.19 - 2019-01-12 23 | ### Changed 24 | - PR #41 Fix for JSON example command with multiple properties by sserbin. 25 | 26 | ## 2.3.18 - 2017-12-06 27 | ### Changed 28 | - PR #32 Separated parsing from compiling parts, by weirdan. 29 | 30 | ## 2.3.17 - 2017-11-28 31 | ### Added 32 | - Support for `additionalProperties` (#31) added by weirdan. 33 | 34 | ## 2.3.16 - 2017-11-07 35 | ### Added 36 | - Support for `allOf` added by weirdan. 37 | ### Fixed 38 | - Suppress `exclusive*` when no min/max specified, by weirdan. 39 | - Significant refactoring of type creating by weirdan. 40 | 41 | ## 2.3.15 - 2017-10-29 42 | ### Added 43 | - Added `example` to Response and parameters to fix #22 submitted by oozolii. 44 | 45 | ## 2.3.14 - 2017-10-22 46 | ### Added 47 | - Short-hand JSON like notation for objects (`{...}`) and arrays (`[...]`). 48 | 49 | ## 2.3.13 - 2016-07-29 50 | ### Fixed 51 | - Passthrough of commands to most recent property of object (#15) submitted by 52 | weirdan. 53 | - Allow `HEAD` and `OPTIONS` methods (#16) submitted by weirdan. 54 | 55 | ## 2.3.12 - 2016-07-22 56 | ### Fixed 57 | - Read-only definitions fix (#14) by petejohnson84. 58 | - Removed hhvm Travis.ci tests due to bug on Travis.ci. 59 | 60 | ## 2.3.11 - 2017-06-14 61 | ### Fixed 62 | - Read-only properties fix (#13) by petejohnson84. 63 | - Fixed issue with preprocessor statements being interpreted as plain text. 64 | 65 | ## 2.3.10 - 2016-12-17 66 | ### Fixed 67 | - Correctly parse parenthesis in object properties. Fixes issue #12 by 68 | ObliviousHarmony. 69 | 70 | ## 2.3.9 - 2016-11-17 71 | ### Fixed 72 | - Supply custom `format` for type `uuid`. 73 | - Improved some `string` type exception messages. 74 | 75 | ## 2.3.8 - 2016-11-16 76 | ### Added 77 | - New string-based builtin type `uuid`. 78 | - Allow model definitions to overwrite builtin types. 79 | 80 | ## 2.3.7 - 2016-10-23 81 | ### Fixed 82 | - Supports referencing a single `definition` (a.k.a. `model`) from within 83 | another `definition`. Fixes issue #10 by tecnom1k3. 84 | 85 | ## 2.3.6 - 2016-10-15 86 | ### Added 87 | - Parameter commands (i.e. `path`, `query?` and `body`) in `Swagger` context to 88 | create global parameter definitions. 89 | - `parameter` command (and alias `param`) in `Operation` context to create 90 | references to global parameter definitions. 91 | - Alternative signature for `response` for references to Response Definitions. 92 | - `description` command in `Schema` context to set/change the description. 93 | - `title` command in `Schema` context to set/change the title. 94 | - `StatementException` added. Can be thrown during the generator phase, after 95 | parsing the input. Contains a `getStatement()` method which returns a 96 | `Statement` object with which you can access the public `getFile()` (if 97 | applicable) and `getLine()` methods. 98 | 99 | ### Changed 100 | - Removed the `type` argument from the `definition` command in the Swagger 101 | context; it's always a Schema. Note that this is a backwards incompatible 102 | change! 103 | 104 | ### Deprecated 105 | - Removed the `define` command in the `Swagger` context as it was in conflict 106 | with the `define` command in the preprocessor. Replace use of this command with 107 | the previous available aliasses `definition` or `model`. Since the `define` 108 | command was blocked by the preprocessor context, this deprecation shouldn't 109 | affect users. 110 | - Merged the `\SwaggerGen\Parser\Php\Statement` class (and tests) into the 111 | `\SwaggerGen\Statement` class for universal file/line support. This shouldn't 112 | affect average users. 113 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Martijn van der Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SwaggerGen/Exception.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class Exception extends \Exception 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/AbstractPreprocessor.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2015 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | abstract class AbstractPreprocessor 14 | { 15 | 16 | private $defines = array(); 17 | private $stack = array(); 18 | 19 | public function __construct() 20 | { 21 | $this->resetDefines(); 22 | } 23 | 24 | public function resetDefines() 25 | { 26 | $this->defines = array(); 27 | } 28 | 29 | public function addDefines(array $defines) 30 | { 31 | $this->defines = array_merge($this->defines, $defines); 32 | } 33 | 34 | public function define($name, $value = 1) 35 | { 36 | $this->defines[$name] = $value; 37 | } 38 | 39 | public function undefine($name) 40 | { 41 | unset($this->defines[$name]); 42 | } 43 | 44 | protected function getState() 45 | { 46 | return empty($this->stack) || end($this->stack); 47 | } 48 | 49 | /** 50 | * Get the first word from a string and remove it from the string. 51 | * 52 | * @param string $data 53 | * @return boolean|string 54 | */ 55 | private static function wordShift(&$data) 56 | { 57 | if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) { 58 | $data = $matches[2]; 59 | return $matches[1]; 60 | } 61 | return false; 62 | } 63 | 64 | protected function handle($command, $expression) 65 | { 66 | switch (strtolower($command)) { 67 | case 'if': 68 | $name = self::wordShift($expression); 69 | $state = $this->getState(); 70 | if (empty($expression)) { 71 | $this->stack[] = $state && !empty($this->defines[$name]); 72 | } else { 73 | $this->stack[] = $state && isset($this->defines[$name]) && $this->defines[$name] == $expression; 74 | } 75 | break; 76 | 77 | case 'ifdef': 78 | $this->stack[] = $this->getState() && isset($this->defines[$expression]); 79 | break; 80 | 81 | case 'ifndef': 82 | $this->stack[] = $this->getState() && !isset($this->defines[$expression]); 83 | break; 84 | 85 | case 'else': 86 | $state = $this->getState(); 87 | array_pop($this->stack); 88 | $this->stack[] = !$state; 89 | break; 90 | 91 | case 'elif': 92 | $name = self::wordShift($expression); 93 | $state = $this->getState(); 94 | array_pop($this->stack); 95 | if (empty($expression)) { 96 | $this->stack[] = !$state && !empty($this->defines[$name]); 97 | } else { 98 | $this->stack[] = !$state && isset($this->defines[$name]) && $this->defines[$name] == $expression; 99 | } 100 | break; 101 | 102 | case 'define': 103 | $name = self::wordShift($expression); 104 | $this->defines[$name] = $expression; 105 | break; 106 | 107 | case 'undef': 108 | unset($this->defines[$expression]); 109 | break; 110 | 111 | case 'endif': 112 | array_pop($this->stack); 113 | break; 114 | 115 | default: 116 | return false; 117 | } 118 | 119 | return true; 120 | } 121 | 122 | public function preprocess($content) 123 | { 124 | $this->stack = array(); 125 | 126 | return $this->parseContent($content); 127 | } 128 | 129 | public function preprocessFile($filename) 130 | { 131 | return $this->preprocess(file_get_contents($filename)); 132 | } 133 | 134 | abstract protected function parseContent($content); 135 | } 136 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/IParser.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2015 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | interface IParser 14 | { 15 | 16 | public function parse($file, array $dirs = array()); 17 | } 18 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/Php/Entity/AbstractEntity.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2015 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class AbstractEntity 16 | { 17 | 18 | /** 19 | * @var Statement[] 20 | */ 21 | public $Statements = array(); 22 | 23 | /** 24 | * Returns true if a statement with the specified command exists. 25 | * @param string $command 26 | * @return boolean 27 | */ 28 | public function hasCommand($command) 29 | { 30 | foreach ($this->Statements as $Statement) { 31 | if ($Statement->getCommand() === $command) { 32 | return true; 33 | } 34 | } 35 | 36 | return false; 37 | } 38 | 39 | public function getStatements() 40 | { 41 | return $this->Statements; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/Php/Entity/ParserFunction.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright 2014-2015 Martijn van der Lee 14 | * @license https://opensource.org/licenses/MIT MIT 15 | */ 16 | class ParserFunction extends AbstractEntity 17 | { 18 | 19 | public $name = null; 20 | private $lastStatements = null; 21 | 22 | public function __construct(Parser $Parser, &$tokens, $Statements) 23 | { 24 | if ($Statements) { 25 | $this->Statements = array_merge($this->Statements, $Statements); 26 | } 27 | 28 | $depth = 0; 29 | 30 | $token = current($tokens); 31 | while ($token) { 32 | switch ($token[0]) { 33 | case T_STRING: 34 | if (empty($this->name)) { 35 | $this->name = $token[1]; 36 | } 37 | break; 38 | 39 | case '{': 40 | case T_CURLY_OPEN: 41 | case T_DOLLAR_OPEN_CURLY_BRACES: 42 | case T_STRING_VARNAME: 43 | ++$depth; 44 | break; 45 | 46 | case '}': 47 | --$depth; 48 | if ($depth == 0) { 49 | if ($this->lastStatements) { 50 | $this->Statements = array_merge($this->Statements, $this->lastStatements); 51 | $this->lastStatements = null; 52 | } 53 | return; 54 | } 55 | break; 56 | 57 | case T_COMMENT: 58 | if ($this->lastStatements) { 59 | $this->Statements = array_merge($this->Statements, $this->lastStatements); 60 | $this->lastStatements = null; 61 | } 62 | $Statements = $Parser->tokenToStatements($token); 63 | $Parser->queueClassesFromComments($Statements); 64 | $this->Statements = array_merge($this->Statements, $Statements); 65 | break; 66 | 67 | case T_DOC_COMMENT: 68 | if ($this->lastStatements) { 69 | $this->Statements = array_merge($this->Statements, $this->lastStatements); 70 | } 71 | $Statements = $Parser->tokenToStatements($token); 72 | $Parser->queueClassesFromComments($Statements); 73 | $this->lastStatements = $Statements; 74 | break; 75 | } 76 | 77 | $token = next($tokens); 78 | } 79 | 80 | if ($this->lastStatements) { 81 | $this->Statements = array_merge($this->Statements, $this->lastStatements); 82 | $this->lastStatements = null; 83 | } 84 | } 85 | 86 | public function getStatements() 87 | { 88 | // inherit 89 | return $this->Statements; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/Php/Preprocessor.php: -------------------------------------------------------------------------------- 1 | 15 | * @copyright 2014-2017 Martijn van der Lee 16 | * @license https://opensource.org/licenses/MIT MIT 17 | */ 18 | class Preprocessor extends AbstractPreprocessor 19 | { 20 | 21 | private $prefix = 'rest'; 22 | 23 | public function __construct($prefix = null) 24 | { 25 | parent::__construct(); 26 | if (!empty($prefix)) { 27 | $this->prefix = $prefix; 28 | } 29 | } 30 | 31 | public function getPrefix() 32 | { 33 | return $this->prefix; 34 | } 35 | 36 | public function setPrefix($prefix) 37 | { 38 | $this->prefix = $prefix; 39 | } 40 | 41 | protected function parseContent($content) 42 | { 43 | $pattern = '/@' . preg_quote($this->getPrefix()) . '\\\\([a-z]+)\\s*(.*)$/'; 44 | 45 | $output_file = ''; 46 | 47 | foreach (token_get_all($content) as $token) { 48 | $output = ''; 49 | 50 | if (is_array($token)) { 51 | switch ($token[0]) { 52 | case T_DOC_COMMENT: 53 | case T_COMMENT: 54 | foreach (preg_split('/(\\R)/m', $token[1], -1, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) { 55 | if ($index % 2) { 56 | $output .= $line; 57 | } else { 58 | $match = array(); 59 | if (preg_match($pattern, $line, $match) === 1) { 60 | if (!$this->handle($match[1], $match[2]) && $this->getState()) { 61 | $output .= $line; 62 | } else { 63 | $output .= str_replace('@' . $this->getPrefix() . '\\', '@!' . $this->getPrefix() . '\\', $line); 64 | } 65 | } else { 66 | $output .= $line; 67 | } 68 | } 69 | } 70 | break; 71 | 72 | default: 73 | $output .= $token[1]; 74 | } 75 | } else { 76 | $output .= $token; 77 | } 78 | 79 | if ($this->getState()) { 80 | $output_file .= $output; 81 | } else { 82 | $output_file .= '/* ' . $output . ' */'; 83 | } 84 | } 85 | 86 | return $output_file; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/Text/Parser.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2016 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class Parser implements IParser 18 | { 19 | 20 | /** 21 | * List of directories to scan for class files referenced in the parsed 22 | * command statements. 23 | * 24 | * @var string[] 25 | */ 26 | protected $common_dirs = []; 27 | 28 | /** 29 | * @var AbstractPreprocessor 30 | */ 31 | private $Preprocessor; 32 | 33 | /** 34 | * Create a new text parser and set directories to scan for referenced 35 | * class files. 36 | * 37 | * @param string[] $dirs 38 | */ 39 | public function __construct(array $dirs = []) 40 | { 41 | foreach ($dirs as $dir) { 42 | $this->common_dirs[] = realpath($dir); 43 | } 44 | 45 | $this->Preprocessor = new Preprocessor(); 46 | } 47 | 48 | /** 49 | * Add additional directories to scan for referenced class files. 50 | * 51 | * @param string[] $dirs 52 | */ 53 | public function addDirs(array $dirs) 54 | { 55 | foreach ($dirs as $dir) { 56 | $this->common_dirs[] = realpath($dir); 57 | } 58 | } 59 | 60 | /** 61 | * Parse a text file 62 | * 63 | * @param string $file 64 | * @param string[] $dirs 65 | * @param string[] $defines 66 | * @return Statement[] 67 | */ 68 | public function parse($file, array $dirs = [], array $defines = []) 69 | { 70 | return $this->parseText(file_get_contents(realpath($file)), $dirs); 71 | } 72 | 73 | /** 74 | * Parse plain text 75 | * 76 | * @param string $text 77 | * @param string[] $dirs 78 | * @param string[] $defines 79 | * @return Statement[] 80 | */ 81 | public function parseText($text, array $dirs = [], array $defines = []): array 82 | { 83 | $this->Preprocessor->resetDefines(); 84 | $this->Preprocessor->addDefines($defines); 85 | $text = $this->Preprocessor->preprocess($text); 86 | 87 | $Statements = []; 88 | 89 | foreach (preg_split('/\\R/m', $text) as $line => $data) { 90 | $data = trim($data); 91 | $command = self::wordShift($data); 92 | if (!empty($command)) { 93 | $Statements[] = new Statement($command, $data, null, $line); 94 | } 95 | } 96 | 97 | return $Statements; 98 | } 99 | 100 | /** 101 | * Get the first word from a string and remove it from the string. 102 | * 103 | * @param string $data 104 | * @return boolean|string 105 | */ 106 | private static function wordShift(&$data) 107 | { 108 | if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) { 109 | $data = $matches[2]; 110 | return $matches[1]; 111 | } 112 | return false; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /SwaggerGen/Parser/Text/Preprocessor.php: -------------------------------------------------------------------------------- 1 | 15 | * @copyright 2014-2016 Martijn van der Lee 16 | * @license https://opensource.org/licenses/MIT MIT 17 | */ 18 | class Preprocessor extends AbstractPreprocessor 19 | { 20 | 21 | protected function parseContent($content) 22 | { 23 | $pattern = '/\\s*([a-z]+)\\s*(.*)\\s*/'; 24 | 25 | $output = ''; 26 | 27 | foreach (preg_split('/(\\R)/m', $content, null, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) { 28 | if ($index % 2) { 29 | $output .= $line; 30 | } else { 31 | $match = array(); 32 | if (preg_match($pattern, $line, $match) === 1) { 33 | if (!$this->handle($match[1], $match[2]) && $this->getState()) { 34 | $output .= $line; 35 | } else { 36 | $output .= ''; 37 | } 38 | } else { 39 | $output .= $line; 40 | } 41 | } 42 | } 43 | 44 | return $output; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /SwaggerGen/Statement.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class Statement 15 | { 16 | 17 | private $command; 18 | private $data; 19 | private $file; 20 | private $line; 21 | 22 | public function __construct($command, $data = null, $file = null, $line = null) 23 | { 24 | $this->command = $command; 25 | $this->data = $data; 26 | $this->file = $file; 27 | $this->line = $line; 28 | } 29 | 30 | public function __toString() 31 | { 32 | $message = "Command '{$this->command}'"; 33 | $message .= $this->data ? " with data '{$this->data}'" : ' without data'; 34 | $message .= $this->file ? " from static text" : " in file '{$this->file}' on line {$this->line}"; 35 | return $message; 36 | } 37 | 38 | /** 39 | * Get the command part of this statement 40 | * @return string single word, without spaces 41 | */ 42 | public function getCommand() 43 | { 44 | return $this->command; 45 | } 46 | 47 | /** 48 | * Get the data of this statement 49 | * @return string may contain spaces 50 | */ 51 | public function getData() 52 | { 53 | return $this->data; 54 | } 55 | 56 | /** 57 | * Get the file (if available) where this statement was parsed from 58 | * @return string|null the full filename or null of from static text 59 | */ 60 | public function getFile() 61 | { 62 | return $this->file; 63 | } 64 | 65 | /** 66 | * Get the line number where this statement was found 67 | * @return int|null the line number 68 | */ 69 | public function getLine() 70 | { 71 | return $this->line; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /SwaggerGen/StatementException.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2016 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class StatementException extends \Exception 16 | { 17 | 18 | /** 19 | * @var Statement 20 | */ 21 | private $statement; 22 | 23 | /** 24 | * 25 | * @param string $message 26 | * @param int $code 27 | * @param Throwable $previous 28 | * @param Statement $statement 29 | */ 30 | public function __construct($message = "", $code = 0, $previous = null, $statement = null) 31 | { 32 | $this->statement = $statement; 33 | 34 | parent::__construct($message, $code, $previous); 35 | } 36 | 37 | public function getStatement() 38 | { 39 | return $this->statement; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/AbstractDocumentableObject.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | abstract class AbstractDocumentableObject extends AbstractObject 15 | { 16 | 17 | /** 18 | * External documentation 19 | * @var ExternalDocumentation 20 | */ 21 | private $externalDocs = null; 22 | 23 | /** 24 | * @param string $command 25 | * @param string $data 26 | * @return AbstractObject|boolean 27 | */ 28 | public function handleCommand($command, $data = null) 29 | { 30 | switch (strtolower($command)) { 31 | case 'doc': 32 | case 'docs': 33 | $url = self::wordShift($data); 34 | $this->externalDocs = new ExternalDocumentation($this, $url, $data); 35 | return $this->externalDocs; 36 | } 37 | 38 | return parent::handleCommand($command, $data); 39 | } 40 | 41 | /** 42 | * @return array 43 | */ 44 | public function toArray() 45 | { 46 | return self::arrayFilterNull(array_merge(array( 47 | 'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null, 48 | ), parent::toArray())); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/BodyParameter.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2016 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class BodyParameter extends AbstractObject implements IParameter 16 | { 17 | 18 | /** 19 | * @var string|boolean 20 | */ 21 | private $name = ''; 22 | private $description; 23 | private $required = false; 24 | 25 | /** 26 | * @var Schema 27 | */ 28 | private $schema; 29 | 30 | /** 31 | * @throws Exception 32 | */ 33 | public function __construct(AbstractObject $parent, $data, $required = false) 34 | { 35 | parent::__construct($parent); 36 | 37 | $type = self::wordShift($data); 38 | if (empty($type)) { 39 | throw new Exception('No type definition for body parameter'); 40 | } 41 | 42 | $this->name = self::wordShift($data); 43 | if (empty($this->name)) { 44 | throw new Exception('No name for body parameter'); 45 | } 46 | 47 | $this->description = $data; 48 | $this->required = (bool)$required; 49 | 50 | $this->schema = new Schema($this, $type); 51 | } 52 | 53 | /** 54 | * @param string $command 55 | * @param string $data 56 | * @return AbstractObject|boolean 57 | * @throws Exception 58 | */ 59 | public function handleCommand($command, $data = null) 60 | { 61 | // Pass through to Type 62 | $return = $this->schema->handleCommand($command, $data); 63 | if ($return) { 64 | return $return; 65 | } 66 | 67 | return parent::handleCommand($command, $data); 68 | } 69 | 70 | public function toArray() 71 | { 72 | return self::arrayFilterNull(array_merge(array( 73 | 'name' => $this->name, 74 | 'in' => 'body', 75 | 'description' => empty($this->description) ? null : $this->description, 76 | 'required' => $this->required ? true : null, 77 | 'schema' => $this->schema->toArray(), 78 | ), parent::toArray())); 79 | } 80 | 81 | public function __toString() 82 | { 83 | return __CLASS__ . ' ' . $this->name; 84 | } 85 | 86 | public function getName() 87 | { 88 | return $this->name; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Contact.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class Contact extends AbstractObject 15 | { 16 | 17 | private $name; 18 | private $url; 19 | private $email; 20 | 21 | public function __construct(AbstractObject $parent, $name = null, $url = null, $email = null) 22 | { 23 | parent::__construct($parent); 24 | 25 | $this->name = empty($name) ? null : $name; 26 | $this->url = empty($url) ? null : $url; 27 | $this->email = empty($email) ? null : $email; 28 | } 29 | 30 | /** 31 | * @param string $command 32 | * @param string $data 33 | * @return AbstractObject|boolean 34 | */ 35 | public function handleCommand($command, $data = null) 36 | { 37 | switch (strtolower($command)) { 38 | case 'name': 39 | case 'url': 40 | case 'email': 41 | $this->$command = $data; 42 | return $this; 43 | } 44 | 45 | return parent::handleCommand($command, $data); 46 | } 47 | 48 | public function toArray() 49 | { 50 | return self::arrayFilterNull(array_merge(array( 51 | 'name' => $this->name, 52 | 'url' => $this->url, 53 | 'email' => $this->email, 54 | ), parent::toArray())); 55 | } 56 | 57 | public function __toString() 58 | { 59 | return __CLASS__ . " {$this->name} <{$this->email}>, {$this->url}"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Error.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2016 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class Error extends Response 15 | { 16 | 17 | public function __construct(AbstractObject $parent, $code, $description = null) 18 | { 19 | parent::__construct($parent, $code, null, $description); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/ExternalDocumentation.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class ExternalDocumentation extends AbstractObject 15 | { 16 | 17 | private $url; 18 | private $description; 19 | 20 | public function __construct(AbstractObject $parent, $url, $description = null) 21 | { 22 | parent::__construct($parent); 23 | $this->url = $url; 24 | $this->description = $description; 25 | } 26 | 27 | /** 28 | * @param string $command 29 | * @param string $data 30 | * @return AbstractObject|boolean 31 | */ 32 | public function handleCommand($command, $data = null) 33 | { 34 | switch (strtolower($command)) { 35 | case 'url': 36 | case 'description': 37 | $this->$command = $data; 38 | return $this; 39 | } 40 | 41 | return parent::handleCommand($command, $data); 42 | } 43 | 44 | public function toArray() 45 | { 46 | return self::arrayFilterNull(array_merge(array( 47 | 'url' => $this->url, 48 | 'description' => empty($this->description) ? null : $this->description, 49 | ), parent::toArray())); 50 | } 51 | 52 | public function __toString() 53 | { 54 | return __CLASS__ . ' ' . $this->url; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Header.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2015 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class Header extends AbstractObject 16 | { 17 | 18 | private $type; 19 | private $description; 20 | 21 | /** 22 | * @throws Exception 23 | */ 24 | public function __construct(AbstractObject $parent, $type, $description = null) 25 | { 26 | parent::__construct($parent); 27 | 28 | $this->type = strtolower($type); 29 | if (!in_array($this->type, array('string', 'number', 'integer', 'boolean', 'array'))) { 30 | throw new Exception('Header type not valid: \'' . $type . '\''); 31 | } 32 | 33 | $this->description = $description; 34 | } 35 | 36 | /** 37 | * @param string $command 38 | * @param string $data 39 | * @return AbstractObject|boolean 40 | */ 41 | public function handleCommand($command, $data = null) 42 | { 43 | if (strtolower($command) === 'description') { 44 | $this->description = $data; 45 | return $this; 46 | } 47 | 48 | return parent::handleCommand($command, $data); 49 | } 50 | 51 | public function toArray() 52 | { 53 | return self::arrayFilterNull(array_merge(array( 54 | 'type' => $this->type, 55 | 'description' => empty($this->description) ? null : $this->description, 56 | ), parent::toArray())); 57 | } 58 | 59 | public function __toString() 60 | { 61 | return __CLASS__ . ' ' . $this->type; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/IDefinition.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2015 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | interface IDefinition 14 | { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/IParameter.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2015 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | interface IParameter 14 | { 15 | 16 | public function getName(); 17 | } 18 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Info.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright 2014-2015 Martijn van der Lee 12 | * @license https://opensource.org/licenses/MIT MIT 13 | */ 14 | class Info extends AbstractObject 15 | { 16 | 17 | /** 18 | * @var string 19 | */ 20 | private $title = 'undefined'; 21 | 22 | /** 23 | * @var string 24 | */ 25 | private $description; 26 | 27 | /** 28 | * @var string 29 | */ 30 | private $termsofservice; 31 | 32 | /** 33 | * @var Contact 34 | */ 35 | private $contact; 36 | 37 | /** 38 | * @var License 39 | */ 40 | private $license; 41 | 42 | /** 43 | * @var string|integer|float 44 | */ 45 | private $version = 0; 46 | 47 | /** 48 | * @param string $command 49 | * @param string $data 50 | * @return AbstractObject|boolean 51 | */ 52 | public function handleCommand($command, $data = null) 53 | { 54 | switch (strtolower($command)) { 55 | case 'title': 56 | case 'description': 57 | case 'termsofservice': 58 | case 'version': 59 | $this->$command = $data; 60 | return $this; 61 | 62 | case 'terms': // alias 63 | case 'tos': // alias 64 | $this->termsofservice = $data; 65 | return $this; 66 | 67 | case 'contact': 68 | $name = array(); 69 | $url = null; 70 | $email = null; 71 | foreach (self::wordSplit($data) as $word) { 72 | if (filter_var($word, FILTER_VALIDATE_URL)) { 73 | $url = $word; 74 | } elseif (filter_var($word, FILTER_VALIDATE_EMAIL)) { 75 | $email = $word; 76 | } else { 77 | $name[] = $word; 78 | } 79 | } 80 | $name = join(' ', array_filter($name)); 81 | $this->contact = new Contact($this, $name, $url, $email); 82 | return $this->contact; 83 | 84 | case 'license': 85 | $name = array(); 86 | $url = null; 87 | foreach (self::wordSplit($data) as $word) { 88 | if (filter_var($word, FILTER_VALIDATE_URL)) { 89 | $url = $word; 90 | } else { 91 | $name[] = $word; 92 | } 93 | } 94 | $name = join(' ', array_filter($name)); 95 | $this->license = new License($this, $name, $url); 96 | return $this->license; 97 | } 98 | 99 | return parent::handleCommand($command, $data); 100 | } 101 | 102 | public function toArray() 103 | { 104 | return self::arrayFilterNull(array_merge(array( 105 | 'title' => $this->title, 106 | 'description' => $this->description, 107 | 'termsOfService' => $this->termsofservice, 108 | 'contact' => $this->contact ? $this->contact->toArray() : null, 109 | 'license' => $this->license ? $this->license->toArray() : null, 110 | 'version' => (string)$this->version, 111 | ), parent::toArray())); 112 | } 113 | 114 | public function __toString() 115 | { 116 | return __CLASS__ . ' \'' . $this->title . '\''; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/ParameterReference.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2016 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | class ParameterReference extends AbstractObject implements IParameter 14 | { 15 | 16 | private $reference; 17 | 18 | public function __construct(AbstractObject $parent, $reference) 19 | { 20 | parent::__construct($parent); 21 | 22 | $this->reference = $reference; 23 | } 24 | 25 | public function toArray() 26 | { 27 | return self::arrayFilterNull(array( 28 | '$ref' => '#/parameters/' . $this->reference, 29 | )); 30 | } 31 | 32 | public function __toString() 33 | { 34 | return __CLASS__ . ' `' . $this->reference . '`'; 35 | } 36 | 37 | public function getName() 38 | { 39 | return $this->reference; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Path.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright 2014-2015 Martijn van der Lee 14 | * @license https://opensource.org/licenses/MIT MIT 15 | */ 16 | class Path extends AbstractObject 17 | { 18 | 19 | private static $methods = array( 20 | 'get', 21 | 'put', 22 | 'post', 23 | 'delete', 24 | 'options', 25 | 'head', 26 | 'patch', 27 | ); 28 | 29 | /** 30 | * @var Operation[] $operation 31 | */ 32 | private $operations = array(); 33 | 34 | /** 35 | * @var Tag|null $tag ; 36 | */ 37 | private $tag; 38 | 39 | public function __construct(AbstractObject $parent, Tag $Tag = null) 40 | { 41 | parent::__construct($parent); 42 | $this->tag = $Tag; 43 | } 44 | 45 | /** 46 | * @param string $command 47 | * @param string $data 48 | * @return AbstractObject|boolean 49 | * @throws Exception 50 | */ 51 | public function handleCommand($command, $data = null) 52 | { 53 | switch (strtolower($command)) { 54 | case 'method': // alias 55 | case 'operation': 56 | $method = strtolower(self::wordShift($data)); 57 | 58 | if (!in_array($method, self::$methods)) { 59 | throw new Exception('Unrecognized operation method \'' . $method . '\''); 60 | } 61 | 62 | if (isset($this->operations[$method])) { 63 | $Operation = $this->operations[$method]; 64 | } else { 65 | $summary = $data; 66 | $Operation = new Operation($this, $summary, $this->tag); 67 | $this->operations[$method] = $Operation; 68 | } 69 | 70 | return $Operation; 71 | 72 | case 'description': 73 | if ($this->tag) { 74 | return $this->tag->handleCommand($command, $data); 75 | } 76 | break; 77 | } 78 | 79 | return parent::handleCommand($command, $data); 80 | } 81 | 82 | public function toArray() 83 | { 84 | $methods = self::$methods; 85 | uksort($this->operations, function ($a, $b) use ($methods) { 86 | return array_search($a, $methods) - array_search($b, $methods); 87 | }); 88 | 89 | return self::arrayFilterNull(array_merge( 90 | self::objectsToArray($this->operations) 91 | , parent::toArray())); 92 | } 93 | 94 | public function __toString() 95 | { 96 | end($this->operations); 97 | return __CLASS__ . ' ' . key($this->operations); 98 | } 99 | 100 | /** 101 | * Check if an operation with the given id is registered to this Path. 102 | * 103 | * @param string $operationId 104 | * @return boolean 105 | */ 106 | public function hasOperationId($operationId) 107 | { 108 | foreach ($this->operations as $operation) { 109 | if ($operation->getId() === $operationId) { 110 | return true; 111 | } 112 | } 113 | 114 | return false; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/ResponseReference.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2016 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | class ResponseReference extends AbstractObject 14 | { 15 | 16 | private $reference; 17 | 18 | public function __construct(AbstractObject $parent, $reference) 19 | { 20 | parent::__construct($parent); 21 | 22 | $this->reference = $reference; 23 | } 24 | 25 | public function toArray() 26 | { 27 | return self::arrayFilterNull(array( 28 | '$ref' => '#/responses/' . $this->reference, 29 | )); 30 | } 31 | 32 | public function __toString() 33 | { 34 | return __CLASS__ . ' `' . $this->reference . '`'; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Schema.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2015 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class Schema extends AbstractDocumentableObject implements IDefinition 18 | { 19 | 20 | /** 21 | * @var string 22 | */ 23 | private $description; 24 | 25 | /** 26 | * @var string 27 | */ 28 | private $title = null; 29 | 30 | /** 31 | * @var bool 32 | */ 33 | private $readOnly = null; 34 | 35 | /** 36 | * @var AbstractType 37 | */ 38 | private $type; 39 | 40 | /** 41 | * @param string $description 42 | * @throws Exception 43 | */ 44 | public function __construct(AbstractObject $parent, $definition = 'object', $description = null) 45 | { 46 | parent::__construct($parent); 47 | 48 | // Check if definition set 49 | if ($this->getSwagger()->hasDefinition($definition)) { 50 | $this->type = new Type\ReferenceObjectType($this, $definition); 51 | } else { 52 | $this->type = Type\AbstractType::typeFactory($this, $definition); 53 | } 54 | 55 | $this->description = $description; 56 | } 57 | 58 | /** 59 | * @param string $command 60 | * @param string $data 61 | * @return AbstractObject|boolean 62 | * @throws Exception 63 | */ 64 | public function handleCommand($command, $data = null) 65 | { 66 | // Pass through to Type 67 | if ($this->type && $this->type->handleCommand($command, $data)) { 68 | return $this; 69 | } 70 | 71 | // handle all the rest manually 72 | switch (strtolower($command)) { 73 | case 'description': 74 | $this->description = $data; 75 | return $this; 76 | 77 | case 'title': 78 | $this->title = $data; 79 | return $this; 80 | } 81 | 82 | return parent::handleCommand($command, $data); 83 | } 84 | 85 | public function toArray() 86 | { 87 | return self::arrayFilterNull(array_merge($this->type->toArray(), array( 88 | 'title' => empty($this->title) ? null : $this->title, 89 | 'description' => empty($this->description) ? null : $this->description, 90 | 'readOnly' => $this->readOnly 91 | ), parent::toArray())); 92 | } 93 | 94 | public function __toString() 95 | { 96 | return __CLASS__; 97 | } 98 | 99 | public function setReadOnly() 100 | { 101 | $this->readOnly = true; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Tag.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2015 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | class Tag extends AbstractDocumentableObject 14 | { 15 | 16 | private $name; 17 | private $description; 18 | 19 | public function __construct(AbstractObject $parent, $name, $description = null) 20 | { 21 | parent::__construct($parent); 22 | $this->name = $name; 23 | $this->description = $description; 24 | } 25 | 26 | /** 27 | * @param string $command 28 | * @param string $data 29 | * @return AbstractObject|boolean 30 | */ 31 | public function handleCommand($command, $data = null) 32 | { 33 | if (strtolower($command) === 'description') { 34 | $this->description = $data; 35 | return $this; 36 | } 37 | 38 | return parent::handleCommand($command, $data); 39 | } 40 | 41 | public function toArray() 42 | { 43 | return self::arrayFilterNull(array_merge(array( 44 | 'name' => $this->name, 45 | 'description' => empty($this->description) ? null : $this->description, 46 | ), parent::toArray())); 47 | } 48 | 49 | public function getName() 50 | { 51 | return $this->name; 52 | } 53 | 54 | public function __toString() 55 | { 56 | return __CLASS__ . ' ' . $this->name; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/AbstractRegexType.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright 2014-2016 Martijn van der Lee 14 | * @license https://opensource.org/licenses/MIT MIT 15 | */ 16 | class AbstractRegexType extends StringType 17 | { 18 | 19 | const REGEX_DEFAULT_START = '(?:=('; 20 | const REGEX_DEFAULT_END = '))?'; 21 | 22 | /** 23 | * The raw regular expression to use. 24 | * Exclude start (`^`) and end (`$`) anchors. 25 | * @var string 26 | */ 27 | private $regex; 28 | 29 | /** 30 | * Construct and set up the regular expression for this type 31 | * 32 | * @param AbstractObject $parent 33 | * @param string $definition 34 | * @param string $format Name of the string format 35 | * @param string $regex Regular expression to use as the format and for default validation 36 | */ 37 | public function __construct(AbstractObject $parent, $definition, $format, $regex) 38 | { 39 | $this->format = $format; 40 | $this->regex = $regex; 41 | 42 | parent::__construct($parent, $definition); 43 | } 44 | 45 | /** 46 | * @throws Exception 47 | */ 48 | protected function parseDefinition($definition) 49 | { 50 | $definition = self::trim($definition); 51 | 52 | $match = array(); 53 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) { 54 | throw new Exception('Unparseable ' . $this->format . ' definition: \'' . $definition . '\''); 55 | } 56 | 57 | if (strtolower($match[1] !== $this->format)) { 58 | throw new Exception('Not a ' . $this->format . ': \'' . $definition . '\''); 59 | } 60 | 61 | $this->pattern = '^' . $this->regex . '$'; 62 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 63 | } 64 | 65 | protected function validateDefault($value) 66 | { 67 | $value = parent::validateDefault($value); 68 | 69 | if (preg_match('/' . $this->pattern . '/', $value) !== 1) { 70 | throw new Exception('Invalid ' . $this->format . ' default value'); 71 | } 72 | 73 | return $value; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/AllOfType.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2015 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class AllOfType extends AbstractType 16 | { 17 | private $allOfItems = array(); 18 | private $mostRecentItem; 19 | 20 | /** 21 | * @throws Exception 22 | */ 23 | protected function parseDefinition($definition) 24 | { 25 | $pattern = self::REGEX_START . 'allof' . self::REGEX_CONTENT . self::REGEX_END; 26 | $inlineDef = ''; 27 | if (preg_match($pattern, $definition, $matches)) { 28 | if (isset($matches[1])) { 29 | $inlineDef = $matches[1]; 30 | } 31 | } 32 | if ($inlineDef) { 33 | foreach ($this->parseList($inlineDef) as $item) { 34 | $this->handleCommand('item', $item); 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * @throws Exception 41 | */ 42 | public function handleCommand($command, $data = null) 43 | { 44 | if (strtolower($command) === 'item') { 45 | $this->mostRecentItem = self::typeFactory($this, $data); 46 | $this->allOfItems[] = $this->mostRecentItem; 47 | return $this; 48 | } 49 | if (isset($this->mostRecentItem)) { 50 | if ($this->mostRecentItem->handleCommand($command, $data)) { 51 | return $this; 52 | } 53 | } 54 | return parent::handleCommand($command, $data); 55 | } 56 | 57 | public function toArray() 58 | { 59 | $allOf = array(); 60 | foreach ($this->allOfItems as $item) { 61 | $allOf[] = $item->toArray(); 62 | } 63 | return self::arrayFilterNull(array_merge(array( 64 | 'allOf' => $allOf, 65 | ), parent::toArray())); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/BooleanType.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2015 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class BooleanType extends AbstractType 16 | { 17 | 18 | const REGEX_DEFAULT = '(?:=(true|false|1|0))?'; 19 | 20 | private $default = null; 21 | 22 | /** 23 | * @throws Exception 24 | */ 25 | protected function parseDefinition($definition) 26 | { 27 | $match = array(); 28 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 29 | throw new Exception("Unparseable boolean definition: '{$definition}'"); 30 | } 31 | 32 | if (strtolower($match[1]) !== 'boolean') { 33 | throw new Exception("Not a boolean: '{$definition}'"); 34 | } 35 | 36 | if (isset($match[2])) { 37 | $this->default = ($match[2] === '1') || (strtolower($match[2]) === 'true'); 38 | } 39 | } 40 | 41 | /** 42 | * @param string $command The comment command 43 | * @param string $data Any data added after the command 44 | * @return AbstractType|boolean 45 | * @throws Exception 46 | * @throws Exception 47 | */ 48 | public function handleCommand($command, $data = null) 49 | { 50 | if (strtolower($command) === 'default') { 51 | if (!in_array($data, array('0', '1', 'true', 'false'))) { 52 | throw new Exception("Invalid boolean default: '{$data}'"); 53 | } 54 | $this->default = ($data == '1') || (strtolower($data) === 'true'); 55 | return $this; 56 | } 57 | 58 | return parent::handleCommand($command, $data); 59 | } 60 | 61 | public function toArray() 62 | { 63 | return self::arrayFilterNull(array_merge(array( 64 | 'type' => 'boolean', 65 | 'default' => $this->default, 66 | ), parent::toArray())); 67 | } 68 | 69 | public function __toString() 70 | { 71 | return __CLASS__; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Custom/EmailType.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2017 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class EmailType extends StringType implements ICustomType 18 | { 19 | 20 | const PATTERN = '\A[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z'; 21 | 22 | /** 23 | * List of formats recognized by this class 24 | * @var string[] 25 | */ 26 | private static $formats = array('email'); 27 | 28 | /** 29 | * Construct and set up the regular expression for this type 30 | * 31 | * @param AbstractObject $parent 32 | * @param string $definition 33 | */ 34 | public function __construct(AbstractObject $parent, $definition) 35 | { 36 | $this->pattern = self::PATTERN; 37 | 38 | parent::__construct($parent, $definition); 39 | } 40 | 41 | /** 42 | * Parse a type definition string, assuming it belongs to this type 43 | * 44 | * @param string $definition 45 | * @throws Exception 46 | */ 47 | protected function parseDefinition($definition) 48 | { 49 | $definition = self::trim($definition); 50 | 51 | $match = array(); 52 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 53 | throw new Exception("Unparseable email definition: '{$definition}'"); 54 | } 55 | 56 | if (!in_array(strtolower($match[1]), self::$formats)) { 57 | throw new Exception("Not an email: '{$definition}'"); 58 | } 59 | 60 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 61 | } 62 | 63 | /** 64 | * Check (and optionally reformat) a default value 65 | * 66 | * @param string $value 67 | * @return string 68 | * @throws Exception 69 | */ 70 | protected function validateDefault($value) 71 | { 72 | if (empty($value)) { 73 | throw new Exception("Empty email default"); 74 | } 75 | 76 | if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) { 77 | throw new Exception("Invalid email default value: '{$value}'"); 78 | } 79 | 80 | return $value; 81 | } 82 | 83 | public static function getFormats() 84 | { 85 | return self::$formats; 86 | } 87 | 88 | public static function setFormats(array $formats) 89 | { 90 | self::$formats = $formats; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Custom/ICustomType.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright 2014-2017 Martijn van der Lee 11 | * @license https://opensource.org/licenses/MIT MIT 12 | */ 13 | interface ICustomType 14 | { 15 | 16 | /** 17 | * Return a list of formats recognized by this type 18 | * @return string[] 19 | */ 20 | public static function getFormats(); 21 | 22 | /** 23 | * Overwrite format names recognized by this type 24 | * @param string[] $formats 25 | */ 26 | public static function setFormats(array $formats); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Custom/Ipv4Type.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2017 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class Ipv4Type extends StringType implements ICustomType 18 | { 19 | 20 | const PATTERN = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$'; 21 | 22 | /** 23 | * List of formats recognized by this class 24 | * @var string[] 25 | */ 26 | private static $formats = array('ipv4'); 27 | 28 | /** 29 | * Construct and set up the regular expression for this type 30 | * 31 | * @param AbstractObject $parent 32 | * @param string $definition 33 | */ 34 | public function __construct(AbstractObject $parent, $definition) 35 | { 36 | $this->pattern = self::PATTERN; 37 | 38 | parent::__construct($parent, $definition); 39 | } 40 | 41 | /** 42 | * Parse a type definition string, assuming it belongs to this type 43 | * 44 | * @param string $definition 45 | * @throws Exception 46 | */ 47 | protected function parseDefinition($definition) 48 | { 49 | $definition = self::trim($definition); 50 | 51 | $match = array(); 52 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 53 | throw new Exception("Unparseable IPv4 definition: '{$definition}'"); 54 | } 55 | 56 | if (!in_array(strtolower($match[1]), self::$formats)) { 57 | throw new Exception("Not an IPv4: '{$definition}'"); 58 | } 59 | 60 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 61 | } 62 | 63 | /** 64 | * Check (and optionally reformat) a default value 65 | * 66 | * @param string $value 67 | * @return string 68 | * @throws Exception 69 | */ 70 | protected function validateDefault($value) 71 | { 72 | if (empty($value)) { 73 | throw new Exception("Empty IPv4 default"); 74 | } 75 | 76 | if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { 77 | throw new Exception("Invalid IPv4 default value: '{$value}'"); 78 | } 79 | 80 | return $value; 81 | } 82 | 83 | public static function getFormats() 84 | { 85 | return self::$formats; 86 | } 87 | 88 | public static function setFormats(array $formats) 89 | { 90 | self::$formats = $formats; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Custom/Ipv6Type.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2017 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class Ipv6Type extends StringType implements ICustomType 18 | { 19 | 20 | const PATTERN = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; 21 | 22 | /** 23 | * List of formats recognized by this class 24 | * @var string[] 25 | */ 26 | private static $formats = array('ipv6'); 27 | 28 | /** 29 | * Construct and set up the regular expression for this type 30 | * 31 | * @param AbstractObject $parent 32 | * @param string $definition 33 | */ 34 | public function __construct(AbstractObject $parent, $definition) 35 | { 36 | $this->pattern = self::PATTERN; 37 | 38 | parent::__construct($parent, $definition); 39 | } 40 | 41 | /** 42 | * Parse a type definition string, assuming it belongs to this type 43 | * 44 | * @param string $definition 45 | * @throws Exception 46 | */ 47 | protected function parseDefinition($definition) 48 | { 49 | $definition = self::trim($definition); 50 | 51 | $match = array(); 52 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 53 | throw new Exception("Unparseable IPv6 definition: '{$definition}'"); 54 | } 55 | 56 | if (!in_array(strtolower($match[1]), self::$formats)) { 57 | throw new Exception("Not an IPv6: '{$definition}'"); 58 | } 59 | 60 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 61 | } 62 | 63 | /** 64 | * Check (and optionally reformat) a default value 65 | * 66 | * @param string $value 67 | * @return string 68 | * @throws Exception 69 | */ 70 | protected function validateDefault($value) 71 | { 72 | if (empty($value)) { 73 | throw new Exception("Empty IPv6 default"); 74 | } 75 | 76 | if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { 77 | throw new Exception("Invalid IPv6 default value: '{$value}'"); 78 | } 79 | 80 | return $value; 81 | } 82 | 83 | public static function getFormats() 84 | { 85 | return self::$formats; 86 | } 87 | 88 | public static function setFormats(array $formats) 89 | { 90 | self::$formats = $formats; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Custom/MacType.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2017 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class MacType extends StringType implements ICustomType 18 | { 19 | 20 | const PATTERN = '^([0-9A-F]){2}(:[0-9A-F]{2}){5}$'; 21 | 22 | /** 23 | * List of formats recognized by this class 24 | * @var string[] 25 | */ 26 | private static $formats = array('mac'); 27 | 28 | /** 29 | * Construct and set up the regular expression for this type 30 | * 31 | * @param AbstractObject $parent 32 | * @param string $definition 33 | */ 34 | public function __construct(AbstractObject $parent, $definition) 35 | { 36 | $this->pattern = self::PATTERN; 37 | 38 | parent::__construct($parent, $definition); 39 | } 40 | 41 | /** 42 | * Parse a type definition string, assuming it belongs to this type 43 | * 44 | * @param string $definition 45 | * @throws Exception 46 | */ 47 | protected function parseDefinition($definition) 48 | { 49 | $definition = self::trim($definition); 50 | 51 | $match = array(); 52 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 53 | throw new Exception("Unparseable MAC definition: '{$definition}'"); 54 | } 55 | 56 | if (!in_array(strtolower($match[1]), self::$formats)) { 57 | throw new Exception("Not a MAC: '{$definition}'"); 58 | } 59 | 60 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 61 | } 62 | 63 | /** 64 | * Check (and optionally reformat) a default value 65 | * 66 | * @param string $value 67 | * @return string 68 | * @throws Exception 69 | */ 70 | protected function validateDefault($value) 71 | { 72 | if (empty($value)) { 73 | throw new Exception("Empty MAC default"); 74 | } 75 | 76 | if (preg_match('/^([0-9A-F]){2}(:[0-9A-F]{2}){5}$/', $value) !== 1) { 77 | throw new Exception("Invalid MAC default value: '{$value}'"); 78 | } 79 | 80 | return $value; 81 | } 82 | 83 | public static function getFormats() 84 | { 85 | return self::$formats; 86 | } 87 | 88 | public static function setFormats(array $formats) 89 | { 90 | self::$formats = $formats; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/DateType.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright 2014-2015 Martijn van der Lee 14 | * @license https://opensource.org/licenses/MIT MIT 15 | */ 16 | class DateType extends AbstractType 17 | { 18 | 19 | const REGEX_DEFAULT = '(?:=(\S+))?'; 20 | 21 | /** 22 | * Map of recognized format names to Swagger formats 23 | * @var array 24 | */ 25 | private static $formats = array( 26 | 'date' => 'date', 27 | 'date-time' => 'date-time', 28 | 'datetime' => 'date-time', 29 | ); 30 | private static $datetime_formats = array( 31 | 'date' => 'Y-m-d', 32 | 'date-time' => DateTime::RFC3339, 33 | ); 34 | 35 | /** 36 | * @var String 37 | */ 38 | private $format; 39 | 40 | /** 41 | * @var DateTime 42 | */ 43 | private $default = null; 44 | 45 | /** 46 | * @throws Exception 47 | */ 48 | protected function parseDefinition($definition) 49 | { 50 | $match = array(); 51 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 52 | throw new Exception("Unparseable date definition: '{$definition}'"); 53 | } 54 | 55 | $type = strtolower($match[1]); 56 | 57 | if (!isset(self::$formats[$type])) { 58 | throw new Exception("Not a date: '{$definition}'"); 59 | } 60 | $this->format = self::$formats[$type]; 61 | 62 | $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; 63 | } 64 | 65 | /** 66 | * @param string $command The comment command 67 | * @param string $data Any data added after the command 68 | * @return AbstractType|boolean 69 | * @throws Exception 70 | * @throws Exception 71 | */ 72 | public function handleCommand($command, $data = null) 73 | { 74 | if (strtolower($command) === 'default') { 75 | $this->default = $this->validateDefault($data); 76 | return $this; 77 | } 78 | 79 | return parent::handleCommand($command, $data); 80 | } 81 | 82 | public function toArray() 83 | { 84 | return self::arrayFilterNull(array_merge(array( 85 | 'type' => 'string', 86 | 'format' => $this->format, 87 | 'default' => $this->default ? $this->default->format(self::$datetime_formats[$this->format]) : null, 88 | ), parent::toArray())); 89 | } 90 | 91 | /** 92 | * @throws Exception 93 | */ 94 | private function validateDefault($value) 95 | { 96 | if (empty($value)) { 97 | throw new Exception("Empty date default"); 98 | } 99 | 100 | if (($DateTime = date_create($value)) !== false) { 101 | return $DateTime; 102 | } 103 | 104 | throw new Exception("Invalid '{$this->format}' default: '{$value}'"); 105 | } 106 | 107 | public function __toString() 108 | { 109 | return __CLASS__; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/FileType.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright 2014-2015 Martijn van der Lee 15 | * @license https://opensource.org/licenses/MIT MIT 16 | */ 17 | class FileType extends AbstractType 18 | { 19 | 20 | /** 21 | * @throws Exception 22 | */ 23 | protected function parseDefinition($definition) 24 | { 25 | $type = strtolower($definition); 26 | 27 | if ($type !== 'file') { 28 | throw new Exception("Not a file: '{$definition}'"); 29 | } 30 | 31 | $parent = $this->getParent(); 32 | if (!($parent instanceof Parameter) || !$parent->isForm()) { 33 | throw new Exception("File type '{$definition}' only allowed on form parameter"); 34 | } 35 | 36 | /** @var Operation $parentOperation */ 37 | $parentOperation = $this->getParentClass(Operation::class); 38 | $consumes = $parentOperation->getConsumes(); 39 | if (empty($consumes)) { 40 | $consumes = $this->getSwagger()->getConsumes(); 41 | } 42 | 43 | $valid_consumes = ((int)in_array('multipart/form-data', $consumes)) + ((int)in_array('application/x-www-form-urlencoded', $consumes)); 44 | if (empty($consumes) || $valid_consumes !== count($consumes)) { 45 | throw new Exception("File type '{$definition}' without valid consume"); 46 | } 47 | } 48 | 49 | public function toArray() 50 | { 51 | return self::arrayFilterNull(array_merge(array( 52 | 'type' => 'file', 53 | ), parent::toArray())); 54 | } 55 | 56 | public function __toString() 57 | { 58 | return __CLASS__; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/Property.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright 2014-2015 Martijn van der Lee 14 | * @license https://opensource.org/licenses/MIT MIT 15 | */ 16 | class Property extends AbstractObject 17 | { 18 | 19 | /** 20 | * Description of this property 21 | * @var string 22 | */ 23 | private $description; 24 | 25 | /** 26 | * Whether property is read only 27 | * @var bool 28 | */ 29 | private $readOnly; 30 | 31 | /** 32 | * Type definition of this property 33 | * @var AbstractType 34 | */ 35 | private $Type; 36 | 37 | /** 38 | * Create a new property 39 | * @param AbstractObject $parent 40 | * @param string $definition Either a built-in type or a definition name 41 | * @param string $description description of the property 42 | * @param bool $readOnly Whether the property is read only 43 | * @throws Exception 44 | */ 45 | public function __construct(AbstractObject $parent, $definition, $description = null, $readOnly = null) 46 | { 47 | parent::__construct($parent); 48 | $this->Type = AbstractType::typeFactory($this, $definition, "Not a property: '%s'"); 49 | $this->description = $description; 50 | $this->readOnly = $readOnly; 51 | } 52 | 53 | /** 54 | * @param string $command The comment command 55 | * @param string $data Any data added after the command 56 | * @return self|boolean 57 | * @throws Exception 58 | */ 59 | public function handleCommand($command, $data = null) 60 | { 61 | // Pass through to Type 62 | if ($this->Type && $this->Type->handleCommand($command, $data)) { 63 | return $this; 64 | } 65 | 66 | return parent::handleCommand($command, $data); 67 | } 68 | 69 | public function toArray() 70 | { 71 | // Reference + readonly/description result in allOf construct 72 | // as it's semantically the same and that's what swagger tools 73 | // like swagger-ui can understand 74 | $requiresWrap = 75 | $this->Type instanceof ReferenceObjectType 76 | && (!empty($this->description) || !is_null($this->readOnly)); 77 | 78 | $valueType = $this->Type->toArray(); 79 | 80 | if ($requiresWrap) { 81 | $valueType = array( 82 | 'allOf' => array($valueType), 83 | ); 84 | } 85 | 86 | return self::arrayFilterNull(array_merge($valueType, array( 87 | 'description' => empty($this->description) ? null : $this->description, 88 | 'readOnly' => $this->readOnly 89 | ), parent::toArray())); 90 | } 91 | 92 | public function __toString() 93 | { 94 | return __CLASS__; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/ReferenceObjectType.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2015 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class ReferenceObjectType extends AbstractType 16 | { 17 | 18 | private $reference = null; 19 | 20 | /** 21 | * @throws Exception 22 | */ 23 | protected function parseDefinition($definition) 24 | { 25 | $definition = self::trim($definition); 26 | 27 | $match = array(); 28 | if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { 29 | throw new Exception('Unparseable string definition: \'' . $definition . '\''); 30 | } 31 | 32 | $type = strtolower($match[1]); 33 | 34 | $reference = null; 35 | if ($type === 'refobject') { 36 | if (isset($match[2])) { 37 | $reference = $match[2]; 38 | } 39 | } else { 40 | $reference = $match[1]; 41 | } 42 | 43 | if (empty($reference)) { 44 | throw new Exception('Referenced object name missing: \'' . $definition . '\''); 45 | } 46 | 47 | $this->reference = $reference; 48 | } 49 | 50 | public function toArray() 51 | { 52 | return self::arrayFilterNull(array_merge(array( 53 | '$ref' => '#/definitions/' . $this->reference, 54 | ), parent::toArray())); 55 | } 56 | 57 | public function __toString() 58 | { 59 | return __CLASS__ . ' ' . $this->reference; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /SwaggerGen/Swagger/Type/StringUuidType.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2016 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class StringUuidType extends AbstractRegexType 16 | { 17 | 18 | /** 19 | * Construct and set up the regular expression for this type 20 | * 21 | * @param AbstractObject $parent 22 | * @param string $definition 23 | */ 24 | public function __construct(AbstractObject $parent, $definition) 25 | { 26 | parent::__construct($parent, $definition, 'uuid', '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}'); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /SwaggerGen/TypeRegistry.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright 2014-2017 Martijn van der Lee 13 | * @license https://opensource.org/licenses/MIT MIT 14 | */ 15 | class TypeRegistry 16 | { 17 | 18 | /** 19 | * Map of format-name => class-name 20 | * 21 | * @var array 22 | */ 23 | private $formats = array(); 24 | 25 | /** 26 | * Add a type name from classname 27 | * 28 | * @param string $classname 29 | */ 30 | public function add(string $classname): void 31 | { 32 | if (is_subclass_of($classname, ICustomType::class)) { 33 | foreach ($classname::getFormats() as $format) { 34 | $this->formats[$format] = $classname; 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * Remove type format by explicitly nulling it (disables it) 41 | * 42 | * @param string $name 43 | */ 44 | public function remove($name) 45 | { 46 | $this->formats[$name] = null; 47 | } 48 | 49 | /** 50 | * Is a type format known? 51 | * 52 | * @return bool 53 | */ 54 | public function has($name) 55 | { 56 | return !empty($this->formats[$name]); 57 | } 58 | 59 | /** 60 | * Get the format class name 61 | * 62 | * @return null|string 63 | */ 64 | public function get($name) 65 | { 66 | return !empty($this->formats[$name]) ? $this->formats[$name] : null; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # Todo 2 | ## Tests 3 | * Reference response definition 4 | * Explicitely reference response definition 5 | 6 | ## Document 7 | * `x-...` on AbstractObject context 8 | 9 | ## Code 10 | * Internal redesign of `handleCommand` Do a `handleStatement` instead. 11 | * Command to move to `swagger` context; `goto`? 12 | * Aliases for force global parameters and/or responses. 13 | * Exception; record statement source 14 | * Add full Schema-level type support for response headers. 15 | * Options to enable/disable comment types. 16 | * Option to specify comment command prefix. `rest` or `@rest\`. 17 | * Ordering options for tags and/or paths and/or operations; sort according to list for tags 18 | * Parse and reference functions 19 | * Rethink pre-function comment(s); add to function/method or class? 20 | * Type alias/extension system 21 | * Command aliassing system. 22 | * Command line interface. Netbeans integration. 23 | * Use different mechanism for preprocessor: `#` or such prefix 24 | * Standardize the Parser interface; `parseFile()`, `parseText()`, defines 25 | * Add text preprocessor 26 | 27 | ## Non-OpenAPI features 28 | * `@rest\type definition typename` to define new "builtin" types on the fly. 29 | * Global parameter definitions that are applied to all operations. This mostly 30 | applies to `query` parameters. Perhaps `globalquery` et al. 31 | * Add more builtin regex-based types; `ipv4`, `ipv6`, `ip` (any kind), `url`, 32 | `uri`, `ftp`, `http`, `https`, `email` 33 | 34 | ## Swagger 35 | * Full Type support in Swagger\Header object 36 | * Use (optional) Namespaces in `@see` and `@uses` 37 | * Set type (array of enumerated strings; can force unique?) 38 | * License: full/formatted names 39 | * Date(-time) format helpers; if no timezone, add 'Z'. Use PHP Date parser. 40 | * Support object `additionalProperties` 41 | * Implement `allOf` annotation 42 | * Shortcut "get", "put", etc. operation methods as proper commands. 43 | * Force correct defaults on models. [See issue](https://github.com/swagger-api/swagger-ui/issues/2436) 44 | * Implement `required` in `Schema` for object properties. (JSON Schema, p.12) 45 | * Add command aliasses `tag`, `scheme`, `consumes` and `produces` in `Operations`. 46 | 47 | ## Quality 48 | * Parsers; pass state object instead of keeping state in parser objects properties. 49 | * PHP: Cache previously parsed files; do not re-parse? 50 | * PSR-* compliance 51 | * Document comment structure in classes; before/in/after class/method/function 52 | * Scrutinizer perfection 53 | 54 | ## Validations 55 | * `body` and `formData` Parameters cannot exist in single Operation. 56 | * `path` Parameters must reference part of Path. 57 | * For `oauth2` security, check scopes in `require` and vice versa. 58 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vanderlee/swaggergen", 3 | "description": "Generate Swagger/OpenAPI documentation from simple PHPdoc-like comments in PHP source code.", 4 | "type": "library", 5 | "keywords": ["swagger", "openapi", "doc", "documentation", "rest", "api", "documentor", "comments", "generate", "generator"], 6 | "homepage": "https://github.com/vanderlee/PHPSwaggerGen", 7 | "license": "MIT", 8 | "support": { 9 | "issues": "https://github.com/vanderlee/PHPSwaggerGen/issues", 10 | "source": "https://github.com/vanderlee/PHPSwaggerGen/" 11 | }, 12 | "require": { 13 | "php": ">=7.1.0", 14 | "ext-json": "*", 15 | "ext-tokenizer": "*", 16 | "ext-filter": "*", 17 | "ext-mbstring": "*" 18 | }, 19 | "suggest": { 20 | "ext-yaml": "Allows producing Swagger docs in Yaml format" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "SwaggerGen\\": "SwaggerGen/" 25 | } 26 | }, 27 | "require-dev": { 28 | "phpunit/phpunit": "^9.5" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/api/.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | 3 | RewriteCond %{REQUEST_FILENAME} !-f 4 | RewriteRule ^(.*)$ example.php?endpoint=$1 [QSA,L] -------------------------------------------------------------------------------- /example/api/autoloader.php: -------------------------------------------------------------------------------- 1 | request($method, $path, $data); 13 | 14 | header('Content-Type: application/json'); 15 | echo json_encode($result, JSON_NUMERIC_CHECK); 16 | } catch (Exception $e) { 17 | header('HTTP/1.0 ' . $e->getCode() . ' ' . $e->getMessage()); 18 | } 19 | -------------------------------------------------------------------------------- /example/api/swagger.php: -------------------------------------------------------------------------------- 1 | add(Ipv4Type::class); 14 | 15 | $SwaggerGen = new SwaggerGen($_SERVER['HTTP_HOST'], dirname($_SERVER['REQUEST_URI'])); 16 | $SwaggerGen->setTypeRegistry($TypeRegistry); 17 | try { 18 | $json = $SwaggerGen->getSwagger($files, [], SwaggerGen::FORMAT_JSON_PRETTY); 19 | } catch (SwaggerException $e) { 20 | var_dump($e); 21 | } 22 | 23 | header('Content-type: application/json'); 24 | echo $json; 25 | -------------------------------------------------------------------------------- /example/docs/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */ 2 | html, 3 | body, 4 | div, 5 | span, 6 | applet, 7 | object, 8 | iframe, 9 | h1, 10 | h2, 11 | h3, 12 | h4, 13 | h5, 14 | h6, 15 | p, 16 | blockquote, 17 | pre, 18 | a, 19 | abbr, 20 | acronym, 21 | address, 22 | big, 23 | cite, 24 | code, 25 | del, 26 | dfn, 27 | em, 28 | img, 29 | ins, 30 | kbd, 31 | q, 32 | s, 33 | samp, 34 | small, 35 | strike, 36 | strong, 37 | sub, 38 | sup, 39 | tt, 40 | var, 41 | b, 42 | u, 43 | i, 44 | center, 45 | dl, 46 | dt, 47 | dd, 48 | ol, 49 | ul, 50 | li, 51 | fieldset, 52 | form, 53 | label, 54 | legend, 55 | table, 56 | caption, 57 | tbody, 58 | tfoot, 59 | thead, 60 | tr, 61 | th, 62 | td, 63 | article, 64 | aside, 65 | canvas, 66 | details, 67 | embed, 68 | figure, 69 | figcaption, 70 | footer, 71 | header, 72 | hgroup, 73 | menu, 74 | nav, 75 | output, 76 | ruby, 77 | section, 78 | summary, 79 | time, 80 | mark, 81 | audio, 82 | video { 83 | margin: 0; 84 | padding: 0; 85 | border: 0; 86 | font-size: 100%; 87 | font: inherit; 88 | vertical-align: baseline; 89 | } 90 | /* HTML5 display-role reset for older browsers */ 91 | article, 92 | aside, 93 | details, 94 | figcaption, 95 | figure, 96 | footer, 97 | header, 98 | hgroup, 99 | menu, 100 | nav, 101 | section { 102 | display: block; 103 | } 104 | body { 105 | line-height: 1; 106 | } 107 | ol, 108 | ul { 109 | list-style: none; 110 | } 111 | blockquote, 112 | q { 113 | quotes: none; 114 | } 115 | blockquote:before, 116 | blockquote:after, 117 | q:before, 118 | q:after { 119 | content: ''; 120 | content: none; 121 | } 122 | table { 123 | border-collapse: collapse; 124 | border-spacing: 0; 125 | } 126 | -------------------------------------------------------------------------------- /example/docs/css/typography.css: -------------------------------------------------------------------------------- 1 | /* Google Font's Droid Sans */ 2 | @font-face { 3 | font-family: 'Droid Sans'; 4 | font-style: normal; 5 | font-weight: 400; 6 | src: local('Droid Sans'), local('DroidSans'), url('../fonts/DroidSans.ttf') format('truetype'); 7 | } 8 | /* Google Font's Droid Sans Bold */ 9 | @font-face { 10 | font-family: 'Droid Sans'; 11 | font-style: normal; 12 | font-weight: 700; 13 | src: local('Droid Sans Bold'), local('DroidSans-Bold'), url('../fonts/DroidSans-Bold.ttf') format('truetype'); 14 | } 15 | -------------------------------------------------------------------------------- /example/docs/fonts/DroidSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/fonts/DroidSans-Bold.ttf -------------------------------------------------------------------------------- /example/docs/fonts/DroidSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/fonts/DroidSans.ttf -------------------------------------------------------------------------------- /example/docs/images/explorer_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/explorer_icons.png -------------------------------------------------------------------------------- /example/docs/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/favicon-16x16.png -------------------------------------------------------------------------------- /example/docs/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/favicon-32x32.png -------------------------------------------------------------------------------- /example/docs/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/favicon.ico -------------------------------------------------------------------------------- /example/docs/images/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/logo_small.png -------------------------------------------------------------------------------- /example/docs/images/pet_store_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/pet_store_api.png -------------------------------------------------------------------------------- /example/docs/images/throbber.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/throbber.gif -------------------------------------------------------------------------------- /example/docs/images/wordnik_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vanderlee/PHPSwaggerGen/a6cc581896994799d3e79d943b392021f985d064/example/docs/images/wordnik_api.png -------------------------------------------------------------------------------- /example/docs/lang/en.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Warning: Deprecated", 6 | "Implementation Notes":"Implementation Notes", 7 | "Response Class":"Response Class", 8 | "Status":"Status", 9 | "Parameters":"Parameters", 10 | "Parameter":"Parameter", 11 | "Value":"Value", 12 | "Description":"Description", 13 | "Parameter Type":"Parameter Type", 14 | "Data Type":"Data Type", 15 | "Response Messages":"Response Messages", 16 | "HTTP Status Code":"HTTP Status Code", 17 | "Reason":"Reason", 18 | "Response Model":"Response Model", 19 | "Request URL":"Request URL", 20 | "Response Body":"Response Body", 21 | "Response Code":"Response Code", 22 | "Response Headers":"Response Headers", 23 | "Hide Response":"Hide Response", 24 | "Headers":"Headers", 25 | "Try it out!":"Try it out!", 26 | "Show/Hide":"Show/Hide", 27 | "List Operations":"List Operations", 28 | "Expand Operations":"Expand Operations", 29 | "Raw":"Raw", 30 | "can't parse JSON. Raw result":"can't parse JSON. Raw result", 31 | "Model Schema":"Model Schema", 32 | "Model":"Model", 33 | "apply":"apply", 34 | "Username":"Username", 35 | "Password":"Password", 36 | "Terms of service":"Terms of service", 37 | "Created by":"Created by", 38 | "See more at":"See more at", 39 | "Contact the developer":"Contact the developer", 40 | "api version":"api version", 41 | "Response Content Type":"Response Content Type", 42 | "fetching resource":"fetching resource", 43 | "fetching resource list":"fetching resource list", 44 | "Explore":"Explore", 45 | "Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Can't read from server. It may not have the appropriate access-control-origin settings.", 47 | "Please specify the protocol for":"Please specify the protocol for", 48 | "Can't read swagger JSON from":"Can't read swagger JSON from", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Finished Loading Resource Information. Rendering Swagger UI", 50 | "Unable to read api":"Unable to read api", 51 | "from path":"from path", 52 | "server returned":"server returned" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lang/es.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Advertencia: Obsoleto", 6 | "Implementation Notes":"Notas de implementación", 7 | "Response Class":"Clase de la Respuesta", 8 | "Status":"Status", 9 | "Parameters":"Parámetros", 10 | "Parameter":"Parámetro", 11 | "Value":"Valor", 12 | "Description":"Descripción", 13 | "Parameter Type":"Tipo del Parámetro", 14 | "Data Type":"Tipo del Dato", 15 | "Response Messages":"Mensajes de la Respuesta", 16 | "HTTP Status Code":"Código de Status HTTP", 17 | "Reason":"Razón", 18 | "Response Model":"Modelo de la Respuesta", 19 | "Request URL":"URL de la Solicitud", 20 | "Response Body":"Cuerpo de la Respuesta", 21 | "Response Code":"Código de la Respuesta", 22 | "Response Headers":"Encabezados de la Respuesta", 23 | "Hide Response":"Ocultar Respuesta", 24 | "Try it out!":"Pruébalo!", 25 | "Show/Hide":"Mostrar/Ocultar", 26 | "List Operations":"Listar Operaciones", 27 | "Expand Operations":"Expandir Operaciones", 28 | "Raw":"Crudo", 29 | "can't parse JSON. Raw result":"no puede parsear el JSON. Resultado crudo", 30 | "Model Schema":"Esquema del Modelo", 31 | "Model":"Modelo", 32 | "apply":"aplicar", 33 | "Username":"Nombre de usuario", 34 | "Password":"Contraseña", 35 | "Terms of service":"Términos de Servicio", 36 | "Created by":"Creado por", 37 | "See more at":"Ver más en", 38 | "Contact the developer":"Contactar al desarrollador", 39 | "api version":"versión de la api", 40 | "Response Content Type":"Tipo de Contenido (Content Type) de la Respuesta", 41 | "fetching resource":"buscando recurso", 42 | "fetching resource list":"buscando lista del recurso", 43 | "Explore":"Explorar", 44 | "Show Swagger Petstore Example Apis":"Mostrar Api Ejemplo de Swagger Petstore", 45 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"No se puede leer del servidor. Tal vez no tiene la configuración de control de acceso de origen (access-control-origin) apropiado.", 46 | "Please specify the protocol for":"Por favor, especificar el protocola para", 47 | "Can't read swagger JSON from":"No se puede leer el JSON de swagger desde", 48 | "Finished Loading Resource Information. Rendering Swagger UI":"Finalizada la carga del recurso de Información. Mostrando Swagger UI", 49 | "Unable to read api":"No se puede leer la api", 50 | "from path":"desde ruta", 51 | "server returned":"el servidor retornó" 52 | }); 53 | -------------------------------------------------------------------------------- /example/docs/lang/fr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Avertissement : Obsolète", 6 | "Implementation Notes":"Notes d'implementation", 7 | "Response Class":"Classe de la réponse", 8 | "Status":"Statut", 9 | "Parameters":"Paramètres", 10 | "Parameter":"Paramètre", 11 | "Value":"Valeur", 12 | "Description":"Description", 13 | "Parameter Type":"Type du paramètre", 14 | "Data Type":"Type de données", 15 | "Response Messages":"Messages de la réponse", 16 | "HTTP Status Code":"Code de statut HTTP", 17 | "Reason":"Raison", 18 | "Response Model":"Modèle de réponse", 19 | "Request URL":"URL appelée", 20 | "Response Body":"Corps de la réponse", 21 | "Response Code":"Code de la réponse", 22 | "Response Headers":"En-têtes de la réponse", 23 | "Hide Response":"Cacher la réponse", 24 | "Headers":"En-têtes", 25 | "Try it out!":"Testez !", 26 | "Show/Hide":"Afficher/Masquer", 27 | "List Operations":"Liste des opérations", 28 | "Expand Operations":"Développer les opérations", 29 | "Raw":"Brut", 30 | "can't parse JSON. Raw result":"impossible de décoder le JSON. Résultat brut", 31 | "Model Schema":"Définition du modèle", 32 | "Model":"Modèle", 33 | "apply":"appliquer", 34 | "Username":"Nom d'utilisateur", 35 | "Password":"Mot de passe", 36 | "Terms of service":"Conditions de service", 37 | "Created by":"Créé par", 38 | "See more at":"Voir plus sur", 39 | "Contact the developer":"Contacter le développeur", 40 | "api version":"version de l'api", 41 | "Response Content Type":"Content Type de la réponse", 42 | "fetching resource":"récupération de la ressource", 43 | "fetching resource list":"récupération de la liste de ressources", 44 | "Explore":"Explorer", 45 | "Show Swagger Petstore Example Apis":"Montrer les Apis de l'exemple Petstore de Swagger", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Impossible de lire à partir du serveur. Il se peut que les réglages access-control-origin ne soient pas appropriés.", 47 | "Please specify the protocol for":"Veuillez spécifier un protocole pour", 48 | "Can't read swagger JSON from":"Impossible de lire le JSON swagger à partir de", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Chargement des informations terminé. Affichage de Swagger UI", 50 | "Unable to read api":"Impossible de lire l'api", 51 | "from path":"à partir du chemin", 52 | "server returned":"réponse du serveur" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lang/it.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Attenzione: Deprecato", 6 | "Implementation Notes":"Note di implementazione", 7 | "Response Class":"Classe della risposta", 8 | "Status":"Stato", 9 | "Parameters":"Parametri", 10 | "Parameter":"Parametro", 11 | "Value":"Valore", 12 | "Description":"Descrizione", 13 | "Parameter Type":"Tipo di parametro", 14 | "Data Type":"Tipo di dato", 15 | "Response Messages":"Messaggi della risposta", 16 | "HTTP Status Code":"Codice stato HTTP", 17 | "Reason":"Motivo", 18 | "Response Model":"Modello di risposta", 19 | "Request URL":"URL della richiesta", 20 | "Response Body":"Corpo della risposta", 21 | "Response Code":"Oggetto della risposta", 22 | "Response Headers":"Intestazioni della risposta", 23 | "Hide Response":"Nascondi risposta", 24 | "Try it out!":"Provalo!", 25 | "Show/Hide":"Mostra/Nascondi", 26 | "List Operations":"Mostra operazioni", 27 | "Expand Operations":"Espandi operazioni", 28 | "Raw":"Grezzo (raw)", 29 | "can't parse JSON. Raw result":"non è possibile parsare il JSON. Risultato grezzo (raw).", 30 | "Model Schema":"Schema del modello", 31 | "Model":"Modello", 32 | "apply":"applica", 33 | "Username":"Nome utente", 34 | "Password":"Password", 35 | "Terms of service":"Condizioni del servizio", 36 | "Created by":"Creato da", 37 | "See more at":"Informazioni aggiuntive:", 38 | "Contact the developer":"Contatta lo sviluppatore", 39 | "api version":"versione api", 40 | "Response Content Type":"Tipo di contenuto (content type) della risposta", 41 | "fetching resource":"recuperando la risorsa", 42 | "fetching resource list":"recuperando lista risorse", 43 | "Explore":"Esplora", 44 | "Show Swagger Petstore Example Apis":"Mostra le api di esempio di Swagger Petstore", 45 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Non è possibile leggere dal server. Potrebbe non avere le impostazioni di controllo accesso origine (access-control-origin) appropriate.", 46 | "Please specify the protocol for":"Si prega di specificare il protocollo per", 47 | "Can't read swagger JSON from":"Impossibile leggere JSON swagger da:", 48 | "Finished Loading Resource Information. Rendering Swagger UI":"Lettura informazioni risorse termianta. Swagger UI viene mostrata", 49 | "Unable to read api":"Impossibile leggere la api", 50 | "from path":"da cartella", 51 | "server returned":"il server ha restituito" 52 | }); 53 | -------------------------------------------------------------------------------- /example/docs/lang/ja.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"警告: 廃止予定", 6 | "Implementation Notes":"実装メモ", 7 | "Response Class":"レスポンスクラス", 8 | "Status":"ステータス", 9 | "Parameters":"パラメータ群", 10 | "Parameter":"パラメータ", 11 | "Value":"値", 12 | "Description":"説明", 13 | "Parameter Type":"パラメータタイプ", 14 | "Data Type":"データタイプ", 15 | "Response Messages":"レスポンスメッセージ", 16 | "HTTP Status Code":"HTTPステータスコード", 17 | "Reason":"理由", 18 | "Response Model":"レスポンスモデル", 19 | "Request URL":"リクエストURL", 20 | "Response Body":"レスポンスボディ", 21 | "Response Code":"レスポンスコード", 22 | "Response Headers":"レスポンスヘッダ", 23 | "Hide Response":"レスポンスを隠す", 24 | "Headers":"ヘッダ", 25 | "Try it out!":"実際に実行!", 26 | "Show/Hide":"表示/非表示", 27 | "List Operations":"操作一覧", 28 | "Expand Operations":"操作の展開", 29 | "Raw":"Raw", 30 | "can't parse JSON. Raw result":"JSONへ解釈できません. 未加工の結果", 31 | "Model Schema":"モデルスキーマ", 32 | "Model":"モデル", 33 | "apply":"実行", 34 | "Username":"ユーザ名", 35 | "Password":"パスワード", 36 | "Terms of service":"サービス利用規約", 37 | "Created by":"Created by", 38 | "See more at":"See more at", 39 | "Contact the developer":"開発者に連絡", 40 | "api version":"APIバージョン", 41 | "Response Content Type":"レスポンス コンテンツタイプ", 42 | "fetching resource":"リソースの取得", 43 | "fetching resource list":"リソース一覧の取得", 44 | "Explore":"Explore", 45 | "Show Swagger Petstore Example Apis":"SwaggerペットストアAPIの表示", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"サーバから読み込めません. 適切なaccess-control-origin設定を持っていない可能性があります.", 47 | "Please specify the protocol for":"プロトコルを指定してください", 48 | "Can't read swagger JSON from":"次からswagger JSONを読み込めません", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"リソース情報の読み込みが完了しました. Swagger UIを描画しています", 50 | "Unable to read api":"APIを読み込めません", 51 | "from path":"次のパスから", 52 | "server returned":"サーバからの返答" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lang/pt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Aviso: Depreciado", 6 | "Implementation Notes":"Notas de Implementação", 7 | "Response Class":"Classe de resposta", 8 | "Status":"Status", 9 | "Parameters":"Parâmetros", 10 | "Parameter":"Parâmetro", 11 | "Value":"Valor", 12 | "Description":"Descrição", 13 | "Parameter Type":"Tipo de parâmetro", 14 | "Data Type":"Tipo de dados", 15 | "Response Messages":"Mensagens de resposta", 16 | "HTTP Status Code":"Código de status HTTP", 17 | "Reason":"Razão", 18 | "Response Model":"Modelo resposta", 19 | "Request URL":"URL requisição", 20 | "Response Body":"Corpo da resposta", 21 | "Response Code":"Código da resposta", 22 | "Response Headers":"Cabeçalho da resposta", 23 | "Headers":"Cabeçalhos", 24 | "Hide Response":"Esconder resposta", 25 | "Try it out!":"Tente agora!", 26 | "Show/Hide":"Mostrar/Esconder", 27 | "List Operations":"Listar operações", 28 | "Expand Operations":"Expandir operações", 29 | "Raw":"Cru", 30 | "can't parse JSON. Raw result":"Falha ao analisar JSON. Resulto cru", 31 | "Model Schema":"Modelo esquema", 32 | "Model":"Modelo", 33 | "apply":"Aplicar", 34 | "Username":"Usuário", 35 | "Password":"Senha", 36 | "Terms of service":"Termos do serviço", 37 | "Created by":"Criado por", 38 | "See more at":"Veja mais em", 39 | "Contact the developer":"Contate o desenvolvedor", 40 | "api version":"Versão api", 41 | "Response Content Type":"Tipo de conteúdo da resposta", 42 | "fetching resource":"busca recurso", 43 | "fetching resource list":"buscando lista de recursos", 44 | "Explore":"Explorar", 45 | "Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Não é possível ler do servidor. Pode não ter as apropriadas configurações access-control-origin", 47 | "Please specify the protocol for":"Por favor especifique o protocolo", 48 | "Can't read swagger JSON from":"Não é possível ler o JSON Swagger de", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Carregar informação de recurso finalizada. Renderizando Swagger UI", 50 | "Unable to read api":"Não foi possível ler api", 51 | "from path":"do caminho", 52 | "server returned":"servidor retornou" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lang/ru.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Ворнинг: Депрекейтед", 6 | "Implementation Notes":"Заметки", 7 | "Response Class":"Пример ответа", 8 | "Status":"Статус", 9 | "Parameters":"Параметры", 10 | "Parameter":"Параметр", 11 | "Value":"Значение", 12 | "Description":"Описание", 13 | "Parameter Type":"Тип параметра", 14 | "Data Type":"Тип данных", 15 | "HTTP Status Code":"HTTP код", 16 | "Reason":"Причина", 17 | "Response Model":"Структура ответа", 18 | "Request URL":"URL запроса", 19 | "Response Body":"Тело ответа", 20 | "Response Code":"HTTP код ответа", 21 | "Response Headers":"Заголовки ответа", 22 | "Hide Response":"Спрятать ответ", 23 | "Response Messages":"Что может прийти в ответ", 24 | "Try it out!":"Попробовать!", 25 | "Show/Hide":"Показать/Скрыть", 26 | "List Operations":"Операции кратко", 27 | "Expand Operations":"Операции подробно", 28 | "Raw":"В сыром виде", 29 | "can't parse JSON. Raw result":"Не удается распарсить ответ:", 30 | "Model Schema":"Структура", 31 | "Model":"Описание", 32 | "apply":"применить", 33 | "Username":"Имя пользователя", 34 | "Password":"Пароль", 35 | "Terms of service":"Условия использования", 36 | "Created by":"Разработано", 37 | "See more at":"Еще тут", 38 | "Contact the developer":"Связаться с разработчиком", 39 | "api version":"Версия API", 40 | "Response Content Type":"Content Type ответа", 41 | "fetching resource":"Получение ресурса", 42 | "fetching resource list":"Получение ресурсов", 43 | "Explore":"Поехали", 44 | "Show Swagger Petstore Example Apis":"Показать примеры АПИ", 45 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Не удается получить ответ от сервера. Возможно, какая-то лажа с настройками доступа", 46 | "Please specify the protocol for":"Пожалуйста, укажите протогол для", 47 | "Can't read swagger JSON from":"Не получается прочитать swagger json из", 48 | "Finished Loading Resource Information. Rendering Swagger UI":"Загрузка информации о ресурсах завершена. Рендерим", 49 | "Unable to read api":"Не удалось прочитать api", 50 | "from path":"по адресу", 51 | "server returned":"сервер сказал" 52 | }); 53 | -------------------------------------------------------------------------------- /example/docs/lang/tr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"Uyarı: Deprecated", 6 | "Implementation Notes":"Gerçekleştirim Notları", 7 | "Response Class":"Dönen Sınıf", 8 | "Status":"Statü", 9 | "Parameters":"Parametreler", 10 | "Parameter":"Parametre", 11 | "Value":"Değer", 12 | "Description":"Açıklama", 13 | "Parameter Type":"Parametre Tipi", 14 | "Data Type":"Veri Tipi", 15 | "Response Messages":"Dönüş Mesajı", 16 | "HTTP Status Code":"HTTP Statü Kodu", 17 | "Reason":"Gerekçe", 18 | "Response Model":"Dönüş Modeli", 19 | "Request URL":"İstek URL", 20 | "Response Body":"Dönüş İçeriği", 21 | "Response Code":"Dönüş Kodu", 22 | "Response Headers":"Dönüş Üst Bilgileri", 23 | "Hide Response":"Dönüşü Gizle", 24 | "Headers":"Üst Bilgiler", 25 | "Try it out!":"Dene!", 26 | "Show/Hide":"Göster/Gizle", 27 | "List Operations":"Operasyonları Listele", 28 | "Expand Operations":"Operasyonları Aç", 29 | "Raw":"Ham", 30 | "can't parse JSON. Raw result":"JSON çözümlenemiyor. Ham sonuç", 31 | "Model Schema":"Model Şema", 32 | "Model":"Model", 33 | "apply":"uygula", 34 | "Username":"Kullanıcı Adı", 35 | "Password":"Parola", 36 | "Terms of service":"Servis şartları", 37 | "Created by":"Oluşturan", 38 | "See more at":"Daha fazlası için", 39 | "Contact the developer":"Geliştirici ile İletişime Geçin", 40 | "api version":"api versiyon", 41 | "Response Content Type":"Dönüş İçerik Tipi", 42 | "fetching resource":"kaynak getiriliyor", 43 | "fetching resource list":"kaynak listesi getiriliyor", 44 | "Explore":"Keşfet", 45 | "Show Swagger Petstore Example Apis":"Swagger Petstore Örnek Api'yi Gör", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"Sunucudan okuma yapılamıyor. Sunucu access-control-origin ayarlarınızı kontrol edin.", 47 | "Please specify the protocol for":"Lütfen istenen adres için protokol belirtiniz", 48 | "Can't read swagger JSON from":"Swagger JSON bu kaynaktan okunamıyor", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"Kaynak baglantısı tamamlandı. Swagger UI gösterime hazırlanıyor", 50 | "Unable to read api":"api okunamadı", 51 | "from path":"yoldan", 52 | "server returned":"sunucuya dönüldü" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lang/translator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Translator for documentation pages. 5 | * 6 | * To enable translation you should include one of language-files in your index.html 7 | * after . 8 | * For example - 9 | * 10 | * If you wish to translate some new texsts you should do two things: 11 | * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. 12 | * 2. Mark that text it templates this way New Phrase or . 13 | * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate. 14 | * 15 | */ 16 | window.SwaggerTranslator = { 17 | 18 | _words:[], 19 | 20 | translate: function(sel) { 21 | var $this = this; 22 | sel = sel || '[data-sw-translate]'; 23 | 24 | $(sel).each(function() { 25 | $(this).html($this._tryTranslate($(this).html())); 26 | 27 | $(this).val($this._tryTranslate($(this).val())); 28 | $(this).attr('title', $this._tryTranslate($(this).attr('title'))); 29 | }); 30 | }, 31 | 32 | _tryTranslate: function(word) { 33 | return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word; 34 | }, 35 | 36 | learn: function(wordsMap) { 37 | this._words = wordsMap; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /example/docs/lang/zh-cn.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* jshint quotmark: double */ 4 | window.SwaggerTranslator.learn({ 5 | "Warning: Deprecated":"警告:已过时", 6 | "Implementation Notes":"实现备注", 7 | "Response Class":"响应类", 8 | "Status":"状态", 9 | "Parameters":"参数", 10 | "Parameter":"参数", 11 | "Value":"值", 12 | "Description":"描述", 13 | "Parameter Type":"参数类型", 14 | "Data Type":"数据类型", 15 | "Response Messages":"响应消息", 16 | "HTTP Status Code":"HTTP状态码", 17 | "Reason":"原因", 18 | "Response Model":"响应模型", 19 | "Request URL":"请求URL", 20 | "Response Body":"响应体", 21 | "Response Code":"响应码", 22 | "Response Headers":"响应头", 23 | "Hide Response":"隐藏响应", 24 | "Headers":"头", 25 | "Try it out!":"试一下!", 26 | "Show/Hide":"显示/隐藏", 27 | "List Operations":"显示操作", 28 | "Expand Operations":"展开操作", 29 | "Raw":"原始", 30 | "can't parse JSON. Raw result":"无法解析JSON. 原始结果", 31 | "Model Schema":"模型架构", 32 | "Model":"模型", 33 | "apply":"应用", 34 | "Username":"用户名", 35 | "Password":"密码", 36 | "Terms of service":"服务条款", 37 | "Created by":"创建者", 38 | "See more at":"查看更多:", 39 | "Contact the developer":"联系开发者", 40 | "api version":"api版本", 41 | "Response Content Type":"响应Content Type", 42 | "fetching resource":"正在获取资源", 43 | "fetching resource list":"正在获取资源列表", 44 | "Explore":"浏览", 45 | "Show Swagger Petstore Example Apis":"显示 Swagger Petstore 示例 Apis", 46 | "Can't read from server. It may not have the appropriate access-control-origin settings.":"无法从服务器读取。可能没有正确设置access-control-origin。", 47 | "Please specify the protocol for":"请指定协议:", 48 | "Can't read swagger JSON from":"无法读取swagger JSON于", 49 | "Finished Loading Resource Information. Rendering Swagger UI":"已加载资源信息。正在渲染Swagger UI", 50 | "Unable to read api":"无法读取api", 51 | "from path":"从路径", 52 | "server returned":"服务器返回" 53 | }); 54 | -------------------------------------------------------------------------------- /example/docs/lib/jquery.ba-bbq.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010 3 | * http://benalman.com/projects/jquery-bbq-plugin/ 4 | * 5 | * Copyright (c) 2010 "Cowboy" Ben Alman 6 | * Dual licensed under the MIT and GPL licenses. 7 | * http://benalman.com/about/license/ 8 | */ 9 | (function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this); -------------------------------------------------------------------------------- /example/docs/lib/jquery.slideto.min.js: -------------------------------------------------------------------------------- 1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery); 2 | -------------------------------------------------------------------------------- /example/docs/lib/jquery.wiggle.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | jQuery Wiggle 3 | Author: WonderGroup, Jordan Thomas 4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html 5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License) 6 | */ 7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('
').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);} 8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});}; -------------------------------------------------------------------------------- /example/docs/o2c.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/Base/PHPUnit5.php: -------------------------------------------------------------------------------- 1 | expectException('\SwaggerGen\Exception'); 12 | 13 | throw new \SwaggerGen\Exception('', 0); 14 | } 15 | 16 | /** 17 | * @covers \SwaggerGen\Exception::__construct 18 | */ 19 | public function testConstructor1() 20 | { 21 | $this->expectException('\SwaggerGen\Exception', 'This is a message'); 22 | 23 | throw new \SwaggerGen\Exception('This is a message', 0); 24 | } 25 | 26 | /** 27 | * @covers \SwaggerGen\Exception::__construct 28 | */ 29 | public function testConstructor2() 30 | { 31 | $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234); 32 | 33 | throw new \SwaggerGen\Exception('This is a message', 1234); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/Parser/Php/ParserTest/testParse_AfterClass.php: -------------------------------------------------------------------------------- 1 | Method 16 | */ 17 | public function Dummy() 18 | { 19 | 20 | } 21 | 22 | } 23 | 24 | class testParse_SeeInheritedThisMethod_Other_Super 25 | { 26 | 27 | /** 28 | * @rest\error 400 29 | */ 30 | private function Method() 31 | { 32 | 33 | } 34 | 35 | } 36 | 37 | class testParse_SeeInheritedThisMethod_Other extends testParse_SeeInheritedThisMethod_Other_Super 38 | { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tests/Parser/Php/ParserTest/testParse_SeeInheritedThisMethod.php: -------------------------------------------------------------------------------- 1 | Method 16 | */ 17 | public function Dummy() 18 | { 19 | 20 | } 21 | 22 | } 23 | 24 | class testParse_SeeInheritedThisMethod_Super 25 | { 26 | 27 | /** 28 | * @rest\error 400 29 | */ 30 | private function Method() 31 | { 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/Parser/Php/ParserTest/testParse_SeeObjectMethod.php: -------------------------------------------------------------------------------- 1 | Method 16 | */ 17 | public function Dummy() 18 | { 19 | 20 | } 21 | 22 | } 23 | 24 | class testParse_SeeObjectMethod_Other 25 | { 26 | 27 | /** 28 | * @rest\error 400 29 | */ 30 | private function Method() 31 | { 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/Parser/Php/ParserTest/testParse_SeeSelfMethod.php: -------------------------------------------------------------------------------- 1 | Method 24 | */ 25 | public function Dummy() 26 | { 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tests/Parser/Php/ParserTest/testParse_StaticMethod.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('\SwaggerGen\Statement', $object); 14 | $this->assertSame('command', $object->getCommand()); 15 | $this->assertSame('some data', $object->getData()); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Statement::__construct 20 | */ 21 | public function testConstructor_File() 22 | { 23 | $object = new \SwaggerGen\Statement('command', 'some data', 'file', 123); 24 | $this->assertInstanceOf('\SwaggerGen\Statement', $object); 25 | 26 | $this->assertSame('command', $object->getCommand()); 27 | $this->assertSame('some data', $object->getData()); 28 | $this->assertSame('file', $object->getFile()); 29 | $this->assertSame(123, $object->getLine()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Swagger/AbstractDocumentableObjectTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Tag::__construct 20 | * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand 21 | */ 22 | public function testCommandDocWithoutDescription() 23 | { 24 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); 25 | 26 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 27 | 28 | $this->assertSame(array( 29 | 'name' => 'Name', 30 | ), $object->toArray()); 31 | 32 | $object->handleCommand('doc', 'http://example.test'); 33 | 34 | $this->assertSame(array( 35 | 'name' => 'Name', 36 | 'externalDocs' => array( 37 | 'url' => 'http://example.test', 38 | ), 39 | ), $object->toArray()); 40 | } 41 | 42 | /** 43 | * @covers \SwaggerGen\Swagger\Tag::__construct 44 | * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand 45 | */ 46 | public function testCommandDocWithDescription() 47 | { 48 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); 49 | 50 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 51 | 52 | $this->assertSame(array( 53 | 'name' => 'Name', 54 | ), $object->toArray()); 55 | 56 | $object->handleCommand('doc', 'http://example.test Some words here'); 57 | 58 | $this->assertSame(array( 59 | 'name' => 'Name', 60 | 'externalDocs' => array( 61 | 'url' => 'http://example.test', 62 | 'description' => 'Some words here', 63 | ), 64 | ), $object->toArray()); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /tests/Swagger/AbstractObjectTest.php: -------------------------------------------------------------------------------- 1 | assertSame('quite', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 14 | $this->assertSame('a few words', $text); 15 | 16 | $this->assertSame('a', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 17 | $this->assertSame('few words', $text); 18 | 19 | $this->assertSame('few', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 20 | $this->assertSame('words', $text); 21 | 22 | $this->assertSame('words', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 23 | $this->assertSame('', $text); 24 | 25 | $this->assertSame(false, \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 26 | $this->assertSame('', $text); 27 | } 28 | 29 | /** 30 | * @covers \SwaggerGen\Swagger\AbstractObject::words_shift 31 | */ 32 | public function testWords_shift_whitespace() 33 | { 34 | $text = " quite a\nfew \r \n\r words \t"; 35 | 36 | $this->assertSame('quite', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 37 | $this->assertSame('a', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 38 | $this->assertSame('few', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 39 | $this->assertSame('words', \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 40 | $this->assertSame(false, \SwaggerGen\Swagger\AbstractObject::wordShift($text)); 41 | $this->assertSame('', $text); 42 | } 43 | 44 | /** 45 | * @covers \SwaggerGen\Swagger\AbstractObject::mb_trim 46 | */ 47 | public function testMb_trim() 48 | { 49 | $this->assertSame('trimmed', \SwaggerGen\Swagger\AbstractObject::trim("trimmed")); 50 | $this->assertSame('trimmed', \SwaggerGen\Swagger\AbstractObject::trim("trimmed ")); 51 | $this->assertSame('trimmed', \SwaggerGen\Swagger\AbstractObject::trim(" trimmed")); 52 | $this->assertSame('trimmed', \SwaggerGen\Swagger\AbstractObject::trim(" trimmed ")); 53 | $this->assertSame('trimmed', \SwaggerGen\Swagger\AbstractObject::trim("\n \t trimmed \f \r")); 54 | } 55 | 56 | /** 57 | * @covers \SwaggerGen\Swagger\AbstractObject::toArray 58 | */ 59 | public function testToArray() 60 | { 61 | $object = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 62 | 63 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $object); 64 | 65 | $this->assertSame(array(), $object->toArray()); 66 | } 67 | 68 | /** 69 | * @covers \SwaggerGen\Swagger\AbstractObject::handleCommand 70 | */ 71 | public function testCommandExtensions() 72 | { 73 | $object = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 74 | 75 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $object); 76 | 77 | $object->handleCommand('x-someTag', 'some value'); 78 | $object->handleCommand('x-anyTag', 'any value'); 79 | 80 | $this->assertSame(array( 81 | 'x-someTag' => 'some value', 82 | 'x-anyTag' => 'any value', 83 | ), $object->toArray()); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /tests/Swagger/ContactTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Contact::__construct 20 | */ 21 | public function testConstructorEmpty() 22 | { 23 | $object = new \SwaggerGen\Swagger\Contact($this->parent); 24 | 25 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 26 | 27 | $this->assertSame(array(), $object->toArray()); 28 | } 29 | 30 | /** 31 | * @covers \SwaggerGen\Swagger\Contact::__construct 32 | */ 33 | public function testConstructorName() 34 | { 35 | $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name'); 36 | 37 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 38 | 39 | $this->assertSame(array( 40 | 'name' => 'Name', 41 | ), $object->toArray()); 42 | } 43 | 44 | /** 45 | * @covers \SwaggerGen\Swagger\Contact::__construct 46 | */ 47 | public function testConstructorUrl() 48 | { 49 | $object = new \SwaggerGen\Swagger\Contact($this->parent, null, 'http://example.com'); 50 | 51 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 52 | 53 | $this->assertSame(array( 54 | 'url' => 'http://example.com', 55 | ), $object->toArray()); 56 | } 57 | 58 | /** 59 | * @covers \SwaggerGen\Swagger\Contact::__construct 60 | */ 61 | public function testConstructorEmail() 62 | { 63 | $object = new \SwaggerGen\Swagger\Contact($this->parent, null, null, 'test@example.com'); 64 | 65 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 66 | 67 | $this->assertSame(array( 68 | 'email' => 'test@example.com', 69 | ), $object->toArray()); 70 | } 71 | 72 | /** 73 | * @covers \SwaggerGen\Swagger\Contact::handleCommand 74 | */ 75 | public function testCommandName() 76 | { 77 | $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', 'test@example.com'); 78 | 79 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 80 | 81 | $object->handleCommand('name', 'Somebody'); 82 | 83 | $this->assertSame(array( 84 | 'name' => 'Somebody', 85 | 'url' => 'http://example.com', 86 | 'email' => 'test@example.com', 87 | ), $object->toArray()); 88 | } 89 | 90 | /** 91 | * @covers \SwaggerGen\Swagger\Contact::handleCommand 92 | */ 93 | public function testCommandUrl() 94 | { 95 | $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', 'test@example.com'); 96 | 97 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 98 | 99 | $object->handleCommand('url', 'http://site.test'); 100 | 101 | $this->assertSame(array( 102 | 'name' => 'Name', 103 | 'url' => 'http://site.test', 104 | 'email' => 'test@example.com', 105 | ), $object->toArray()); 106 | } 107 | 108 | /** 109 | * @covers \SwaggerGen\Swagger\Contact::handleCommand 110 | */ 111 | public function testCommandEmail() 112 | { 113 | $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', 'test@example.com'); 114 | 115 | $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); 116 | 117 | $object->handleCommand('email', 'somebody@somewhere.test'); 118 | 119 | $this->assertSame(array( 120 | 'name' => 'Name', 121 | 'url' => 'http://example.com', 122 | 'email' => 'somebody@somewhere.test', 123 | ), $object->toArray()); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /tests/Swagger/ErrorTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Error::__construct 20 | */ 21 | public function testConstructor_200(): void 22 | { 23 | $object = new \SwaggerGen\Swagger\Error($this->parent, 200); 24 | 25 | $this->assertInstanceOf('\SwaggerGen\Swagger\Error', $object); 26 | 27 | $this->assertSame(array( 28 | 'description' => 'OK', 29 | ), $object->toArray()); 30 | } 31 | 32 | /** 33 | * @covers \SwaggerGen\Swagger\Error::__construct 34 | */ 35 | public function testConstructor_404(): void 36 | { 37 | $object = new \SwaggerGen\Swagger\Error($this->parent, 404); 38 | 39 | $this->assertInstanceOf('\SwaggerGen\Swagger\Error', $object); 40 | 41 | $this->assertSame(array( 42 | 'description' => 'Not Found', 43 | ), $object->toArray()); 44 | } 45 | 46 | /** 47 | * @covers \SwaggerGen\Swagger\Error::__construct 48 | */ 49 | public function testConstructor_Description(): void 50 | { 51 | $object = new \SwaggerGen\Swagger\Error($this->parent, '200', 'Fine And Dandy'); 52 | 53 | $this->assertInstanceOf('\SwaggerGen\Swagger\Error', $object); 54 | 55 | $this->assertSame(array( 56 | 'description' => 'Fine And Dandy', 57 | ), $object->toArray()); 58 | } 59 | 60 | /** 61 | * Just checks that the `header` command is inherited. Actual tests for 62 | * this command are in `ResponseTest` 63 | * @covers \SwaggerGen\Swagger\Type\Error->handleCommand 64 | */ 65 | public function testHandleCommand_Header(): void 66 | { 67 | $object = new \SwaggerGen\Swagger\Error($this->parent, 200); 68 | 69 | $this->assertInstanceOf('\SwaggerGen\Swagger\Error', $object); 70 | 71 | $object->handleCommand('header', 'integer bar'); 72 | 73 | $this->assertSame(array( 74 | 'description' => 'OK', 75 | 'headers' => array( 76 | 'bar' => array( 77 | 'type' => 'integer', 78 | ), 79 | ), 80 | ), $object->toArray()); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /tests/Swagger/ExternalDocumentationTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\ExternalDocumentation::__construct 20 | */ 21 | public function testConstructorUrl(): void 22 | { 23 | $object = new \SwaggerGen\Swagger\ExternalDocumentation($this->parent, 'http://example.test'); 24 | 25 | $this->assertInstanceOf('\SwaggerGen\Swagger\ExternalDocumentation', $object); 26 | 27 | $this->assertSame(array( 28 | 'url' => 'http://example.test', 29 | ), $object->toArray()); 30 | } 31 | 32 | /** 33 | * @covers \SwaggerGen\Swagger\ExternalDocumentation::__construct 34 | */ 35 | public function testConstructorFull() 36 | { 37 | $object = new \SwaggerGen\Swagger\ExternalDocumentation($this->parent, 'http://example.test', 'Descriptive text'); 38 | 39 | $this->assertInstanceOf('\SwaggerGen\Swagger\ExternalDocumentation', $object); 40 | 41 | $this->assertSame(array( 42 | 'url' => 'http://example.test', 43 | 'description' => 'Descriptive text', 44 | ), $object->toArray()); 45 | } 46 | 47 | /** 48 | * @covers \SwaggerGen\Swagger\ExternalDocumentation::handleCommand 49 | */ 50 | public function testCommandUrl() 51 | { 52 | $object = new \SwaggerGen\Swagger\ExternalDocumentation($this->parent, 'http://example.test', 'Descriptive text'); 53 | 54 | $this->assertInstanceOf('\SwaggerGen\Swagger\ExternalDocumentation', $object); 55 | 56 | $object->handleCommand('url', 'http://other.test'); 57 | 58 | $this->assertSame(array( 59 | 'url' => 'http://other.test', 60 | 'description' => 'Descriptive text', 61 | ), $object->toArray()); 62 | } 63 | 64 | /** 65 | * @covers \SwaggerGen\Swagger\ExternalDocumentation::handleCommand 66 | */ 67 | public function testCommandDescription() 68 | { 69 | $object = new \SwaggerGen\Swagger\ExternalDocumentation($this->parent, 'http://example.test', 'Descriptive text'); 70 | 71 | $this->assertInstanceOf('\SwaggerGen\Swagger\ExternalDocumentation', $object); 72 | 73 | $object->handleCommand('description', 'Some other words'); 74 | 75 | $this->assertSame(array( 76 | 'url' => 'http://example.test', 77 | 'description' => 'Some other words', 78 | ), $object->toArray()); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /tests/Swagger/HeaderTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Header::__construct 20 | */ 21 | public function testConstructorType(): void 22 | { 23 | $object = new \SwaggerGen\Swagger\Header($this->parent, 'integer'); 24 | 25 | $this->assertInstanceOf('\SwaggerGen\Swagger\Header', $object); 26 | 27 | $this->assertSame(array( 28 | 'type' => 'integer', 29 | ), $object->toArray()); 30 | } 31 | 32 | /** 33 | * @covers \SwaggerGen\Swagger\Header::__construct 34 | */ 35 | public function testConstructorInvalidType() 36 | { 37 | $this->expectException('\SwaggerGen\Exception', "Header type not valid: 'BadType'"); 38 | 39 | new \SwaggerGen\Swagger\Header($this->parent, 'BadType'); 40 | } 41 | 42 | /** 43 | * @covers \SwaggerGen\Swagger\Header::__construct 44 | */ 45 | public function testConstructorNoDescription() 46 | { 47 | $object = new \SwaggerGen\Swagger\Header($this->parent, 'integer'); 48 | 49 | $this->assertInstanceOf('\SwaggerGen\Swagger\Header', $object); 50 | 51 | $this->assertSame(array( 52 | 'type' => 'integer', 53 | ), $object->toArray()); 54 | } 55 | 56 | /** 57 | * @covers \SwaggerGen\Swagger\Header::__construct 58 | */ 59 | public function testConstructorBlankDescription() 60 | { 61 | $object = new \SwaggerGen\Swagger\Header($this->parent, 'integer', ''); 62 | 63 | $this->assertInstanceOf('\SwaggerGen\Swagger\Header', $object); 64 | 65 | $this->assertSame(array( 66 | 'type' => 'integer', 67 | ), $object->toArray()); 68 | } 69 | 70 | /** 71 | * @covers \SwaggerGen\Swagger\Header::__construct 72 | */ 73 | public function testConstructorFull() 74 | { 75 | $object = new \SwaggerGen\Swagger\Header($this->parent, 'integer', 'descriptive text'); 76 | 77 | $this->assertInstanceOf('\SwaggerGen\Swagger\Header', $object); 78 | 79 | $this->assertSame(array( 80 | 'type' => 'integer', 81 | 'description' => 'descriptive text', 82 | ), $object->toArray()); 83 | } 84 | 85 | /** 86 | * @covers \SwaggerGen\Swagger\Header->handleCommand 87 | */ 88 | public function testCommandDescription() 89 | { 90 | $object = new \SwaggerGen\Swagger\Header($this->parent, 'integer', 'descriptive text'); 91 | 92 | $this->assertInstanceOf('\SwaggerGen\Swagger\Header', $object); 93 | 94 | $object->handleCommand('description', 'Some other lines'); 95 | 96 | $this->assertSame(array( 97 | 'type' => 'integer', 98 | 'description' => 'Some other lines', 99 | ), $object->toArray()); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /tests/Swagger/LicenseTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\License::__construct 20 | * @covers \SwaggerGen\Swagger\License::toArray 21 | */ 22 | public function testConstructor2Unknown(): void 23 | { 24 | $object = new \SwaggerGen\Swagger\License($this->parent, 'Name'); 25 | 26 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 27 | 28 | $this->assertSame(array( 29 | 'name' => 'Name', 30 | ), $object->toArray()); 31 | } 32 | 33 | /** 34 | * @covers \SwaggerGen\Swagger\License::__construct 35 | * @covers \SwaggerGen\Swagger\License::toArray 36 | */ 37 | public function testConstructor2Known() 38 | { 39 | $object = new \SwaggerGen\Swagger\License($this->parent, 'MIT'); 40 | 41 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 42 | 43 | $this->assertSame(array( 44 | 'name' => 'MIT', 45 | 'url' => 'http://opensource.org/licenses/MIT', 46 | ), $object->toArray()); 47 | } 48 | 49 | /** 50 | * @covers \SwaggerGen\Swagger\License::__construct 51 | * @covers \SwaggerGen\Swagger\License::toArray 52 | */ 53 | public function testConstructor3Unknown() 54 | { 55 | $object = new \SwaggerGen\Swagger\License($this->parent, 'Name', 'http://example'); 56 | 57 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 58 | 59 | $this->assertSame(array( 60 | 'name' => 'Name', 61 | 'url' => 'http://example', 62 | ), $object->toArray()); 63 | } 64 | 65 | /** 66 | * @covers \SwaggerGen\Swagger\License::__construct 67 | * @covers \SwaggerGen\Swagger\License::toArray 68 | */ 69 | public function testConstructor3Known() 70 | { 71 | $object = new \SwaggerGen\Swagger\License($this->parent, 'MIT', 'http://example'); 72 | 73 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 74 | 75 | $this->assertSame(array( 76 | 'name' => 'MIT', 77 | 'url' => 'http://example', 78 | ), $object->toArray()); 79 | } 80 | 81 | /** 82 | * @covers \SwaggerGen\Swagger\Tag::handleCommand 83 | */ 84 | public function testCommandName() 85 | { 86 | $object = new \SwaggerGen\Swagger\License($this->parent, 'MIT'); 87 | 88 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 89 | 90 | $object->handleCommand('name', 'GPL-3'); 91 | 92 | $this->assertSame(array( 93 | 'name' => 'GPL-3', 94 | 'url' => 'http://opensource.org/licenses/MIT', 95 | ), $object->toArray()); 96 | } 97 | 98 | /** 99 | * @covers \SwaggerGen\Swagger\Tag::handleCommand 100 | */ 101 | public function testCommandUrl() 102 | { 103 | $object = new \SwaggerGen\Swagger\License($this->parent, 'MIT'); 104 | 105 | $this->assertInstanceOf('\SwaggerGen\Swagger\License', $object); 106 | 107 | $object->handleCommand('url', 'http://example'); 108 | 109 | $this->assertSame(array( 110 | 'name' => 'MIT', 111 | 'url' => 'http://example', 112 | ), $object->toArray()); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /tests/Swagger/TagTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Tag::__construct 20 | * @covers \SwaggerGen\Swagger\License::toArray 21 | */ 22 | public function testConstructor2() 23 | { 24 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); 25 | 26 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 27 | 28 | $this->assertSame(array( 29 | 'name' => 'Name', 30 | ), $object->toArray()); 31 | } 32 | 33 | /** 34 | * @covers \SwaggerGen\Swagger\Tag::__construct 35 | * @covers \SwaggerGen\Swagger\License::toArray 36 | */ 37 | public function testConstructor_Description_Empty() 38 | { 39 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name', ''); 40 | 41 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 42 | 43 | $this->assertSame(array( 44 | 'name' => 'Name', 45 | ), $object->toArray()); 46 | } 47 | 48 | /** 49 | * @covers \SwaggerGen\Swagger\Tag::__construct 50 | * @covers \SwaggerGen\Swagger\License::toArray 51 | */ 52 | public function testConstructor3() 53 | { 54 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name', 'Description'); 55 | 56 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 57 | 58 | $this->assertSame(array( 59 | 'name' => 'Name', 60 | 'description' => 'Description', 61 | ), $object->toArray()); 62 | } 63 | 64 | /** 65 | * @covers \SwaggerGen\Swagger\Tag::getName 66 | */ 67 | public function testGetName() 68 | { 69 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); 70 | 71 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 72 | 73 | $this->assertSame('Name', $object->getName()); 74 | } 75 | 76 | /** 77 | * @covers \SwaggerGen\Swagger\Tag::handleCommand 78 | */ 79 | public function testCommandDescription() 80 | { 81 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); 82 | 83 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 84 | 85 | $object->handleCommand('description', 'Command Description'); 86 | 87 | $this->assertSame(array( 88 | 'name' => 'Name', 89 | 'description' => 'Command Description', 90 | ), $object->toArray()); 91 | } 92 | 93 | /** 94 | * @covers \SwaggerGen\Swagger\Tag::handleCommand 95 | */ 96 | public function testCommandDescriptionOverwrite() 97 | { 98 | $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name', 'Description'); 99 | 100 | $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); 101 | 102 | $object->handleCommand('description', 'Command Description'); 103 | 104 | $this->assertSame(array( 105 | 'name' => 'Name', 106 | 'description' => 'Command Description', 107 | ), $object->toArray()); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /tests/Swagger/Type/AbstractTypeTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\AbstractType::__construct 20 | */ 21 | public function testConstruct() 22 | { 23 | $stub = $this->getMockForAbstractClass('SwaggerGen\Swagger\Type\AbstractType', array( 24 | $this->parent, 25 | 'whatever' 26 | )); 27 | 28 | $this->assertFalse($stub->handleCommand('x-extra', 'whatever')); 29 | } 30 | 31 | /** 32 | * @covers \SwaggerGen\Swagger\Type\AbstractType->handleCommand 33 | */ 34 | public function testCommand_Example() 35 | { 36 | $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); 37 | 38 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); 39 | 40 | $object->handleCommand('example', 'foo'); 41 | 42 | $this->assertSame(array( 43 | 'type' => 'string', 44 | 'example' => 'foo', 45 | ), $object->toArray()); 46 | } 47 | 48 | /** 49 | * @covers \SwaggerGen\Swagger\Type\AbstractType->handleCommand 50 | */ 51 | public function testCommand_Example_Json() 52 | { 53 | $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); 54 | 55 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); 56 | 57 | $object->handleCommand('example', '{foo:bar}'); 58 | 59 | $this->assertSame(array( 60 | 'type' => 'string', 61 | 'example' => array( 62 | 'foo' => 'bar', 63 | ), 64 | ), $object->toArray()); 65 | } 66 | 67 | /** 68 | * @covers \SwaggerGen\Swagger\Type\AbstractType->handleCommand 69 | */ 70 | public function testCommand_Example_Json_Multiple_Properties() 71 | { 72 | $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); 73 | 74 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); 75 | 76 | $object->handleCommand('example', '{foo:bar,baz:bat}'); 77 | 78 | $this->assertSame(array( 79 | 'type' => 'string', 80 | 'example' => array( 81 | 'foo' => 'bar', 82 | 'baz' => 'bat', 83 | ), 84 | ), $object->toArray()); 85 | } 86 | 87 | /** 88 | * @covers \SwaggerGen\Swagger\Type\AbstractType->handleCommand 89 | */ 90 | public function testCommand_Example_Json_String_With_Special_Chars() 91 | { 92 | $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); 93 | 94 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); 95 | 96 | $object->handleCommand('example', '"2019-01-01 17:59:59"'); 97 | 98 | $this->assertSame(array( 99 | 'type' => 'string', 100 | 'example' => '2019-01-01 17:59:59', 101 | ), $object->toArray()); 102 | } 103 | 104 | /** 105 | * @covers \SwaggerGen\Swagger\Type\AbstractType->handleCommand 106 | */ 107 | public function testCommand_Example_Invalid_Json_Not_Ignored() 108 | { 109 | $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); 110 | 111 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); 112 | 113 | $object->handleCommand('example', '2019-01-01{}'); 114 | 115 | $this->assertSame(array( 116 | 'type' => 'string', 117 | 'example' => '2019-01-01{}', 118 | ), $object->toArray()); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /tests/Swagger/Type/Custom/EmailTypeTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 20 | */ 21 | public function testConstructNotAnEmail() 22 | { 23 | $this->expectException('\SwaggerGen\Exception', "Not an email: 'wrong'"); 24 | 25 | new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'wrong'); 26 | } 27 | 28 | /** 29 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 30 | */ 31 | public function testConstruct() 32 | { 33 | $object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); 34 | 35 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); 36 | 37 | $this->assertSame(array( 38 | 'type' => 'string', 39 | 'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, 40 | ), $object->toArray()); 41 | } 42 | 43 | /** 44 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 45 | */ 46 | public function testConstructEmptyDefault() 47 | { 48 | $this->expectException('\SwaggerGen\Exception', "Unparseable email definition: 'email='"); 49 | 50 | new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email= '); 51 | } 52 | 53 | /** 54 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 55 | */ 56 | public function testConstructDefaultDoubleAt() 57 | { 58 | $this->expectException('\SwaggerGen\Exception', "Invalid email default value: 'test@test@test.test'"); 59 | 60 | new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email=test@test@test.test'); 61 | } 62 | 63 | /** 64 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 65 | */ 66 | public function testConstructDefaultUntrimmed() 67 | { 68 | $this->expectException('\SwaggerGen\Exception', "Invalid email default value: ' test@test.test'"); 69 | 70 | new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email= test@test.test'); 71 | } 72 | 73 | /** 74 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType::__construct 75 | */ 76 | public function testConstructDefault() 77 | { 78 | $object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email=test@test.test'); 79 | 80 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); 81 | 82 | $this->assertSame(array( 83 | 'type' => 'string', 84 | 'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, 85 | 'default' => 'test@test.test', 86 | ), $object->toArray()); 87 | } 88 | 89 | /** 90 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType->handleCommand 91 | */ 92 | public function testCommandDefaultNoValue() 93 | { 94 | $object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); 95 | 96 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); 97 | 98 | $this->expectException('\SwaggerGen\Exception', "Empty email default"); 99 | $object->handleCommand('default', ''); 100 | } 101 | 102 | /** 103 | * @covers \SwaggerGen\Swagger\Type\Custom\EmailType->handleCommand 104 | */ 105 | public function testCommandDefault() 106 | { 107 | $object = new SwaggerGen\Swagger\Type\Custom\EmailType($this->parent, 'email'); 108 | 109 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Custom\EmailType', $object); 110 | 111 | $object->handleCommand('default', 'test@test.test'); 112 | 113 | $this->assertSame(array( 114 | 'type' => 'string', 115 | 'pattern' => \SwaggerGen\Swagger\Type\Custom\EmailType::PATTERN, 116 | 'default' => 'test@test.test', 117 | ), $object->toArray()); 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /tests/Swagger/Type/FileTypeTest.php: -------------------------------------------------------------------------------- 1 | parent = new \SwaggerGen\Swagger\Swagger; 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 20 | */ 21 | public function testConstructNotAFile() 22 | { 23 | $this->expectException('\SwaggerGen\Exception', "Not a file: 'wrong'"); 24 | 25 | $object = new SwaggerGen\Swagger\Type\FileType($this->parent, 'wrong'); 26 | } 27 | 28 | /** 29 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 30 | */ 31 | public function testConstructNotParameter() 32 | { 33 | $this->expectException('\SwaggerGen\Exception', "File type 'file' only allowed on form parameter"); 34 | 35 | $object = new SwaggerGen\Swagger\Type\FileType($this->parent, 'file'); 36 | } 37 | 38 | /** 39 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 40 | */ 41 | public function testConstructNotFormParameter() 42 | { 43 | $this->expectException('\SwaggerGen\Exception', "File type 'file' only allowed on form parameter"); 44 | 45 | $parameter = new SwaggerGen\Swagger\Parameter($this->parent, 'query', 'long whatever'); 46 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 47 | } 48 | 49 | /** 50 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 51 | */ 52 | public function testConstructNoFormConsumes() 53 | { 54 | $this->expectException('\SwaggerGen\Exception', "File type 'file' without valid consume"); 55 | 56 | $operation = new SwaggerGen\Swagger\Operation($this->parent); 57 | $operation->handleCommand('consumes', 'text'); 58 | $parameter = new SwaggerGen\Swagger\Parameter($operation, 'form', 'long whatever'); 59 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 60 | } 61 | 62 | /** 63 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 64 | */ 65 | public function testConstructNotExclusiveFormConsumes() 66 | { 67 | $this->expectException('\SwaggerGen\Exception', "File type 'file' without valid consume"); 68 | 69 | $operation = new SwaggerGen\Swagger\Operation($this->parent); 70 | $operation->handleCommand('consumes', 'text file'); 71 | $parameter = new SwaggerGen\Swagger\Parameter($operation, 'form', 'long whatever'); 72 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 73 | } 74 | 75 | /** 76 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 77 | */ 78 | public function testConstructFormConsumes() 79 | { 80 | $operation = new SwaggerGen\Swagger\Operation($this->parent); 81 | $operation->handleCommand('consumes', 'form'); 82 | $parameter = new SwaggerGen\Swagger\Parameter($operation, 'form', 'long whatever'); 83 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 84 | } 85 | 86 | /** 87 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 88 | */ 89 | public function testConstructFileformConsumes() 90 | { 91 | $operation = new SwaggerGen\Swagger\Operation($this->parent); 92 | $operation->handleCommand('consumes', 'fileform'); 93 | $parameter = new SwaggerGen\Swagger\Parameter($operation, 'form', 'long whatever'); 94 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 95 | } 96 | 97 | /** 98 | * @covers \SwaggerGen\Swagger\Type\FileType::__construct 99 | */ 100 | public function testConstructBothConsumes() 101 | { 102 | $operation = new SwaggerGen\Swagger\Operation($this->parent); 103 | $operation->handleCommand('consumes', 'fileform form'); 104 | $parameter = new SwaggerGen\Swagger\Parameter($operation, 'form', 'long whatever'); 105 | $object = new SwaggerGen\Swagger\Type\FileType($parameter, 'file'); 106 | 107 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\FileType', $object); 108 | 109 | $this->assertSame(array( 110 | 'type' => 'file', 111 | ), $object->toArray()); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /tests/Swagger/Type/ReferenceObjectTypeTest.php: -------------------------------------------------------------------------------- 1 | parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); 11 | } 12 | 13 | protected function assertPreConditions(): void 14 | { 15 | $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); 16 | } 17 | 18 | /** 19 | * @covers \SwaggerGen\Swagger\Type\ReferenceObjectType::__construct 20 | */ 21 | public function testConstructBothConsumes() 22 | { 23 | $this->parent->handleCommand('model', 'blah'); 24 | 25 | $object = new SwaggerGen\Swagger\Type\ReferenceObjectType($this->parent, 'blah'); 26 | 27 | $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ReferenceObjectType', $object); 28 | 29 | $this->assertSame(array( 30 | '$ref' => '#/definitions/blah', 31 | ), $object->toArray()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | =')) { 27 | require dirname(__FILE__) . '/Base/PHPUnit7.php'; 28 | class_alias('Base_PHPUnit7', 'SwaggerGen_TestCase'); 29 | } else if (version_compare($version, '6.0.0', '>=')) { 30 | require dirname(__FILE__) . '/Base/PHPUnit6.php'; 31 | class_alias('Base_PHPUnit6', 'SwaggerGen_TestCase'); 32 | } else { 33 | require dirname(__FILE__) . '/Base/PHPUnit5.php'; 34 | class_alias('Base_PHPUnit5', 'SwaggerGen_TestCase'); 35 | } 36 | -------------------------------------------------------------------------------- /tests/issues/Issue0002Test.php: -------------------------------------------------------------------------------- 1 | getSwagger(array(' 14 | security api_key apikey X-Api-Authentication header 15 | require api_key 16 | api Test 17 | endpoint /test 18 | method GET something 19 | require api_key 20 | response 202 21 | ')); 22 | 23 | $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' 24 | . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' 25 | . ',"security":[{"api_key":[]}]}}},"securityDefinitions":{"api_key":{"type":"apiKey","name":"X-Api-Authentication","in":"header"}}' 26 | . ',"security":[{"api_key":[]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); 27 | } 28 | 29 | public function testRequireAsObjectWithScopes() 30 | { 31 | $object = new \SwaggerGen\SwaggerGen(); 32 | $array = $object->getSwagger(array(' 33 | security oauth oauth2 implicit http://www.test 34 | require oauth user:name 35 | api Test 36 | endpoint /test 37 | method GET something 38 | require oauth user:name 39 | response 202 40 | ')); 41 | 42 | $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' 43 | . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"202":{"description":"Accepted"}}' 44 | . ',"security":[{"oauth":["user:name"]}]}}},"securityDefinitions":{"oauth":{"type":"oauth2","flow":"implicit","authorizationUrl":"http:\/\/www.test"}}' 45 | . ',"security":[{"oauth":["user:name"]}],"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tests/issues/Issue0012Test.php: -------------------------------------------------------------------------------- 1 | getSwagger(array(' 14 | api Test 15 | endpoint /test 16 | method GET something 17 | response 200 object(modifications:array(ModificationHistory),users:array(User)) 18 | ')); 19 | 20 | $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' 21 | . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' 22 | . ',"responses":{"200":{"description":"OK","schema":{"type":"object","required":["modifications","users"]' 23 | . ',"properties":{"modifications":{"type":"array","items":{"$ref":"#\/definitions\/ModificationHistory"}}' 24 | . ',"users":{"type":"array","items":{"$ref":"#\/definitions\/User"}}}}}}}}}' 25 | . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/issues/Issue0015Test.php: -------------------------------------------------------------------------------- 1 | getSwagger(array(' 14 | api Test 15 | definition ClassName 16 | title ClassName 17 | property string type 18 | enum ClassName 19 | property int meaningOfLifeTheUniverseAndEverything 20 | enum 42 21 | endpoint /test 22 | method GET something 23 | response 204 24 | ')); 25 | 26 | $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' 27 | . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something","responses":{"204":{"description":"No Content"}}}}}' 28 | . ',"definitions":{"ClassName":{"type":"object","required":["type","meaningOfLifeTheUniverseAndEverything"],"properties":{"type":{"type":"string","enum":["ClassName"]},"meaningOfLifeTheUniverseAndEverything":{"type":"integer","format":"int32","enum":[42]}},"title":"ClassName"}}' 29 | . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tests/output/OutputTest.php: -------------------------------------------------------------------------------- 1 | getSwagger($files, array(), \SwaggerGen\SwaggerGen::FORMAT_JSON); 14 | $this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name); 15 | } 16 | 17 | /** 18 | * Normalizes and pretty-prints json (whitespace mostly) 19 | * 20 | * This is useful to get better diff results when assertions fail. 21 | * 22 | * @param string $json 23 | * @return string 24 | */ 25 | private function normalizeJson($json) 26 | { 27 | return json_encode( 28 | json_decode($json), 29 | PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0 30 | ); 31 | } 32 | 33 | public function provideAllCases() 34 | { 35 | $cases = array(); 36 | 37 | foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) { 38 | $path = realpath($dir); 39 | $json = $this->normalizeJson(file_get_contents($path . '/expected.json')); 40 | 41 | $files = array(); 42 | if (file_exists($path . '/source.php')) { 43 | $files[] = $path . '/source.php'; 44 | } 45 | if (file_exists($path . '/source.txt')) { 46 | $files[] = $path . '/source.txt'; 47 | } 48 | 49 | $cases[] = array( 50 | basename($dir), 51 | $files, 52 | $json 53 | ); 54 | } 55 | 56 | return $cases; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /tests/output/additionalProperties/source.txt: -------------------------------------------------------------------------------- 1 | model IdModel object(id:uuid) 2 | 3 | model AnyPropertiesAllowedInline object(...) 4 | 5 | model AnyPropertiesAllowedCommand object 6 | additionalproperties true 7 | 8 | model TypedPropertiesAllowedInline object(...integer) 9 | 10 | model TypedPropertiesAllowedCommand object 11 | additionalproperties integer 12 | 13 | model RefPropertiesAllowedInline object(...IdModel) 14 | 15 | model RefPropertiesAllowedCommand object 16 | additionalproperties IdModel 17 | 18 | model NoAdditionalPropertiesAllowedInline object(propName:integer,...!) 19 | 20 | model NoAdditionalPropertiesAllowedCommand object 21 | property integer propName 22 | additionalproperties false 23 | 24 | model MixedPropertiesAndAdditionalPropertiesInline object(propName:integer,...) 25 | 26 | model MixedPropertiesAndAdditionalPropertiesCommand object 27 | property integer propName 28 | additionalproperties true 29 | 30 | model MixedPropertiesAndTypedAdditionalPropertiesInline object(propName:integer,...string) 31 | 32 | model MixedPropertiesAndTypedAdditionalPropertiesCommand object 33 | property integer propName 34 | additionalproperties string 35 | 36 | model MixedPropertiesAndRefAdditionalPropertiesInline object(propName:integer,...IdModel) 37 | 38 | model MixedPropertiesAndRefAdditionalPropertiesCommand object 39 | property integer propName 40 | additionalproperties IdModel 41 | 42 | 43 | 44 | api Test 45 | 46 | endpoint /stub-see-definitions 47 | method GET 48 | response 200 integer 49 | -------------------------------------------------------------------------------- /tests/output/allOf in array/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "/base", 9 | "paths": { 10 | "/object": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#/definitions/someObject" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "objectWithArrayWithItems": { 28 | "type": "object", 29 | "required": [ 30 | "positiveArray" 31 | ], 32 | "properties": { 33 | "positiveArray": { 34 | "type": "array", 35 | "items": { 36 | "allOf": [ 37 | { 38 | "$ref": "#/definitions/IntegerNumber" 39 | }, 40 | { 41 | "type": "integer", 42 | "format": "int32", 43 | "minimum": 1 44 | } 45 | ] 46 | } 47 | } 48 | } 49 | }, 50 | "someObject": { 51 | "type": "object", 52 | "required": [ 53 | "positiveArray" 54 | ], 55 | "properties": { 56 | "positiveArray": { 57 | "type": "array", 58 | "items": { 59 | "allOf": [ 60 | { 61 | "$ref": "#/definitions/IntegerNumber" 62 | }, 63 | { 64 | "type": "integer", 65 | "format": "int32", 66 | "minimum": 1 67 | } 68 | ] 69 | } 70 | } 71 | } 72 | }, 73 | "IntegerNumber": { 74 | "type": "integer", 75 | "format": "int32" 76 | } 77 | }, 78 | "tags": [ 79 | { 80 | "name": "Test" 81 | } 82 | ] 83 | } 84 | -------------------------------------------------------------------------------- /tests/output/allOf in array/source.txt: -------------------------------------------------------------------------------- 1 | model IntegerNumber integer 2 | 3 | model someObject 4 | property array(allOf(IntegerNumber,integer[1,>)) positiveArray 5 | 6 | model objectWithArrayWithItems 7 | property array positiveArray 8 | items allOf(IntegerNumber) 9 | item integer[1,> 10 | 11 | api Test 12 | endpoint /object 13 | method GET 14 | response 200 someObject 15 | -------------------------------------------------------------------------------- /tests/output/allOf in model top level/source.txt: -------------------------------------------------------------------------------- 1 | model Id object(id:uuid) 2 | 3 | model CustomerRef allOf 4 | item Id 5 | item object 6 | discriminator type 7 | property string type 8 | enum Customer CustomerRef Person PersonRef Company CompanyRef 9 | 10 | model CustomerData object 11 | discriminator type 12 | property string address 13 | property string type 14 | enum Customer CustomerData Person PersonData Company CompanyData 15 | 16 | model Customer allOf 17 | item CustomerRef 18 | item CustomerData 19 | item object 20 | property string type 21 | enum Customer Person Company 22 | 23 | model PersonRef allOf 24 | item CustomerRef 25 | item object 26 | property string type 27 | enum Person PersonRef 28 | 29 | model PersonData allOf 30 | item CustomerData 31 | item object 32 | property string firstName 33 | property string lastName 34 | property string type 35 | enum Person PersonData 36 | 37 | model Person allOf 38 | item PersonRef 39 | item PersonData 40 | item object 41 | property string type 42 | enum Person 43 | 44 | model CompanyRef allOf(CustomerRef) 45 | item object 46 | property string type 47 | enum Company CompanyRef 48 | 49 | model CompanyData allOf 50 | item CustomerData 51 | item object(companyName:string) 52 | property string type 53 | enum Company CompanyData 54 | 55 | model Company allOf(CompanyRef,CompanyData) 56 | item object 57 | property string type 58 | enum Company 59 | 60 | api Test 61 | endpoint /customers 62 | method GET 63 | response 200 Customer 64 | -------------------------------------------------------------------------------- /tests/output/allOf in property/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "/base", 9 | "paths": { 10 | "/enum": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#/definitions/UsingEnum" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "WideEnum": { 28 | "type": "string", 29 | "enum": [ 30 | "1", 31 | "2", 32 | "3" 33 | ] 34 | }, 35 | "UsingEnum": { 36 | "type": "object", 37 | "required": [ 38 | "enumProperty" 39 | ], 40 | "properties": { 41 | "enumProperty": { 42 | "allOf": [ 43 | { 44 | "$ref": "#/definitions/WideEnum" 45 | }, 46 | { 47 | "type": "string", 48 | "enum": [ 49 | "2" 50 | ] 51 | } 52 | ] 53 | } 54 | } 55 | } 56 | }, 57 | "tags": [ 58 | { 59 | "name": "Test" 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /tests/output/allOf in property/source.txt: -------------------------------------------------------------------------------- 1 | model WideEnum enum(1,2,3) 2 | 3 | model UsingEnum 4 | property allof(WideEnum) enumProperty 5 | item string 6 | enum 2 7 | 8 | api Test 9 | endpoint /enum 10 | method GET 11 | response 200 UsingEnum 12 | -------------------------------------------------------------------------------- /tests/output/allOf in response/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "/base", 9 | "paths": { 10 | "/me": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "allOf": [ 20 | { 21 | "$ref": "#/definitions/Person" 22 | }, 23 | { 24 | "$ref": "#/definitions/Id" 25 | } 26 | ] 27 | } 28 | } 29 | } 30 | } 31 | } 32 | }, 33 | "definitions": { 34 | "Person": { 35 | "type": "object", 36 | "required": [ 37 | "firstName", 38 | "lastName" 39 | ], 40 | "properties": { 41 | "firstName": { 42 | "type": "string" 43 | }, 44 | "lastName": { 45 | "type": "string" 46 | } 47 | } 48 | }, 49 | "Id": { 50 | "type": "object", 51 | "required": [ 52 | "id" 53 | ], 54 | "properties": { 55 | "id": { 56 | "type": "string", 57 | "format": "uuid", 58 | "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$" 59 | } 60 | } 61 | } 62 | }, 63 | "tags": [ 64 | { 65 | "name": "Test" 66 | } 67 | ] 68 | } 69 | -------------------------------------------------------------------------------- /tests/output/allOf in response/source.txt: -------------------------------------------------------------------------------- 1 | model Id object 2 | property uuid id 3 | 4 | model Person object 5 | property string firstName 6 | property string lastName 7 | 8 | api Test 9 | endpoint /me 10 | method GET 11 | response 200 allOf(Person,Id) 12 | -------------------------------------------------------------------------------- /tests/output/docblock comment in method/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "UUID", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/v1/users/{id}": { 11 | "get": { 12 | "tags": [ 13 | "MyApi" 14 | ], 15 | "summary": "Return a JSON with all the user attributes", 16 | "parameters": [ 17 | { 18 | "name": "id", 19 | "in": "path", 20 | "required": true, 21 | "type": "integer", 22 | "format": "int32", 23 | "description": "The ID of the User" 24 | } 25 | ], 26 | "responses": { 27 | "200": { 28 | "description": "OK", 29 | "schema": { 30 | "$ref": "#\/definitions\/User" 31 | } 32 | } 33 | } 34 | } 35 | } 36 | }, 37 | "definitions": { 38 | "uuid": { 39 | "type": "object", 40 | "required": [ 41 | "ip", 42 | "path" 43 | ], 44 | "properties": { 45 | "ip": { 46 | "type": "string" 47 | }, 48 | "path": { 49 | "type": "string" 50 | } 51 | } 52 | } 53 | }, 54 | "tags": [ 55 | { 56 | "name": "MyApi", 57 | "description": "Example" 58 | } 59 | ] 60 | } -------------------------------------------------------------------------------- /tests/output/docblock comment in method/source.php: -------------------------------------------------------------------------------- 1 | get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) { 25 | // ... 26 | }); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /tests/output/global parameter/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "Minimal", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/endpoint\/{listid}": { 11 | "get": { 12 | "tags": [ 13 | "MyApi" 14 | ], 15 | "summary": "Something", 16 | "parameters": [ 17 | { 18 | "$ref": "#\/parameters\/listid" 19 | } 20 | ], 21 | "responses": { 22 | "200": { 23 | "description": "OK" 24 | } 25 | } 26 | } 27 | } 28 | }, 29 | "parameters": { 30 | "listid": { 31 | "name": "listid", 32 | "in": "path", 33 | "required": true, 34 | "type": "integer", 35 | "format": "int64", 36 | "minimum": 0 37 | } 38 | }, 39 | "tags": [ 40 | { 41 | "name": "MyApi", 42 | "description": "Example" 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /tests/output/global parameter/source.php: -------------------------------------------------------------------------------- 1 | listid 10 | */ 11 | class Example 12 | { 13 | 14 | /** 15 | * @rest\endpoint /endpoint/{listid} 16 | * @rest\method GET Something 17 | * @rest\param listid 18 | * @rest\response 200 19 | */ 20 | public function Dummy() 21 | { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/output/global response/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "Minimal", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/endpoint\/{listid}": { 11 | "get": { 12 | "tags": [ 13 | "MyApi" 14 | ], 15 | "summary": "Something", 16 | "parameters": [ 17 | { 18 | "$ref": "#\/parameters\/listid" 19 | } 20 | ], 21 | "responses": { 22 | "200": { 23 | "description": "OK" 24 | } 25 | } 26 | } 27 | } 28 | }, 29 | "parameters": { 30 | "listid": { 31 | "name": "listid", 32 | "in": "path", 33 | "required": true, 34 | "type": "integer", 35 | "format": "int64", 36 | "minimum": 0 37 | } 38 | }, 39 | "tags": [ 40 | { 41 | "name": "MyApi", 42 | "description": "Example" 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /tests/output/global response/source.php: -------------------------------------------------------------------------------- 1 | listid 10 | */ 11 | class Example 12 | { 13 | 14 | /** 15 | * @rest\endpoint /endpoint/{listid} 16 | * @rest\method GET Something 17 | * @rest\param listid 18 | * @rest\response 200 19 | */ 20 | public function Dummy() 21 | { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/output/preprocessor replace/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "Minimal", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/endpoint\/{listid}": { 11 | "get": { 12 | "tags": [ 13 | "MyApi" 14 | ], 15 | "summary": "Something", 16 | "parameters": [ 17 | { 18 | "$ref": "#\/parameters\/listid" 19 | } 20 | ], 21 | "responses": { 22 | "200": { 23 | "description": "OK" 24 | } 25 | } 26 | } 27 | } 28 | }, 29 | "parameters": { 30 | "listid": { 31 | "name": "listid", 32 | "in": "path", 33 | "required": true, 34 | "type": "integer", 35 | "format": "int64", 36 | "minimum": 0 37 | } 38 | }, 39 | "tags": [ 40 | { 41 | "name": "MyApi", 42 | "description": "Example" 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /tests/output/preprocessor replace/source.php: -------------------------------------------------------------------------------- 1 | listid 10 | */ 11 | class Example 12 | { 13 | 14 | /** 15 | * @rest\endpoint /endpoint/{listid} 16 | * @rest\method GET Something 17 | * @rest\ifndef skip 18 | * @rest\param listid 19 | * @rest\endif 20 | * @rest\response 200 21 | */ 22 | public function Dummy() 23 | { 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/output/readonly ref property/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/customers": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#\/definitions\/Person" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "Address": { 28 | "type": "object", 29 | "required": [ 30 | "city" 31 | ], 32 | "properties": { 33 | "city": { 34 | "type": "string" 35 | } 36 | } 37 | }, 38 | "Person": { 39 | "type": "object", 40 | "required": [ 41 | "name" 42 | ], 43 | "properties": { 44 | "name": { 45 | "type": "string" 46 | }, 47 | "home": { 48 | "allOf": [ 49 | { 50 | "$ref": "#\/definitions\/Address" 51 | } 52 | ], 53 | "readOnly": true 54 | } 55 | } 56 | } 57 | }, 58 | "tags": [ 59 | { 60 | "name": "Test" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /tests/output/readonly ref property/source.txt: -------------------------------------------------------------------------------- 1 | model Address 2 | property string city 3 | model Person 4 | property string name 5 | property! Address home 6 | api Test 7 | endpoint /customers 8 | method GET 9 | response 200 Person 10 | -------------------------------------------------------------------------------- /tests/output/reference array of models in model/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/customers": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#\/definitions\/Person" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "Address": { 28 | "type": "object", 29 | "required": [ 30 | "city" 31 | ], 32 | "properties": { 33 | "city": { 34 | "type": "string" 35 | } 36 | } 37 | }, 38 | "Person": { 39 | "type": "object", 40 | "required": [ 41 | "name", 42 | "home" 43 | ], 44 | "properties": { 45 | "name": { 46 | "type": "string" 47 | }, 48 | "home": { 49 | "type": "array", 50 | "items": { 51 | "$ref": "#\/definitions\/Address" 52 | } 53 | } 54 | } 55 | } 56 | }, 57 | "tags": [ 58 | { 59 | "name": "Test" 60 | } 61 | ] 62 | } -------------------------------------------------------------------------------- /tests/output/reference array of models in model/source.txt: -------------------------------------------------------------------------------- 1 | model Address 2 | property string city 3 | model Person 4 | property string name 5 | property array(Address) home 6 | api Test 7 | endpoint /customers 8 | method GET 9 | response 200 Person -------------------------------------------------------------------------------- /tests/output/reference model in array of models/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/customers": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "type": "array", 20 | "items": { 21 | "$ref": "#\/definitions\/Person" 22 | } 23 | } 24 | } 25 | } 26 | } 27 | } 28 | }, 29 | "definitions": { 30 | "Address": { 31 | "type": "object", 32 | "required": [ 33 | "city" 34 | ], 35 | "properties": { 36 | "city": { 37 | "type": "string" 38 | } 39 | } 40 | }, 41 | "Person": { 42 | "type": "object", 43 | "required": [ 44 | "name", 45 | "home" 46 | ], 47 | "properties": { 48 | "name": { 49 | "type": "string" 50 | }, 51 | "home": { 52 | "$ref": "#\/definitions\/Address" 53 | } 54 | } 55 | } 56 | }, 57 | "tags": [ 58 | { 59 | "name": "Test" 60 | } 61 | ] 62 | } -------------------------------------------------------------------------------- /tests/output/reference model in array of models/source.txt: -------------------------------------------------------------------------------- 1 | model Address 2 | property string city 3 | model Person 4 | property string name 5 | property Address home 6 | api Test 7 | endpoint /customers 8 | method GET 9 | response 200 array(Person) -------------------------------------------------------------------------------- /tests/output/reference model in model infinite/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/customers": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#\/definitions\/Person" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "Address": { 28 | "type": "object", 29 | "required": [ 30 | "city", 31 | "person" 32 | ], 33 | "properties": { 34 | "city": { 35 | "type": "string" 36 | }, 37 | "person": { 38 | "$ref": "#\/definitions\/Person" 39 | } 40 | } 41 | }, 42 | "Person": { 43 | "type": "object", 44 | "required": [ 45 | "name", 46 | "home" 47 | ], 48 | "properties": { 49 | "name": { 50 | "type": "string" 51 | }, 52 | "home": { 53 | "$ref": "#\/definitions\/Address" 54 | } 55 | } 56 | } 57 | }, 58 | "tags": [ 59 | { 60 | "name": "Test" 61 | } 62 | ] 63 | } -------------------------------------------------------------------------------- /tests/output/reference model in model infinite/source.txt: -------------------------------------------------------------------------------- 1 | model Address 2 | property string city 3 | property Person person 4 | model Person 5 | property string name 6 | property Address home 7 | api Test 8 | endpoint /customers 9 | method GET 10 | response 200 Person -------------------------------------------------------------------------------- /tests/output/reference model in model/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/customers": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "$ref": "#\/definitions\/Person" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | }, 26 | "definitions": { 27 | "Address": { 28 | "type": "object", 29 | "required": [ 30 | "city" 31 | ], 32 | "properties": { 33 | "city": { 34 | "type": "string" 35 | } 36 | } 37 | }, 38 | "Person": { 39 | "type": "object", 40 | "required": [ 41 | "name", 42 | "home" 43 | ], 44 | "properties": { 45 | "name": { 46 | "type": "string" 47 | }, 48 | "home": { 49 | "$ref": "#\/definitions\/Address" 50 | } 51 | } 52 | } 53 | }, 54 | "tags": [ 55 | { 56 | "name": "Test" 57 | } 58 | ] 59 | } -------------------------------------------------------------------------------- /tests/output/reference model in model/source.txt: -------------------------------------------------------------------------------- 1 | model Address 2 | property string city 3 | model Person 4 | property string name 5 | property Address home 6 | api Test 7 | endpoint /customers 8 | method GET 9 | response 200 Person -------------------------------------------------------------------------------- /tests/output/unbounded range/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "undefined", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "/base", 9 | "paths": { 10 | "/positive-integer": { 11 | "get": { 12 | "tags": [ 13 | "Test" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "OK", 18 | "schema": { 19 | "type": "integer", 20 | "format": "int32", 21 | "minimum": 1 22 | } 23 | } 24 | } 25 | } 26 | }, 27 | "/positive-number": { 28 | "get": { 29 | "tags": [ 30 | "Test" 31 | ], 32 | "responses": { 33 | "200": { 34 | "description": "OK", 35 | "schema": { 36 | "type": "number", 37 | "format": "float", 38 | "minimum": 1.1 39 | } 40 | } 41 | } 42 | } 43 | } 44 | }, 45 | "tags": [ 46 | { 47 | "name": "Test" 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /tests/output/unbounded range/source.txt: -------------------------------------------------------------------------------- 1 | api Test 2 | 3 | endpoint /positive-integer 4 | method GET 5 | response 200 int[1,> 6 | 7 | endpoint /positive-number 8 | method GET 9 | response 200 float[1.1,> 10 | -------------------------------------------------------------------------------- /tests/output/uuid model overwrite/expected.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "UUID", 5 | "version": "0" 6 | }, 7 | "host": "example.com", 8 | "basePath": "\/base", 9 | "paths": { 10 | "\/endpoint": { 11 | "get": { 12 | "tags": [ 13 | "MyApi" 14 | ], 15 | "summary": "Something", 16 | "responses": { 17 | "200": { 18 | "description": "OK", 19 | "schema": { 20 | "$ref": "#\/definitions\/uuid" 21 | } 22 | } 23 | } 24 | } 25 | } 26 | }, 27 | "definitions": { 28 | "uuid": { 29 | "type": "object", 30 | "required": [ 31 | "ip", 32 | "path" 33 | ], 34 | "properties": { 35 | "ip": { 36 | "type": "string" 37 | }, 38 | "path": { 39 | "type": "string" 40 | } 41 | } 42 | } 43 | }, 44 | "tags": [ 45 | { 46 | "name": "MyApi", 47 | "description": "Example" 48 | } 49 | ] 50 | } -------------------------------------------------------------------------------- /tests/output/uuid model overwrite/source.php: -------------------------------------------------------------------------------- 1 |