├── .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