Repository: GuilhemN/swagger
Branch: master
Commit: bdd3b68d1f8d
Files: 60
Total size: 120.5 KB
Directory structure:
gitextract_3xv09ez2/
├── .gitattributes
├── .gitignore
├── .php_cs.dist
├── .travis.yml
├── LICENSE
├── README.md
├── composer.json
├── phpunit
├── phpunit.xml.dist
├── src/
│ ├── AbstractModel.php
│ ├── Collections/
│ │ ├── Definitions.php
│ │ ├── Headers.php
│ │ ├── Parameters.php
│ │ ├── Paths.php
│ │ └── Responses.php
│ ├── Contact.php
│ ├── ExternalDocs.php
│ ├── Header.php
│ ├── Info.php
│ ├── Items.php
│ ├── License.php
│ ├── Operation.php
│ ├── Parameter.php
│ ├── Parts/
│ │ ├── ConsumesPart.php
│ │ ├── DescriptionPart.php
│ │ ├── ExtensionPart.php
│ │ ├── ExternalDocsPart.php
│ │ ├── ItemsPart.php
│ │ ├── ParametersPart.php
│ │ ├── ProducesPart.php
│ │ ├── RefPart.php
│ │ ├── RequiredPart.php
│ │ ├── ResponsesPart.php
│ │ ├── SchemaPart.php
│ │ ├── SchemesPart.php
│ │ ├── SecurityPart.php
│ │ ├── TagsPart.php
│ │ ├── TypePart.php
│ │ └── UrlPart.php
│ ├── Path.php
│ ├── Response.php
│ ├── Schema.php
│ ├── SecurityScheme.php
│ ├── Swagger.php
│ ├── Tag.php
│ └── Util/
│ └── MergeHelper.php
└── tests/
├── BasicAuthTest.php
├── CollectionsTest.php
├── KeekoTest.php
├── PetstoreTest.php
├── SwaggerTest.php
└── fixtures/
├── basic-auth.json
├── keeko-user.json
├── petstore-dictionaries.json
├── petstore-expanded.json
├── petstore-minimal.json
├── petstore-parameter-refs.json
├── petstore-simple.json
├── petstore-with-external-docs.json
└── petstore.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
.* export-ignore
*.md export-ignore
tests export-ignore
================================================
FILE: .gitignore
================================================
.buildpath
.php_cs.cache
composer.phar
composer.lock
phpunit.xml
vendor/
coverage/
================================================
FILE: .php_cs.dist
================================================
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('Tests/Functional/cache')
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'header_comment' => [
'header' => <<<HEADER
This file is part of the Swagger package.
(c) EXSyst
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
HEADER
],
])
->setFinder($finder)
;
================================================
FILE: .travis.yml
================================================
language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
sudo: false
cache:
directories:
- $HOME/.composer/cache
branches:
only:
- master
- /^\d+\.\d+$/
matrix:
fast_finish: true
include:
- php: 7.0
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.4
env: COMPOSER_FLAGS="--prefer-lowest"
before_install:
- composer self-update
install: composer update $COMPOSER_FLAGS
script: ./phpunit
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2015 Thomas Gossmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Swagger
[](https://travis-ci.org/GuilhemN/swagger)
[](https://scrutinizer-ci.com/g/EXSyst/Swagger)
[](https://scrutinizer-ci.com/g/EXSyst/Swagger)
A php library to manipulate [Swagger](http://Swagger.io)/[Open API](https://openapis.org) specifications.
## Installation
```
composer require EXSyst/Swagger
```
## Usage
Read an `api.json` file:
```php
$swagger = Swagger::fromFile('api.json');
// or
$swagger = new Swagger($array);
```
### Collections
There are two major collections: `Paths` and `Definitions`. The API is similar for both:
```php
$paths = $swagger->getPaths();
$p = new Path('/user');
foreach ($paths as $path) {
// adding
$paths->add($a);
// retrieving
if ($paths->has('/user') || $paths->contains($p)) {
$path = $paths->get('/user');
}
// removing
$paths->remove('/user');
}
```
### Models
There are a lot of models, e.g. the mentioned `Path` above. The API is well written, so it works with the auto-completion of your IDE. It is straight forward and uses the same naming scheme as the OpenAPI specification.
## Contributing
Feel free to fork and submit a pull request (don't forget the tests) and I am happy to merge.
================================================
FILE: composer.json
================================================
{
"name" : "exsyst/swagger",
"description" : "A php library to manipulate Swagger specifications",
"type" : "library",
"license" : "MIT",
"authors" : [
{
"name" : "Guilhem Niot",
"email" : "guilhem@gniot.fr"
}
],
"autoload" : {
"psr-4" : {
"EXSyst\\Component\\Swagger\\" : "src/"
}
},
"autoload-dev" : {
"psr-4" : {
"EXSyst\\Component\\Swagger\\tests\\" : "tests/"
}
},
"require" : {
"php" : "^7.0|^8.0"
},
"require-dev" : {
"symfony/phpunit-bridge": "^4.1.8|^5.0"
}
}
================================================
FILE: phpunit
================================================
#!/usr/bin/env php
<?php
if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n";
exit(1);
}
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';
================================================
FILE: phpunit.xml.dist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/6.5/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>tests</directory>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
================================================
FILE: src/AbstractModel.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
/**
* @internal
*/
abstract class AbstractModel
{
const REQUIRED = true;
public function merge($data, $overwrite = false)
{
return $this->doMerge($this->normalize($data), $overwrite);
}
public function toArray()
{
$return = [];
foreach ($this->doExport() as $key => $value) {
$value = $this->resolve($value);
if (null === $value) {
continue;
}
$return[$key] = $value;
}
if (method_exists($this, 'getExtensions')) {
foreach ($this->getExtensions() as $name => $value) {
$return['x-'.$name] = $value;
}
}
if (is_array($return) && 0 === count($return) && !static::REQUIRED) {
$return = null;
}
return $return;
}
abstract protected function doMerge($data, $overwrite = false);
protected function normalize($data)
{
if ($data instanceof \stdClass || $data instanceof \ArrayAccess) {
return (array) $data;
}
return $data;
}
private function resolve($value)
{
if (is_array($value)) {
foreach ($value as &$v) {
$v = $this->resolve($v);
}
} elseif ($value instanceof self) {
$value = $value->toArray();
}
return $value;
}
}
================================================
FILE: src/Collections/Definitions.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Collections;
use EXSyst\Component\Swagger\AbstractModel;
use EXSyst\Component\Swagger\Schema;
final class Definitions extends AbstractModel implements \IteratorAggregate
{
const REQUIRED = false;
private $definitions = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
foreach ($data as $name => $schema) {
$this->get($name)->merge($schema, $overwrite);
}
}
protected function doExport(): array
{
return $this->definitions;
}
/**
* Returns the schema for the given field.
*/
public function get(string $name): Schema
{
if (!$this->has($name)) {
$this->set($name, new Schema());
}
return $this->definitions[$name];
}
/**
* Sets the field.
*/
public function set(string $name, Schema $schema): self
{
$this->definitions[$name] = $schema;
return $this;
}
/**
* Removes the given field.
*/
public function remove(string $name): self
{
unset($this->definitions[$name]);
return $this;
}
/**
* Returns definitions has a schema with the given name.
*/
public function has(string $name): bool
{
return isset($this->definitions[$name]);
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->definitions);
}
}
================================================
FILE: src/Collections/Headers.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Collections;
use EXSyst\Component\Swagger\AbstractModel;
use EXSyst\Component\Swagger\Header;
final class Headers extends AbstractModel implements \IteratorAggregate
{
const REQUIRED = false;
private $headers = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
foreach ($data as $name => $header) {
$this->get($name)->merge($header, $overwrite);
}
}
protected function doExport(): array
{
return $this->headers;
}
/**
* Returns whether a header with the given name exists.
*/
public function has(string $header): bool
{
return isset($this->headers[$header]);
}
/**
* Returns the header info for the given code.
*/
public function get($header): Header
{
if (!$this->has($header)) {
$this->set($header, new Header());
}
return $this->headers[$header];
}
/**
* Sets the header.
*/
public function set(string $name, Header $header): self
{
$this->headers[$name] = $header;
return $this;
}
/**
* Removes the given header.
*/
public function remove(string $header): self
{
unset($this->headers[$header]);
return $this;
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->headers);
}
}
================================================
FILE: src/Collections/Parameters.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Collections;
use EXSyst\Component\Swagger\AbstractModel;
use EXSyst\Component\Swagger\Parameter;
use EXSyst\Component\Swagger\Parts\RefPart;
final class Parameters extends AbstractModel implements \IteratorAggregate
{
const REQUIRED = false;
use RefPart;
private $parameters = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
$this->mergeRef($data, $overwrite);
if (!$this->hasRef()) {
foreach ($data as $parameter) {
$this->add(new Parameter($parameter));
}
}
}
protected function doExport(): array
{
if ($this->hasRef()) {
return ['$ref' => $this->getRef()];
}
return array_values($this->parameters);
}
/**
* Searches whether a parameter with the given unique combination exists.
*/
public function has(string $name, string $in = null): bool
{
$id = $in ? $name.'/'.$in : $name;
return isset($this->parameters[$id]);
}
public function get(string $name, string $in = null): Parameter
{
if (!$this->has($name, $in)) {
$this->add(
new Parameter(['name' => $name, 'in' => $in])
);
}
$id = $in ? $name.'/'.$in : $name;
return $this->parameters[$id];
}
/**
* Adds a parameter.
*/
public function add(Parameter $parameter): self
{
$this->parameters[$this->getIdentifier($parameter)] = $parameter;
return $this;
}
/**
* Removes a parameter.
*/
public function remove(Parameter $parameter): self
{
unset($this->parameters[$this->getIdentifier($parameter)]);
return $this;
}
private function getIdentifier(Parameter $parameter)
{
if ($parameter->hasRef()) {
return $parameter->getRef();
}
return $parameter->getName().'/'.$parameter->getIn();
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator(array_values($this->parameters));
}
}
================================================
FILE: src/Collections/Paths.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Collections;
use EXSyst\Component\Swagger\AbstractModel;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Path;
final class Paths extends AbstractModel implements \IteratorAggregate
{
const REQUIRED = false;
use ExtensionPart;
private $paths = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
foreach ($data as $key => $path) {
if (0 !== strpos($key, 'x-')) {
$this->get($key)->merge($path, $overwrite);
}
}
$this->mergeExtensions($data, $overwrite);
}
protected function doExport(): array
{
return $this->paths;
}
/**
* Returns whether a path with the given name exists.
*/
public function has(string $path): bool
{
return isset($this->paths[$path]);
}
/**
* Returns the path info for the given path.
*/
public function get(string $path): Path
{
if (!$this->has($path)) {
$this->set($path, new Path());
}
return $this->paths[$path];
}
/**
* Sets the path.
*/
public function set(string $path, Path $model): self
{
$this->paths[$path] = $model;
return $this;
}
/**
* Removes the given path.
*/
public function remove(string $path): self
{
unset($this->paths[$path]);
return $this;
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->paths);
}
}
================================================
FILE: src/Collections/Responses.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Collections;
use EXSyst\Component\Swagger\AbstractModel;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Response;
final class Responses extends AbstractModel implements \IteratorAggregate
{
use ExtensionPart;
private $responses = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
$this->mergeExtensions($data, $overwrite);
foreach ($data as $code => $response) {
if (0 !== strpos($code, 'x-')) {
$this->set($code, new Response($response));
}
}
}
protected function doExport(): array
{
return $this->responses;
}
/**
* Returns whether the given response exists.
*/
public function has($code): bool
{
return isset($this->responses[$code]);
}
/**
* Returns the response info for the given code.
*/
public function get($code): Response
{
if (!$this->has($code)) {
$this->set($code, new Response());
}
return $this->responses[$code];
}
/**
* Sets the response.
*/
public function set($code, Response $response): self
{
$this->responses[$code] = $response;
return $this;
}
/**
* Removes the given response.
*/
public function remove($code): self
{
unset($this->responses[$code]);
return $this;
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->responses);
}
}
================================================
FILE: src/Contact.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Contact extends AbstractModel
{
const REQUIRED = false;
use ExtensionPart;
/** @var string */
private $name;
/** @var string */
private $url;
/** @var string */
private $email;
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->name, $data['name'] ?? null, $overwrite);
MergeHelper::mergeFields($this->url, $data['url'] ?? null, $overwrite);
MergeHelper::mergeFields($this->email, $data['email'] ?? null, $overwrite);
$this->mergeExtensions($data, $overwrite);
}
protected function doExport(): array
{
return [
'name' => $this->name,
'url' => $this->url,
'email' => $this->email,
];
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name): self
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl($url): self
{
$this->url = $url;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email): self
{
$this->email = $email;
return $this;
}
}
================================================
FILE: src/ExternalDocs.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\UrlPart;
final class ExternalDocs extends AbstractModel
{
const REQUIRED = false;
use DescriptionPart;
use UrlPart;
use ExtensionPart;
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeUrl($data, $overwrite);
}
protected function doExport(): array
{
return [
'description' => $this->description,
'url' => $this->url,
];
}
}
================================================
FILE: src/Header.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ItemsPart;
use EXSyst\Component\Swagger\Parts\TypePart;
final class Header extends AbstractModel
{
use DescriptionPart;
use TypePart;
use ItemsPart;
use ExtensionPart;
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeItems($data, $overwrite);
$this->mergeType($data, $overwrite);
}
public function doExport(): array
{
return array_merge(
[
'description' => $this->description,
'items' => $this->items,
],
$this->doExportType()
);
}
}
================================================
FILE: src/Info.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Info extends AbstractModel
{
const REQUIRED = false;
use DescriptionPart;
use ExtensionPart;
/** @var string */
private $title;
/** @var string */
private $termsOfService;
/** @var Contact */
private $contact;
/** @var License */
private $license;
/** @var string */
private $version;
public function __construct($data = [])
{
$this->contact = new Contact();
$this->license = new License();
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->title, $data['title'] ?? null, $overwrite);
MergeHelper::mergeFields($this->termsOfService, $data['termsOfService'] ?? null, $overwrite);
MergeHelper::mergeFields($this->version, $data['version'] ?? null, $overwrite);
$this->contact->merge($data['contact'] ?? [], $overwrite);
$this->license->merge($data['license'] ?? [], $overwrite);
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
}
protected function doExport(): array
{
return [
'title' => $this->title,
'description' => $this->description,
'termsOfService' => $this->termsOfService,
'contact' => $this->contact,
'license' => $this->license,
'version' => $this->version,
];
}
/**
* @return string|null
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string|null $title
*/
public function setTitle($title): self
{
$this->title = $title;
return $this;
}
/**
* @return string|null
*/
public function getTerms()
{
return $this->termsOfService;
}
/**
* @param string|null $terms
*/
public function setTerms($terms): self
{
$this->termsOfService = $terms;
return $this;
}
/**
* @return Contact
*/
public function getContact()
{
return $this->contact;
}
/**
* @return License
*/
public function getLicense()
{
return $this->license;
}
/**
* @return string|null
*/
public function getVersion()
{
return $this->version;
}
/**
* @param string|null $version
*
* @return Info
*/
public function setVersion($version): self
{
$this->version = $version;
return $this;
}
}
================================================
FILE: src/Items.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
final class Items extends Schema
{
const REQUIRED = false;
}
================================================
FILE: src/License.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\UrlPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class License extends AbstractModel
{
const REQUIRED = false;
use UrlPart;
use ExtensionPart;
/** @var string */
private $name;
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->name, $data['name'] ?? null, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeUrl($data, $overwrite);
}
protected function doExport(): array
{
return [
'name' => $this->name,
'url' => $this->url,
];
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name): self
{
$this->name = $name;
return $this;
}
}
================================================
FILE: src/Operation.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\ConsumesPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ExternalDocsPart;
use EXSyst\Component\Swagger\Parts\ParametersPart;
use EXSyst\Component\Swagger\Parts\ProducesPart;
use EXSyst\Component\Swagger\Parts\ResponsesPart;
use EXSyst\Component\Swagger\Parts\SchemesPart;
use EXSyst\Component\Swagger\Parts\SecurityPart;
use EXSyst\Component\Swagger\Parts\TagsPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Operation extends AbstractModel
{
use ConsumesPart;
use ProducesPart;
use TagsPart;
use ParametersPart;
use ResponsesPart;
use SchemesPart;
use ExternalDocsPart;
use ExtensionPart;
use SecurityPart;
/** @var string */
private $summary;
/** @var string */
private $description;
/** @var string */
private $operationId;
/** @var bool */
private $deprecated;
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->summary, $data['summary'] ?? null, $overwrite);
MergeHelper::mergeFields($this->description, $data['description'] ?? null, $overwrite);
MergeHelper::mergeFields($this->operationId, $data['operationId'] ?? null, $overwrite);
MergeHelper::mergeFields($this->deprecated, $data['deprecated'] ?? null, $overwrite);
$this->mergeConsumes($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeExternalDocs($data, $overwrite);
$this->mergeParameters($data, $overwrite);
$this->mergeProduces($data, $overwrite);
$this->mergeResponses($data, $overwrite);
$this->mergeSchemes($data, $overwrite);
$this->mergeSecurity($data, $overwrite);
$this->mergeTags($data, $overwrite);
}
protected function doExport(): array
{
return [
'summary' => $this->getSummary(),
'description' => $this->getDescription(),
'operationId' => $this->getOperationId(),
'deprecated' => $this->getDeprecated(),
'consumes' => $this->getConsumes() ?: null,
'produces' => $this->getProduces() ?: null,
'parameters' => $this->getParameters(),
'responses' => $this->getResponses(),
'schemes' => $this->getSchemes() ?: null,
'tags' => $this->getTags() ?: null,
'externalDocs' => $this->getExternalDocs(),
'security' => $this->getSecurity(),
];
}
/**
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* @param string $summary
*/
public function setSummary($summary): self
{
$this->summary = $summary;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description): self
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getOperationId()
{
return $this->operationId;
}
/**
* @param string $operationId
*/
public function setOperationId($operationId): self
{
$this->operationId = $operationId;
return $this;
}
/**
* @return bool
*/
public function getDeprecated()
{
return $this->deprecated;
}
/**
* @param bool $deprecated
*/
public function setDeprecated($deprecated): self
{
$this->deprecated = $deprecated;
return $this;
}
}
================================================
FILE: src/Parameter.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ItemsPart;
use EXSyst\Component\Swagger\Parts\RefPart;
use EXSyst\Component\Swagger\Parts\RequiredPart;
use EXSyst\Component\Swagger\Parts\SchemaPart;
use EXSyst\Component\Swagger\Parts\TypePart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Parameter extends AbstractModel
{
use RefPart;
use DescriptionPart;
use SchemaPart;
use TypePart;
use ItemsPart;
use RequiredPart;
use ExtensionPart;
/** @var string */
private $name;
/** @var string */
private $in;
/** @var bool|null */
private $allowEmptyValue;
public function __construct($data = [])
{
$data = $this->normalize($data);
$this->merge($data);
if (!$this->hasRef()) {
if (!isset($data['name']) || !isset($data['in'])) {
throw new \InvalidArgumentException('"in" and "name" are required for parameters');
}
$this->name = $data['name'];
$this->in = $data['in'];
}
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->allowEmptyValue, $data['allowEmptyValue'] ?? null, $overwrite);
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeItems($data, $overwrite);
$this->mergeRef($data, $overwrite);
$this->mergeRequired($data, $overwrite);
$this->mergeSchema($data, $overwrite);
$this->mergeType($data, $overwrite);
}
protected function doExport(): array
{
if ($this->hasRef()) {
return ['$ref' => $this->getRef()];
}
return array_merge(
[
'name' => $this->name,
'in' => $this->in,
'allowEmptyValue' => $this->allowEmptyValue,
'required' => $this->required,
'description' => $this->description,
'schema' => $this->schema,
'items' => $this->items,
],
$this->doExportType()
);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getIn()
{
return $this->in;
}
/**
* @return bool
*/
public function getAllowEmptyValue()
{
return $this->allowEmptyValue;
}
/**
* Sets the ability to pass empty-valued parameters. This is valid only for either `query` or
* `formData` parameters and allows you to send a parameter with a name only or an empty value.
* Default value is `false`.
*
* @param bool $allowEmptyValue
*/
public function setAllowEmptyValue($allowEmptyValue): self
{
$this->allowEmptyValue = $allowEmptyValue;
return $this;
}
}
================================================
FILE: src/Parts/ConsumesPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait ConsumesPart
{
private $consumes;
private function mergeConsumes(array $data, bool $overwrite)
{
MergeHelper::mergeFields($this->consumes, $data['consumes'] ?? null, $overwrite);
}
/**
* Return consumes.
*/
public function getConsumes()
{
return $this->consumes;
}
}
================================================
FILE: src/Parts/DescriptionPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait DescriptionPart
{
/** @var string|null */
private $description;
private function mergeDescription(array $data, bool $overwrite)
{
MergeHelper::mergeFields($this->description, $data['description'] ?? null, $overwrite);
}
/**
* @return string|null
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*
* @return $this
*/
public function setDescription(string $description = null): self
{
$this->description = $description;
return $this;
}
}
================================================
FILE: src/Parts/ExtensionPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
/**
* @internal
*/
trait ExtensionPart
{
private $extensions = [];
private function mergeExtensions(array $data, bool $overwrite)
{
foreach ($data as $name => $value) {
if (0 === strpos($name, 'x-')) {
$this->extensions[substr($name, 2)] = $value;
}
}
}
/**
* Returns extensions.
*
* @return array
*/
public function getExtensions(): array
{
return $this->extensions;
}
}
================================================
FILE: src/Parts/ExternalDocsPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\ExternalDocs;
/**
* @internal
*/
trait ExternalDocsPart
{
/** @var ExternalDocs|null */
private $externalDocs;
private function mergeExternalDocs(array $data, bool $overwrite)
{
if (isset($data['externalDocs'])) {
$this->getExternalDocs()->merge($data['externalDocs']);
}
}
/**
* @return ExternalDocs
*/
public function getExternalDocs(): ExternalDocs
{
if (null === $this->externalDocs) {
$this->externalDocs = new ExternalDocs();
}
return $this->externalDocs;
}
public function setExternalDocs(ExternalDocs $externalDocs): self
{
$this->externalDocs = $externalDocs;
return $this;
}
}
================================================
FILE: src/Parts/ItemsPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Items;
/**
* @internal
*/
trait ItemsPart
{
/** @var Items|null */
private $items;
private function mergeItems(array $data, bool $overwrite)
{
if (isset($data['items'])) {
$this->getItems()->merge($data['items'], $overwrite);
}
}
/**
* Returns the items.
*/
public function getItems(): Items
{
if (null === $this->items) {
$this->items = new Items();
}
return $this->items;
}
}
================================================
FILE: src/Parts/ParametersPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Collections\Parameters;
/**
* @internal
*/
trait ParametersPart
{
/** @var Parameters|null */
private $parameters;
private function mergeParameters(array $data, bool $overwrite)
{
if (isset($data['parameters'])) {
$this->getParameters()->merge($data['parameters'], $overwrite);
}
}
/**
* Return parameters.
*/
public function getParameters(): Parameters
{
if (null === $this->parameters) {
$this->parameters = new Parameters();
}
return $this->parameters;
}
}
================================================
FILE: src/Parts/ProducesPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
/**
* @internal
*/
trait ProducesPart
{
private $produces = [];
private function mergeProduces(array $data, bool $overwrite)
{
foreach ($data['produces'] ?? [] as $produce) {
$this->produces[$produce] = true;
}
}
/**
* Return produces.
*/
public function getProduces(): array
{
return array_keys($this->produces);
}
}
================================================
FILE: src/Parts/RefPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
/**
* @internal
*/
trait RefPart
{
/** @var string|null */
private $ref;
private function mergeRef(array $data, bool $overwrite)
{
$this->ref = $data['$ref'] ?? null;
}
/**
* @return string|null
*/
public function getRef()
{
return $this->ref;
}
/**
* @param string|null $ref
*/
public function setRef(string $ref = null): self
{
$this->ref = $ref;
return $this;
}
public function hasRef(): bool
{
return null !== $this->ref;
}
}
================================================
FILE: src/Parts/RequiredPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait RequiredPart
{
/** @var bool|null */
private $required;
private function mergeRequired(array $data, bool $overwrite)
{
MergeHelper::mergeFields($this->required, $data['required'] ?? null, $overwrite);
}
/**
* @return bool|null
*/
public function getRequired()
{
return $this->required;
}
/**
* @param bool|null $required
*/
public function setRequired(bool $required = null): self
{
$this->required = $required;
return $this;
}
}
================================================
FILE: src/Parts/ResponsesPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Collections\Responses;
/**
* @internal
*/
trait ResponsesPart
{
/** @var Responses|null */
private $responses;
private function mergeResponses(array $data, bool $overwrite)
{
if (isset($data['responses'])) {
$this->getResponses()->merge($data['responses'], $overwrite);
}
}
/**
* Return responses.
*/
public function getResponses(): Responses
{
if (null === $this->responses) {
$this->responses = new Responses();
}
return $this->responses;
}
}
================================================
FILE: src/Parts/SchemaPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Schema;
/**
* @internal
*/
trait SchemaPart
{
/** @var Schema|null */
private $schema;
private function mergeSchema(array $data, bool $overwrite)
{
if (isset($data['schema'])) {
$this->getSchema()->merge($data['schema'], $overwrite);
}
}
public function getSchema(): Schema
{
if (null === $this->schema) {
$this->schema = new Schema();
}
return $this->schema ?: new Schema();
}
}
================================================
FILE: src/Parts/SchemesPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
/**
* @internal
*/
trait SchemesPart
{
private $schemes = [];
private function mergeSchemes(array $data, bool $overwrite)
{
foreach ($data['schemes'] ?? [] as $scheme) {
$this->schemes[$scheme] = true;
}
}
/**
* Return schemes.
*/
public function getSchemes(): array
{
return array_keys($this->schemes);
}
}
================================================
FILE: src/Parts/SecurityPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait SecurityPart
{
/** @var array */
private $security;
private function mergeSecurity(array $data, bool $overwrite)
{
MergeHelper::mergeFields($this->security, $data['security'] ?? null, $overwrite);
}
/**
* @return array|null
*/
public function getSecurity()
{
return $this->security;
}
public function setSecurity(array $security = null): self
{
$this->security = $security;
return $this;
}
}
================================================
FILE: src/Parts/TagsPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Tag;
/**
* @internal
*/
trait TagsPart
{
private $tags = [];
private function mergeTags(array $data, bool $overwrite)
{
foreach ($data['tags'] ?? [] as $value) {
$tag = new Tag($value);
$this->tags[$tag->getName()] = $tag;
}
}
/**
* Return tags.
*/
public function getTags(): array
{
return array_values($this->tags);
}
protected function exportTags(): array
{
$out = [];
foreach ($this->tags as $tag) {
$out[] = $tag->toArray();
}
return $out;
}
}
================================================
FILE: src/Parts/TypePart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait TypePart
{
/** @var string */
private $type;
/** @var string */
private $format;
/** @var string */
private $collectionFormat;
/** @var mixed */
private $default;
/** @var float */
private $maximum;
/** @var bool */
private $exclusiveMaximum;
/** @var float */
private $minimum;
/** @var bool */
private $exclusiveMinimum;
/** @var int */
private $maxLength;
/** @var int */
private $minLength;
/** @var string */
private $pattern;
/** @var int */
private $maxItems;
/** @var int */
private $minItems;
/** @var bool */
private $uniqueItems;
/** @var mixed */
private $enum;
/** @var float */
private $multipleOf;
private function mergeType(array $data, bool $overwrite)
{
foreach ($this->getTypeFields() as $field) {
MergeHelper::mergeFields($this->{$field}, $data[$field] ?? null, $overwrite);
}
}
protected function doExportType(): array
{
$return = [];
foreach ($this->getTypeFields() as $field) {
$return[$field] = $this->{$field};
}
return $return;
}
private function getTypeFields(): array
{
return [
'type',
'format',
'collectionFormat',
'default',
'maximum',
'exclusiveMaximum',
'minimum',
'exclusiveMinimum',
'maxLength',
'minLength',
'pattern',
'maxItems',
'minItems',
'uniqueItems',
'enum',
'multipleOf',
];
}
/**
* @return string|null
*/
public function getType()
{
return $this->type;
}
/**
* @param string|null $type
*/
public function setType($type): self
{
$this->type = $type;
return $this;
}
/**
* @return string|null
*/
public function getFormat()
{
return $this->format;
}
/**
* Sets the extending format for the type.
*
* @param string|null $format
*/
public function setFormat($format): self
{
$this->format = $format;
return $this;
}
/**
* @return string|null
*/
public function getCollectionFormat()
{
return $this->collectionFormat;
}
/**
* Determines the format of the array if type array is used. Possible values are:.
*
* - `csv` - comma separated values `foo,bar`.
* - `ssv` - space separated values `foo bar`.
* - `tsv` - tab separated values `foo\tbar`.
* - `pipes` - pipe separated values `foo|bar`.
* - `multi` - corresponds to multiple parameter instances instead of multiple values for a
* single instance `foo=bar&foo=baz`. This is valid only for parameters in "query" or "formData".
*
* Default value is `csv`.
*
*
* @param string|null $collectionFormat
*/
public function setCollectionFormat($collectionFormat): self
{
$this->collectionFormat = $collectionFormat;
return $this;
}
/**
* @return mixed
*/
public function getDefault()
{
return $this->default;
}
/**
* @param mixed|null $default
*/
public function setDefault($default): self
{
$this->default = $default;
return $this;
}
/**
* @return float|null
*/
public function getMaximum()
{
return $this->maximum;
}
/**
* @param float|null $maximum
*/
public function setMaximum($maximum): self
{
$this->maximum = $maximum;
return $this;
}
/**
* @return bool|null
*/
public function isExclusiveMaximum()
{
return $this->exclusiveMaximum;
}
/**
* @param bool|null $exclusiveMaximum
*/
public function setExclusiveMaximum($exclusiveMaximum): self
{
$this->exclusiveMaximum = $exclusiveMaximum;
return $this;
}
/**
* @return float|null
*/
public function getMinimum()
{
return $this->minimum;
}
/**
* @param float|null $minimum
*/
public function setMinimum($minimum): self
{
$this->minimum = $minimum;
return $this;
}
/**
* @return bool|null
*/
public function isExclusiveMinimum()
{
return $this->exclusiveMinimum;
}
/**
* @param bool|null $exclusiveMinimum
*
* @return $this
*/
public function setExclusiveMinimum($exclusiveMinimum)
{
$this->exclusiveMinimum = $exclusiveMinimum;
return $this;
}
/**
* @return int|null
*/
public function getMaxLength()
{
return $this->maxLength;
}
/**
* @param int|null $maxLength
*/
public function setMaxLength($maxLength): self
{
$this->maxLength = $maxLength;
return $this;
}
/**
* @return int|null
*/
public function getMinLength()
{
return $this->minLength;
}
/**
* @param int|null $minLength
*/
public function setMinLength($minLength): self
{
$this->minLength = $minLength;
return $this;
}
/**
* @return string|null
*/
public function getPattern()
{
return $this->pattern;
}
/**
* @param string|null $pattern
*/
public function setPattern($pattern): self
{
$this->pattern = $pattern;
return $this;
}
/**
* @return int|null
*/
public function getMaxItems()
{
return $this->maxItems;
}
/**
* @param int|null $maxItems
*/
public function setMaxItems($maxItems): self
{
$this->maxItems = $maxItems;
return $this;
}
/**
* @return int|null
*/
public function getMinItems()
{
return $this->minItems;
}
/**
* @param int|null $minItems
*/
public function setMinItems($minItems): self
{
$this->minItems = $minItems;
return $this;
}
/**
* @return bool|null
*/
public function hasUniqueItems()
{
return $this->uniqueItems;
}
/**
* @param bool|null $uniqueItems
*/
public function setUniqueItems($uniqueItems): self
{
$this->uniqueItems = $uniqueItems;
return $this;
}
/**
* @return mixed
*/
public function getEnum()
{
return $this->enum;
}
/**
* @param mixed $enum
*/
public function setEnum($enum): self
{
$this->enum = $enum;
return $this;
}
/**
* @return float|null
*/
public function getMultipleOf()
{
return $this->multipleOf;
}
/**
* @param float|null $multipleOf
*/
public function setMultipleOf($multipleOf): self
{
$this->multipleOf = $multipleOf;
return $this;
}
}
================================================
FILE: src/Parts/UrlPart.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Parts;
use EXSyst\Component\Swagger\Util\MergeHelper;
/**
* @internal
*/
trait UrlPart
{
/** @var string|null */
private $url;
private function mergeUrl(array $data, bool $overwrite)
{
MergeHelper::mergeFields($this->url, $data['url'] ?? null, $overwrite);
}
/**
* @return string|null
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url = null): self
{
$this->url = $url;
return $this;
}
}
================================================
FILE: src/Path.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ParametersPart;
final class Path extends AbstractModel
{
use ExtensionPart;
use ParametersPart;
private $operations = [];
public function __construct($data = [])
{
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
foreach (Swagger::$METHODS as $method) {
if (isset($data[$method])) {
$this->getOperation($method)->merge($data[$method]);
}
}
$this->mergeExtensions($data, $overwrite);
$this->mergeParameters($data, $overwrite);
}
protected function doExport(): array
{
return array_merge($this->operations, array('parameters' => $this->getParameters()));
}
public function getOperations(): array
{
return $this->operations;
}
/**
* Gets the operation for the given method, creates one if none exists.
*/
public function getOperation(string $method): Operation
{
if (!$this->hasOperation($method)) {
$this->setOperation($method, new Operation());
}
return $this->operations[$method];
}
/**
* Sets the operation for a method.
*/
public function setOperation(string $method, Operation $operation): self
{
$this->operations[$method] = $operation;
return $this;
}
public function hasOperation(string $method): bool
{
return isset($this->operations[$method]);
}
/**
* Removes an operation for the given method.
*/
public function removeOperation(string $method): self
{
unset($this->operations[$method]);
return $this;
}
/**
* Returns all methods for this path.
*/
public function getMethods(): array
{
return array_keys($this->operations);
}
}
================================================
FILE: src/Response.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Collections\Headers;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\RefPart;
use EXSyst\Component\Swagger\Parts\SchemaPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Response extends AbstractModel
{
use RefPart;
use DescriptionPart;
use SchemaPart;
use ExtensionPart;
private $examples = [];
/** @var Headers */
private $headers;
public function __construct($data = [])
{
$this->headers = new Headers();
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
foreach ($data['examples'] ?? [] as $mimeType => $example) {
$this->examples[$mimeType] = $this->examples[$mimeType] ?? null;
MergeHelper::mergeFields($this->examples[$mimeType], $example, $overwrite);
}
$this->headers->merge($data['headers'] ?? [], $overwrite);
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeRef($data, $overwrite);
$this->mergeSchema($data, $overwrite);
}
protected function doExport(): array
{
if ($this->hasRef()) {
return ['$ref' => $this->getRef()];
}
return [
'description' => $this->description,
'schema' => $this->schema,
'headers' => $this->headers,
'examples' => $this->examples ?: null,
];
}
public function getExamples(): array
{
return $this->examples;
}
/**
* Returns headers for this response.
*/
public function getHeaders(): Headers
{
return $this->headers;
}
}
================================================
FILE: src/Schema.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Collections\Definitions;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ExternalDocsPart;
use EXSyst\Component\Swagger\Parts\ItemsPart;
use EXSyst\Component\Swagger\Parts\RefPart;
use EXSyst\Component\Swagger\Parts\TypePart;
use EXSyst\Component\Swagger\Util\MergeHelper;
class Schema extends AbstractModel
{
use RefPart;
use TypePart;
use DescriptionPart;
use ItemsPart;
use ExternalDocsPart;
use ExtensionPart;
/** @var string */
private $discriminator;
/** @var bool */
private $readOnly;
/** @var string */
private $title;
/** @var string */
private $example;
/** @var array|bool */
private $required;
/** @var Definitions */
private $properties;
/** @var array */
private $allOf = [];
/** @var Schema */
private $additionalProperties;
public function __construct($data = [])
{
$this->properties = new Definitions();
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->required, $data['required'] ?? null, $overwrite);
MergeHelper::mergeFields($this->title, $data['title'] ?? null, $overwrite);
MergeHelper::mergeFields($this->discriminator, $data['discriminator'] ?? null, $overwrite);
MergeHelper::mergeFields($this->readOnly, $data['readOnly'] ?? null, $overwrite);
MergeHelper::mergeFields($this->example, $data['example'] ?? null, $overwrite);
$this->properties->merge($data['properties'] ?? [], $overwrite);
foreach ($data['allOf'] ?? [] as $schema) {
$this->allOf[] = new self($schema);
}
if (isset($data['additionalProperties'])) {
if (null === $this->additionalProperties) {
$this->additionalProperties = new self();
}
if (true === $data['additionalProperties']) {
$data['additionalProperties'] = [];
}
$this->additionalProperties->merge($data['additionalProperties'], $overwrite);
}
$this->mergeDescription($data, $overwrite);
$this->mergeExternalDocs($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeItems($data, $overwrite);
$this->mergeRef($data, $overwrite);
$this->mergeType($data, $overwrite);
}
protected function doExport()
{
if ($this->hasRef()) {
return ['$ref' => $this->getRef()];
}
// if "additionalProperties" has no special types/refs, it must return `{}` or `true`
// @see https://swagger.io/docs/specification/data-models/dictionaries/
$additionalProperties = ($this->additionalProperties instanceof self && [] === $this->additionalProperties->toArray()) ?: $this->additionalProperties;
return array_merge([
'title' => $this->title,
'discriminator' => $this->discriminator,
'description' => $this->description,
'readOnly' => $this->readOnly,
'example' => $this->example,
'externalDocs' => $this->externalDocs,
'items' => $this->items,
'required' => $this->required,
'properties' => $this->properties,
'additionalProperties' => $additionalProperties,
'allOf' => $this->allOf ?: null,
], $this->doExportType());
}
/**
* @return bool|array
*/
public function getRequired()
{
return $this->required;
}
/**
* @param bool|array $required
*
* @return $this
*/
public function setRequired($required)
{
$this->required = $required;
return $this;
}
/**
* @return string|null
*/
public function getDiscriminator()
{
return $this->discriminator;
}
/**
* @param string|null $discriminator
*
* @return Schema
*/
public function setDiscriminator($discriminator)
{
$this->discriminator = $discriminator;
return $this;
}
/**
* @return bool|null
*/
public function isReadOnly()
{
return $this->readOnly;
}
/**
* @param bool|null $readOnly
*
* @return Schema
*/
public function setReadOnly($readOnly)
{
$this->readOnly = $readOnly;
return $this;
}
/**
* @return string|null
*/
public function getExample()
{
return $this->example;
}
/**
* @param string|null $example
*
* @return Schema
*/
public function setExample($example)
{
$this->example = $example;
return $this;
}
/**
* @return string|null
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string|null $title
*
* @return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return Definitions
*/
public function getProperties()
{
return $this->properties;
}
/**
* @return array
*/
public function getAllOf(): array
{
return $this->allOf;
}
/**
* @return Schema|null
*/
public function getAdditionalProperties()
{
return $this->additionalProperties;
}
}
================================================
FILE: src/SecurityScheme.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
class SecurityScheme extends AbstractModel
{
use DescriptionPart;
/** @var string */
private $name;
/** @var string */
private $type;
/** @var string */
private $in;
/** @var string */
private $flow;
/** @var string */
private $authorizationUrl;
/** @var string */
private $tokenUrl;
/** @var array */
private $scopes;
public function __construct($data = [])
{
$this->merge($data);
}
/**
* Return the name of the header or query parameter to be used.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Sets the name of the header or query parameter to be used.
*
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Returns the type of the security scheme.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Sets the type of the security scheme.
*
* @param string $type Valid values are "basic", "apiKey" or "oauth2"
*
* @return $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Returns the location of the API key.
*
* @return string
*/
public function getIn()
{
return $this->in;
}
/**
* Sets the location of the API key.
*
* @param string $in Valid values are "query" or "header"
*
* @return $this
*/
public function setIn($in)
{
$this->in = $in;
return $this;
}
/**
* Retunrs the flow used by the OAuth2 security scheme.
*
* @return string
*/
public function getFlow()
{
return $this->flow;
}
/**
* Sets the flow used by the OAuth2 security scheme.
*
* @param string $flow Valid values are "implicit", "password", "application" or "accessCode"
*
* @return $this
*/
public function setFlow($flow)
{
$this->flow = $flow;
return $this;
}
/**
* Returns the authorization URL to be used for this flow.
*
* @return string
*/
public function getAuthorizationUrl()
{
return $this->authorizationUrl;
}
/**
* Sets the authorization URL to be used for this flow.
*
* @param string $authorizationUrl
*
* @return $this
*/
public function setAuthorizationUrl($authorizationUrl)
{
$this->authorizationUrl = $authorizationUrl;
return $this;
}
/**
* Returns the token URL to be used for this flow.
*
* @return string
*/
public function getTokenUrl()
{
return $this->tokenUrl;
}
/**
* Sets the token URL to be used for this flow.
*
* @param string $tokenUrl
*
* @return $this
*/
public function setTokenUrl($tokenUrl)
{
$this->tokenUrl = $tokenUrl;
return $this;
}
/**
* Returns the scopes.
*
* @return array
*/
public function getScopes()
{
return $this->scopes;
}
/**
* @return $this
*/
public function setScopes(array $scopes = null)
{
$this->scopes = $scopes;
return $this;
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->name, $data['name'] ?? null, $overwrite);
MergeHelper::mergeFields($this->type, $data['type'] ?? null, $overwrite);
MergeHelper::mergeFields($this->in, $data['in'] ?? null, $overwrite);
MergeHelper::mergeFields($this->flow, $data['flow'] ?? null, $overwrite);
MergeHelper::mergeFields($this->authorizationUrl, $data['authorizationUrl'] ?? null, $overwrite);
MergeHelper::mergeFields($this->tokenUrl, $data['tokenUrl'] ?? null, $overwrite);
MergeHelper::mergeFields($this->scopes, $data['scopes'] ?? null, $overwrite);
$this->mergeDescription($data, $overwrite);
}
protected function doExport()
{
return [
'name' => $this->name,
'type' => $this->type,
'in' => $this->in,
'flow' => $this->flow,
'authorizationUrl' => $this->authorizationUrl,
'tokenUrl' => $this->tokenUrl,
'scopes' => $this->scopes,
'description' => $this->description,
];
}
}
================================================
FILE: src/Swagger.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Collections\Definitions;
use EXSyst\Component\Swagger\Collections\Paths;
use EXSyst\Component\Swagger\Parts\ConsumesPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ExternalDocsPart;
use EXSyst\Component\Swagger\Parts\ProducesPart;
use EXSyst\Component\Swagger\Parts\ResponsesPart;
use EXSyst\Component\Swagger\Parts\SchemesPart;
use EXSyst\Component\Swagger\Parts\SecurityPart;
use EXSyst\Component\Swagger\Parts\TagsPart;
use EXSyst\Component\Swagger\Util\MergeHelper;
final class Swagger extends AbstractModel
{
use SchemesPart;
use ConsumesPart;
use ProducesPart;
use TagsPart;
use ResponsesPart;
use ExternalDocsPart;
use ExtensionPart;
use SecurityPart;
public static $METHODS = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'];
/** @var Info */
private $info;
/** @var string */
private $host;
/** @var string */
private $basePath;
/** @var Paths */
private $paths;
/** @var Definitions */
private $definitions;
/** @var array */
private $parameters;
/** @var array */
private $securityDefinitions = [];
/**
* @param string $filename
*
* @return static
*/
public static function fromFile(string $filename): self
{
return new static(json_decode(file_get_contents($filename), true));
}
public function __construct($data = [])
{
$this->info = new Info();
$this->definitions = new Definitions();
$this->paths = new Paths();
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
MergeHelper::mergeFields($this->host, $data['host'] ?? null, $overwrite);
MergeHelper::mergeFields($this->basePath, $data['basePath'] ?? null, $overwrite);
if (isset($data['info'])) {
$this->info->merge($data['info'], $overwrite);
}
if (isset($data['definitions'])) {
$this->getDefinitions()->merge($data['definitions'], $overwrite);
}
if (isset($data['paths'])) {
$this->getPaths()->merge($data['paths'], $overwrite);
}
$this->mergeConsumes($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeExternalDocs($data, $overwrite);
$this->mergeProduces($data, $overwrite);
$this->mergeResponses($data, $overwrite);
$this->mergeSchemes($data, $overwrite);
$this->mergeSecurity($data, $overwrite);
$this->mergeTags($data, $overwrite);
foreach ($data['parameters'] ?? [] as $name => $def) {
$this->parameters[$name] = new Parameter($def);
}
foreach ($data['securityDefinitions'] ?? [] as $name => $def) {
$this->securityDefinitions[$name] = new SecurityScheme($def);
}
}
protected function doExport(): array
{
return [
'swagger' => '2.0',
'info' => $this->info,
'host' => $this->host,
'basePath' => $this->basePath,
'schemes' => $this->getSchemes() ?: null,
'consumes' => $this->getConsumes() ?: null,
'produces' => $this->getProduces() ?: null,
'paths' => $this->paths,
'definitions' => $this->definitions,
'parameters' => $this->parameters ?: null,
'responses' => $this->responses,
'tags' => $this->getTags() ?: null,
'externalDocs' => $this->externalDocs,
'securityDefinitions' => $this->securityDefinitions ?: null,
'security' => $this->getSecurity(),
];
}
/**
* @return string
*/
public function getVersion(): string
{
return '2.0';
}
/**
* @return Info
*/
public function getInfo()
{
return $this->info;
}
/**
* @return string
*/
public function getHost()
{
return $this->host;
}
/**
* @param string $host
*/
public function setHost($host): self
{
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getBasePath()
{
return $this->basePath;
}
/**
* @param string $basePath
*
* @return $this
*/
public function setBasePath($basePath)
{
$this->basePath = $basePath;
return $this;
}
/**
* @return Paths
*/
public function getPaths()
{
return $this->paths;
}
/**
* @return Definitions
*/
public function getDefinitions()
{
return $this->definitions;
}
/**
* @return array
*/
public function getSecurityDefinitions()
{
return $this->securityDefinitions;
}
/**
* @return array
*/
public function getParameters()
{
return $this->parameters;
}
/**
* @param array $parameters
*/
public function setParameters(array $parameters): self
{
$this->parameters = $parameters;
return $this;
}
}
================================================
FILE: src/Tag.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger;
use EXSyst\Component\Swagger\Parts\DescriptionPart;
use EXSyst\Component\Swagger\Parts\ExtensionPart;
use EXSyst\Component\Swagger\Parts\ExternalDocsPart;
final class Tag extends AbstractModel
{
use DescriptionPart;
use ExternalDocsPart;
use ExtensionPart;
private $name;
public function __construct($data)
{
$data = $this->normalize($data);
if (!isset($data['name'])) {
throw new \InvalidArgumentException('A tag must have a name.');
}
$this->name = $data['name'];
$this->merge($data);
}
protected function doMerge($data, $overwrite = false)
{
$this->mergeDescription($data, $overwrite);
$this->mergeExtensions($data, $overwrite);
$this->mergeExternalDocs($data, $overwrite);
}
public function toArray()
{
$return = parent::toArray();
if (1 === count($return)) {
return $return['name'];
}
return $return;
}
protected function doExport(): array
{
return [
'name' => $this->name,
'description' => $this->description,
'externalDocs' => $this->externalDocs,
];
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string|array $data
*
* @return array
*/
protected function normalize($data): array
{
if (is_string($data)) {
return [
'name' => $data,
];
}
return parent::normalize($data);
}
}
================================================
FILE: src/Util/MergeHelper.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\Util;
/**
* @internal
*/
class MergeHelper
{
/**
* @param string|int|array|null $original
* @param string|int|array|null $external
* @param bool $overwrite
*/
public static function mergeFields(&$original, $external, $overwrite)
{
if ($overwrite) {
$original = $external ?? $original;
} else {
$original = $original ?? $external;
}
}
}
================================================
FILE: tests/BasicAuthTest.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\tests;
use EXSyst\Component\Swagger\Swagger;
use PHPUnit\Framework\TestCase;
class BasicAuthTest extends TestCase
{
private function fileToArray($filename)
{
return json_decode(file_get_contents($filename), true);
}
public function testUser()
{
$filename = __DIR__.'/fixtures/basic-auth.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
}
================================================
FILE: tests/CollectionsTest.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\tests;
use EXSyst\Component\Swagger\Collections\Definitions;
use EXSyst\Component\Swagger\Collections\Parameters;
use EXSyst\Component\Swagger\Collections\Paths;
use EXSyst\Component\Swagger\Collections\Responses;
use EXSyst\Component\Swagger\Operation;
use EXSyst\Component\Swagger\Parameter;
use EXSyst\Component\Swagger\Path;
use EXSyst\Component\Swagger\Response;
use EXSyst\Component\Swagger\Schema;
use EXSyst\Component\Swagger\Swagger;
use PHPUnit\Framework\TestCase;
class CollectionsTest extends TestCase
{
public function testDefinitions()
{
$swagger = new Swagger();
$definitions = $swagger->getDefinitions();
$this->assertInstanceOf(Definitions::class, $definitions);
$this->assertNull($definitions->toArray());
$this->assertFalse($definitions->has('User'));
$user = new Schema();
$definitions->set('User', $user);
$this->assertCount(1, $definitions->toArray());
$this->assertTrue($definitions->has('User'));
$this->assertSame($user, $definitions->get('User'));
$this->assertInternalType('array', $definitions->toArray()['User']);
$definitions->remove('User');
$this->assertNull($definitions->toArray());
$this->assertFalse($definitions->has('User'));
}
public function testPaths()
{
$swagger = new Swagger();
$paths = $swagger->getPaths();
$this->assertInstanceOf(Paths::class, $paths);
$this->assertNull($paths->toArray());
$this->assertFalse($paths->has('/pets'));
$pets = new Path();
$paths->set('/pets', $pets);
$this->assertCount(1, $paths->toArray());
$this->assertTrue($paths->has('/pets'));
$this->assertSame($pets, $paths->get('/pets'));
$this->assertInternalType('array', $paths->toArray()['/pets']);
$paths->remove('/pets');
$this->assertNull($paths->toArray());
$this->assertFalse($paths->has('/pets'));
}
public function testParameters()
{
$path = new Path();
$parameters = $path->getOperation('get')->getParameters();
$this->assertInstanceOf(Parameters::class, $parameters);
$this->assertNull($parameters->toArray());
$id = new Parameter([
'name' => 'id',
'in' => 'path',
]);
$parameters->add($id);
$this->assertCount(1, $parameters->toArray());
$this->assertTrue($parameters->has('id', 'path'));
$id2 = new Parameter([
'name' => 'id',
'in' => 'body',
]);
$parameters->add($id2);
$this->assertCount(2, $parameters->toArray());
$this->assertTrue($parameters->has('id', 'body'));
$this->assertSame($id, $parameters->get('id', 'path'));
$this->assertSame($id2, $parameters->get('id', 'body'));
$parameter = $parameters->get('bar', 'query');
$this->assertEquals('bar', $parameter->getName());
$this->assertEquals('query', $parameter->getIn());
$this->assertInternalType('array', $parameters->toArray()[0]);
$this->assertInternalType('array', $parameters->toArray()[1]);
$parameters->remove($id);
$parameters->remove($id2);
$parameters->remove($parameter);
$this->assertNull($parameters->toArray());
// test $ref
$parameters->setRef('#/definitions/id');
$this->assertEquals(['$ref' => '#/definitions/id'], $parameters->toArray());
}
public function testResponses()
{
$operation = new Operation();
$responses = $operation->getResponses();
$this->assertInstanceOf(Responses::class, $responses);
$this->assertCount(0, $responses->toArray());
$this->assertFalse($responses->has('200'));
$ok = new Response();
$responses->set('200', $ok);
$this->assertCount(1, $responses->toArray());
$this->assertTrue($responses->has('200'));
$this->assertInstanceOf(Response::class, $responses->get('200'));
$this->assertSame($ok, $responses->get('200'));
$this->assertInternalType('array', $responses->toArray()['200']);
$responses->remove('200');
$this->assertCount(0, $responses->toArray());
$this->assertFalse($responses->has('200'));
}
}
================================================
FILE: tests/KeekoTest.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\tests;
use EXSyst\Component\Swagger\Swagger;
use PHPUnit\Framework\TestCase;
class KeekoTest extends TestCase
{
private function fileToArray($filename)
{
return json_decode(file_get_contents($filename), true);
}
public function testUser()
{
$filename = __DIR__.'/fixtures/keeko-user.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
}
================================================
FILE: tests/PetstoreTest.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\tests;
use EXSyst\Component\Swagger\Schema;
use EXSyst\Component\Swagger\Swagger;
use PHPUnit\Framework\TestCase;
class PetstoreTest extends TestCase
{
private function fileToArray($filename)
{
return json_decode(file_get_contents($filename), true);
}
public function testMinimal()
{
$filename = __DIR__.'/fixtures/petstore-minimal.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
public function testSimple()
{
$filename = __DIR__.'/fixtures/petstore-simple.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
public function testParameterRefs()
{
$filename = __DIR__.'/fixtures/petstore-parameter-refs.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
public function testPetstore()
{
$filename = __DIR__.'/fixtures/petstore.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
$responses = $swagger->getPaths()->get('/pets')->getOperation('get')->getResponses();
$headers = $responses->get('200')->getHeaders();
$this->assertEquals(1, count($headers->toArray()));
$this->assertTrue($headers->has('x-expires'));
$expires = $headers->get('x-expires');
$this->assertEquals('string', $expires->getType());
$headers->remove('x-expires');
$this->assertNull($headers->toArray());
$this->assertFalse($headers->has('x-expires'));
$headers->set('x-expires', $expires);
$this->assertCount(1, $headers->toArray());
$this->assertTrue($headers->has('x-expires'));
}
public function testExpanded()
{
$filename = __DIR__.'/fixtures/petstore-expanded.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
}
public function testExternalDocs()
{
$filename = __DIR__.'/fixtures/petstore-with-external-docs.json';
$swagger = Swagger::fromFile($filename);
$this->assertEquals($this->fileToArray($filename), $swagger->toArray());
$external = $swagger->getExternalDocs();
$this->assertEquals('find more info here', $external->getDescription());
$this->assertEquals('https://Swagger.io/about', $external->getUrl());
$info = $swagger->getInfo();
$this->assertEquals('1.0.0', $info->getVersion());
$this->assertEquals('Swagger Petstore', $info->getTitle());
$this->assertEquals('A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification', $info->getDescription());
$this->assertEquals('http://Swagger.io/terms/', $info->getTerms());
$this->assertEquals('1.0.1', $info->setVersion('1.0.1')->getVersion());
$this->assertEquals('Pets', $info->setTitle('Pets')->getTitle());
$this->assertEquals('desc', $info->setDescription('desc')->getDescription());
$this->assertEquals('T-O-S', $info->setTerms('T-O-S')->getTerms());
$contact = $info->getContact();
$this->assertEquals('Swagger API Team', $contact->getName());
$this->assertEquals('apiteam@Swagger.io', $contact->getEmail());
$this->assertEquals('http://Swagger.io', $contact->getUrl());
$this->assertEquals('Swaggers', $contact->setName('Swaggers')->getName());
$this->assertEquals('team@Swagger.io', $contact->setEmail('team@Swagger.io')->getEmail());
$this->assertEquals('https://Swagger.io', $contact->setUrl('https://Swagger.io')->getUrl());
$license = $info->getLicense();
$this->assertEquals('MIT', $license->getName());
$this->assertEquals('http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT', $license->getUrl());
$this->assertEquals('APL', $license->setName('APL')->getName());
$this->assertEquals('https://www.apache.org/licenses/LICENSE-2.0', $license->setUrl('https://www.apache.org/licenses/LICENSE-2.0')->getUrl());
}
public function testDictionaries()
{
$filename = __DIR__.'/fixtures/petstore-dictionaries.json';
$swagger = Swagger::fromFile($filename);
$swaggerAsArray = $swagger->toArray();
$this->assertEquals($this->fileToArray($filename), $swaggerAsArray);
$this->assertInstanceOf(Schema::class, $swagger->getDefinitions()->get('Pet')->getProperties()->get('sub-object')->getAdditionalProperties());
$this->assertSame(true, $swaggerAsArray['definitions']['Pet']['properties']['sub-object']['additionalProperties']);
$this->assertSame(null, $swagger->getDefinitions()->get('Pet')->getProperties()->get('sub-object')->getAdditionalProperties()->getType());
$this->assertSame(null, $swagger->getDefinitions()->get('Pet')->getProperties()->get('sub-object')->getAdditionalProperties()->getAdditionalProperties());
$this->assertSame('string', $swagger->getDefinitions()->get('Pet')->getProperties()->get('another-sub-object')->getAdditionalProperties()->getType());
$this->assertSame(null, $swagger->getDefinitions()->get('Pet')->getProperties()->get('another-sub-object')->getAdditionalProperties()->getAdditionalProperties());
$this->assertSame('object', $swagger->getDefinitions()->get('Pet')->getProperties()->get('nested-sub-objects')->getAdditionalProperties()->getType());
$this->assertInstanceOf(Schema::class, $swagger->getDefinitions()->get('Pet')->getProperties()->get('nested-sub-objects')->getAdditionalProperties()->getAdditionalProperties());
$this->assertSame('string', $swagger->getDefinitions()->get('Pet')->getProperties()->get('nested-sub-objects')->getAdditionalProperties()->getAdditionalProperties()->getType());
$this->assertSame('string', $swaggerAsArray['definitions']['Pet']['properties']['nested-sub-objects']['additionalProperties']['additionalProperties']['type']);
$this->assertSame('array', $swagger->getDefinitions()->get('Pet')->getProperties()->get('children')->getType());
$this->assertSame('array', $swaggerAsArray['definitions']['Pet']['properties']['children']['type']);
$this->assertInstanceOf(Schema::class, $swagger->getDefinitions()->get('Pet')->getProperties()->get('children')->getItems());
$this->assertSame('#/definitions/Pet', $swagger->getDefinitions()->get('Pet')->getProperties()->get('children')->getItems()->getRef());
$this->assertSame('#/definitions/Pet', $swaggerAsArray['definitions']['Pet']['properties']['children']['items']['$ref']);
$this->assertSame('object', $swaggerAsArray['definitions']['Pet']['properties']['child-pet']['type']);
$this->assertInstanceOf(Schema::class, $swagger->getDefinitions()->get('Pet')->getProperties()->get('child-pet')->getProperties()->get('name'));
$this->assertSame('string', $swagger->getDefinitions()->get('Pet')->getProperties()->get('child-pet')->getAdditionalProperties()->getProperties()->get('name')->getType());
$this->assertSame('string', $swaggerAsArray['definitions']['Pet']['properties']['child-pet']['additionalProperties']['properties']['name']['type']);
$this->assertSame('object', $swagger->getDefinitions()->get('Pet')->getProperties()->get('child-pet')->getAdditionalProperties()->getProperties()->get('child-pet-children')->getType());
$this->assertSame('string', $swagger->getDefinitions()->get('Pet')->getProperties()->get('child-pet')->getAdditionalProperties()->getProperties()->get('child-pet-children')->getAdditionalProperties()->getType());
$this->assertSame('object', $swagger->getDefinitions()->get('Pet')->getProperties()->get('child-pet')->getAdditionalProperties()->getProperties()->get('sub-object')->getType());
$this->assertSame(true, $swaggerAsArray['definitions']['Pet']['properties']['child-pet']['additionalProperties']['properties']['sub-object']['additionalProperties']);
}
}
================================================
FILE: tests/SwaggerTest.php
================================================
<?php
/*
* This file is part of the Swagger package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Component\Swagger\tests;
use EXSyst\Component\Swagger\Swagger;
use PHPUnit\Framework\TestCase;
class SwaggerTest extends TestCase
{
public function testVersion()
{
$swagger = new Swagger();
$this->assertEquals('2.0', $swagger->getVersion());
}
public function testBasics()
{
$swagger = new Swagger();
$swagger->setBasePath('/api');
$swagger->setHost('http://example.com');
$this->assertEquals('/api', $swagger->getBasePath());
$this->assertEquals('http://example.com', $swagger->getHost());
$this->assertEquals([
'swagger' => '2.0',
'host' => 'http://example.com',
'basePath' => '/api',
], $swagger->toArray());
}
}
================================================
FILE: tests/fixtures/basic-auth.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Basic Auth Example",
"description": "An example for how to use Basic Auth with Swagger.\nServer code is available [here](https://github.com/mohsen1/basic-auth-server). It's running on Heroku.\n\n**User Name and Password**\n* User Name: `user`\n* Password: `pass`\n"
},
"host": "basic-auth-server.herokuapp.com",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"basicAuth": {
"type": "basic",
"description": "HTTP Basic Authentication. Works over `HTTP` and `HTTPS`"
}
},
"paths": {
"/": {
"get": {
"security": [
{
"basicAuth": []
}
],
"responses": {
"200": {
"description": "Will send `Authenticated` if authentication is succesful, otherwise it will send `Unauthorized`"
}
}
}
}
}
}
================================================
FILE: tests/fixtures/keeko-user.json
================================================
{
"swagger": "2.0",
"paths": {
"/users": {
"get": {
"description": "List all users",
"operationId": "user-list",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Array of users",
"schema": {
"$ref": "#/definitions/PagedUsers"
}
}
}
},
"post": {
"description": "Creates an user",
"operationId": "user-create",
"schemes": ["https", "wss"],
"produces": [
"application/json"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"description": "The new user",
"schema": {
"$ref": "#/definitions/WritableUser"
}
}
],
"responses": {
"201": {
"description": "user created"
}
}
}
},
"/users/{id}": {
"get": {
"description": "Reads an user",
"operationId": "user-read",
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The user id",
"type": "integer"
}
],
"responses": {
"200": {
"description": "gets the user",
"schema": {
"$ref": "#/definitions/User"
}
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "No user found"
}
}
},
"put": {
"description": "Updates an user",
"operationId": "user-update",
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The user id",
"type": "integer"
}
],
"responses": {
"200": {
"description": "user updated",
"schema": {
"$ref": "#/definitions/User"
}
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "No user found"
}
}
},
"delete": {
"description": "Deletes an user",
"operationId": "user-delete",
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"description": "The user id",
"type": "integer"
}
],
"responses": {
"204": {
"description": "user deleted"
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "No user found"
}
}
}
}
},
"definitions": {
"Meta": {
"properties": {
"total": {
"type": "integer"
},
"first": {
"type": "integer"
},
"next": {
"type": "integer"
},
"previous": {
"type": "integer"
},
"last": {
"type": "integer"
}
}
},
"PagedUsers": {
"properties": {
"users": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
},
"meta": {
"$ref": "#/definitions/Meta"
}
}
},
"WritableUser": {
"properties": {
"id": {
"type": "int"
},
"login_name": {
"type": "string"
},
"password": {
"type": "string"
},
"given_name": {
"type": "string"
},
"family_name": {
"type": "string"
},
"display_name": {
"type": "string"
},
"email": {
"type": "string"
},
"birthday": {
"type": "string"
},
"sex": {
"type": "int"
},
"password_recover_code": {
"type": "string"
},
"password_recover_time": {
"type": "string"
}
}
},
"User": {
"properties": {
"id": {
"type": "int"
},
"login_name": {
"type": "string"
},
"password": {
"type": "string"
},
"given_name": {
"type": "string"
},
"family_name": {
"type": "string"
},
"display_name": {
"type": "string"
},
"email": {
"type": "string"
},
"birthday": {
"type": "string"
},
"sex": {
"type": "int"
},
"password_recover_code": {
"type": "string"
},
"password_recover_time": {
"type": "string"
},
"created_at": {
"type": "string"
},
"updated_at": {
"type": "string"
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore-dictionaries.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"contact": {
"name": "Swagger API Team",
"url": "http://Swagger.io"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "A list of pets.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"properties": {
"sub-object": {
"type": "object",
"additionalProperties": true
},
"another-sub-object": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"nested-sub-objects": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"children": {
"items": {
"$ref": "#/definitions/Pet"
},
"type": "array"
},
"child-pet": {
"type": "object",
"additionalProperties": {
"properties": {
"name": {
"type": "string"
},
"child-pet-children": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"sub-object": {
"type": "object",
"additionalProperties": true
}
}
}
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore-expanded.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification",
"termsOfService": "http://Swagger.io/terms/",
"contact": {
"name": "Swagger API Team",
"email": "foo@example.com",
"url": "http://madskristensen.net"
},
"license": {
"name": "MIT",
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
"operationId": "findPets",
"parameters": [
{
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"type": "array",
"collectionFormat": "csv",
"items": {
"type": "string"
}
},
{
"name": "limit",
"in": "query",
"description": "maximum number of results to return",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"post": {
"description": "Creates a new pet in the store. Duplicates are allowed",
"operationId": "addPet",
"parameters": [
{
"name": "pet",
"in": "body",
"description": "Pet to add to the store",
"required": true,
"schema": {
"$ref": "#/definitions/NewPet"
}
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
},
"/pets/{id}": {
"get": {
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
"operationId": "find pet by id",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to fetch",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"delete": {
"description": "deletes a single pet based on the ID supplied",
"operationId": "deletePet",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to delete",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"204": {
"description": "pet deleted"
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/NewPet"
},
{
"required": [
"id"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
}
}
]
},
"NewPet": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore-minimal.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification",
"termsOfService": "http://Swagger.io/terms/",
"contact": {
"name": "Swagger API Team"
},
"license": {
"name": "MIT"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "A list of pets.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore-parameter-refs.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification",
"termsOfService": "http://Swagger.io/terms/",
"contact": {
"name": "Swagger API Team"
},
"license": {
"name": "MIT"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"operationId": "findPets",
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv"
},
{
"name": "limit",
"in": "query",
"description": "maximum number of results to return",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"post": {
"description": "Creates a new pet in the store. Duplicates are allowed",
"operationId": "addPet",
"produces": [
"application/json"
],
"parameters": [
{
"name": "pet",
"in": "body",
"description": "Pet to add to the store",
"required": true,
"schema": {
"$ref": "#/definitions/PetInput"
}
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/pets/{id}": {
"get": {
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
"operationId": "findPetById",
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{ "$ref": "#/parameters/petId" }
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"delete": {
"description": "deletes a single pet based on the ID supplied",
"operationId": "deletePet",
"parameters": [
{ "$ref": "#/parameters/petId" }
],
"responses": {
"204": {
"description": "pet deleted"
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"PetInput": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"required": [
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
}
}
]
},
"ErrorModel": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
},
"parameters": {
"petId": {
"name": "id",
"in": "path",
"description": "Pet ID",
"required": true,
"type": "integer",
"format": "int64"
}
}
}
================================================
FILE: tests/fixtures/petstore-simple.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification",
"termsOfService": "http://Swagger.io/terms/",
"contact": {
"name": "Swagger API Team"
},
"license": {
"name": "MIT"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"operationId": "findPets",
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv"
},
{
"name": "limit",
"in": "query",
"description": "maximum number of results to return",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"post": {
"description": "Creates a new pet in the store. Duplicates are allowed",
"operationId": "addPet",
"produces": [
"application/json"
],
"parameters": [
{
"name": "pet",
"in": "body",
"description": "Pet to add to the store",
"required": true,
"schema": {
"$ref": "#/definitions/PetInput"
}
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/pets/{id}": {
"get": {
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
"operationId": "findPetById",
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to fetch",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"delete": {
"description": "deletes a single pet based on the ID supplied",
"operationId": "deletePet",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to delete",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"204": {
"description": "pet deleted"
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"PetInput": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"required": [
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
}
}
]
},
"ErrorModel": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore-with-external-docs.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the Swagger-2.0 specification",
"termsOfService": "http://Swagger.io/terms/",
"contact": {
"name": "Swagger API Team",
"email": "apiteam@Swagger.io",
"url": "http://Swagger.io"
},
"license": {
"name": "MIT",
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
}
},
"externalDocs": {
"description": "find more info here",
"url": "https://Swagger.io/about"
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"operationId": "findPets",
"externalDocs": {
"description": "find more info here",
"url": "https://Swagger.io/about"
},
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv"
},
{
"name": "limit",
"in": "query",
"description": "maximum number of results to return",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"post": {
"description": "Creates a new pet in the store. Duplicates are allowed",
"operationId": "addPet",
"produces": [
"application/json"
],
"parameters": [
{
"name": "pet",
"in": "body",
"description": "Pet to add to the store",
"required": true,
"schema": {
"$ref": "#/definitions/NewPet"
}
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/pets/{id}": {
"get": {
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
"operationId": "findPetById",
"produces": [
"application/json",
"application/xml",
"text/xml",
"text/html"
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to fetch",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"description": "pet response",
"schema": {
"$ref": "#/definitions/Pet"
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
},
"delete": {
"description": "deletes a single pet based on the ID supplied",
"operationId": "deletePet",
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to delete",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"204": {
"description": "pet deleted"
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"externalDocs": {
"description": "find more info here",
"url": "https://Swagger.io/about"
},
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"NewPet": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"required": [
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
}
}
]
},
"ErrorModel": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
================================================
FILE: tests/fixtures/petstore.json
================================================
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"contact": {
"name": "Swagger API Team",
"url": "http://Swagger.io"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
}
},
"host": "petstore.Swagger.io",
"basePath": "/api",
"schemes": [
"http"
],
"paths": {
"/pets": {
"get": {
"tags": [ "Pet Operations" ],
"summary": "finds pets in the system",
"responses": {
"200": {
"description": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Pet"
}
},
"headers": {
"x-expires": {
"type": "string"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
gitextract_3xv09ez2/
├── .gitattributes
├── .gitignore
├── .php_cs.dist
├── .travis.yml
├── LICENSE
├── README.md
├── composer.json
├── phpunit
├── phpunit.xml.dist
├── src/
│ ├── AbstractModel.php
│ ├── Collections/
│ │ ├── Definitions.php
│ │ ├── Headers.php
│ │ ├── Parameters.php
│ │ ├── Paths.php
│ │ └── Responses.php
│ ├── Contact.php
│ ├── ExternalDocs.php
│ ├── Header.php
│ ├── Info.php
│ ├── Items.php
│ ├── License.php
│ ├── Operation.php
│ ├── Parameter.php
│ ├── Parts/
│ │ ├── ConsumesPart.php
│ │ ├── DescriptionPart.php
│ │ ├── ExtensionPart.php
│ │ ├── ExternalDocsPart.php
│ │ ├── ItemsPart.php
│ │ ├── ParametersPart.php
│ │ ├── ProducesPart.php
│ │ ├── RefPart.php
│ │ ├── RequiredPart.php
│ │ ├── ResponsesPart.php
│ │ ├── SchemaPart.php
│ │ ├── SchemesPart.php
│ │ ├── SecurityPart.php
│ │ ├── TagsPart.php
│ │ ├── TypePart.php
│ │ └── UrlPart.php
│ ├── Path.php
│ ├── Response.php
│ ├── Schema.php
│ ├── SecurityScheme.php
│ ├── Swagger.php
│ ├── Tag.php
│ └── Util/
│ └── MergeHelper.php
└── tests/
├── BasicAuthTest.php
├── CollectionsTest.php
├── KeekoTest.php
├── PetstoreTest.php
├── SwaggerTest.php
└── fixtures/
├── basic-auth.json
├── keeko-user.json
├── petstore-dictionaries.json
├── petstore-expanded.json
├── petstore-minimal.json
├── petstore-parameter-refs.json
├── petstore-simple.json
├── petstore-with-external-docs.json
└── petstore.json
SYMBOL INDEX (297 symbols across 42 files)
FILE: src/AbstractModel.php
class AbstractModel (line 17) | abstract class AbstractModel
method merge (line 21) | public function merge($data, $overwrite = false)
method toArray (line 26) | public function toArray()
method doMerge (line 51) | abstract protected function doMerge($data, $overwrite = false);
method normalize (line 53) | protected function normalize($data)
method resolve (line 62) | private function resolve($value)
FILE: src/Collections/Definitions.php
class Definitions (line 17) | final class Definitions extends AbstractModel implements \IteratorAggregate
method __construct (line 23) | public function __construct($data = [])
method doMerge (line 28) | protected function doMerge($data, $overwrite = false)
method doExport (line 35) | protected function doExport(): array
method get (line 43) | public function get(string $name): Schema
method set (line 55) | public function set(string $name, Schema $schema): self
method remove (line 65) | public function remove(string $name): self
method has (line 75) | public function has(string $name): bool
method getIterator (line 80) | public function getIterator(): \ArrayIterator
FILE: src/Collections/Headers.php
class Headers (line 17) | final class Headers extends AbstractModel implements \IteratorAggregate
method __construct (line 23) | public function __construct($data = [])
method doMerge (line 28) | protected function doMerge($data, $overwrite = false)
method doExport (line 35) | protected function doExport(): array
method has (line 43) | public function has(string $header): bool
method get (line 51) | public function get($header): Header
method set (line 63) | public function set(string $name, Header $header): self
method remove (line 73) | public function remove(string $header): self
method getIterator (line 80) | public function getIterator(): \ArrayIterator
FILE: src/Collections/Parameters.php
class Parameters (line 18) | final class Parameters extends AbstractModel implements \IteratorAggregate
method __construct (line 26) | public function __construct($data = [])
method doMerge (line 31) | protected function doMerge($data, $overwrite = false)
method doExport (line 41) | protected function doExport(): array
method has (line 53) | public function has(string $name, string $in = null): bool
method get (line 60) | public function get(string $name, string $in = null): Parameter
method add (line 76) | public function add(Parameter $parameter): self
method remove (line 86) | public function remove(Parameter $parameter): self
method getIdentifier (line 93) | private function getIdentifier(Parameter $parameter)
method getIterator (line 102) | public function getIterator(): \ArrayIterator
FILE: src/Collections/Paths.php
class Paths (line 18) | final class Paths extends AbstractModel implements \IteratorAggregate
method __construct (line 26) | public function __construct($data = [])
method doMerge (line 31) | protected function doMerge($data, $overwrite = false)
method doExport (line 42) | protected function doExport(): array
method has (line 50) | public function has(string $path): bool
method get (line 58) | public function get(string $path): Path
method set (line 70) | public function set(string $path, Path $model): self
method remove (line 80) | public function remove(string $path): self
method getIterator (line 87) | public function getIterator(): \ArrayIterator
FILE: src/Collections/Responses.php
class Responses (line 18) | final class Responses extends AbstractModel implements \IteratorAggregate
method __construct (line 24) | public function __construct($data = [])
method doMerge (line 29) | protected function doMerge($data, $overwrite = false)
method doExport (line 40) | protected function doExport(): array
method has (line 48) | public function has($code): bool
method get (line 56) | public function get($code): Response
method set (line 68) | public function set($code, Response $response): self
method remove (line 78) | public function remove($code): self
method getIterator (line 85) | public function getIterator(): \ArrayIterator
FILE: src/Contact.php
class Contact (line 17) | final class Contact extends AbstractModel
method __construct (line 32) | public function __construct($data = [])
method doMerge (line 37) | protected function doMerge($data, $overwrite = false)
method doExport (line 46) | protected function doExport(): array
method getName (line 58) | public function getName()
method setName (line 66) | public function setName($name): self
method getUrl (line 76) | public function getUrl()
method setUrl (line 84) | public function setUrl($url): self
method getEmail (line 94) | public function getEmail()
method setEmail (line 102) | public function setEmail($email): self
FILE: src/ExternalDocs.php
class ExternalDocs (line 18) | final class ExternalDocs extends AbstractModel
method __construct (line 26) | public function __construct($data = [])
method doMerge (line 31) | protected function doMerge($data, $overwrite = false)
method doExport (line 38) | protected function doExport(): array
FILE: src/Header.php
class Header (line 19) | final class Header extends AbstractModel
method __construct (line 26) | public function __construct($data = [])
method doMerge (line 31) | protected function doMerge($data, $overwrite = false)
method doExport (line 39) | public function doExport(): array
FILE: src/Info.php
class Info (line 18) | final class Info extends AbstractModel
method __construct (line 40) | public function __construct($data = [])
method doMerge (line 48) | protected function doMerge($data, $overwrite = false)
method doExport (line 61) | protected function doExport(): array
method getTitle (line 76) | public function getTitle()
method setTitle (line 84) | public function setTitle($title): self
method getTerms (line 94) | public function getTerms()
method setTerms (line 102) | public function setTerms($terms): self
method getContact (line 112) | public function getContact()
method getLicense (line 120) | public function getLicense()
method getVersion (line 128) | public function getVersion()
method setVersion (line 138) | public function setVersion($version): self
FILE: src/Items.php
class Items (line 14) | final class Items extends Schema
FILE: src/License.php
class License (line 18) | final class License extends AbstractModel
method __construct (line 28) | public function __construct($data = [])
method doMerge (line 33) | protected function doMerge($data, $overwrite = false)
method doExport (line 41) | protected function doExport(): array
method getName (line 52) | public function getName()
method setName (line 60) | public function setName($name): self
FILE: src/Operation.php
class Operation (line 25) | final class Operation extends AbstractModel
method __construct (line 49) | public function __construct($data = [])
method doMerge (line 54) | protected function doMerge($data, $overwrite = false)
method doExport (line 72) | protected function doExport(): array
method getSummary (line 93) | public function getSummary()
method setSummary (line 101) | public function setSummary($summary): self
method getDescription (line 111) | public function getDescription()
method setDescription (line 119) | public function setDescription($description): self
method getOperationId (line 129) | public function getOperationId()
method setOperationId (line 137) | public function setOperationId($operationId): self
method getDeprecated (line 147) | public function getDeprecated()
method setDeprecated (line 155) | public function setDeprecated($deprecated): self
FILE: src/Parameter.php
class Parameter (line 23) | final class Parameter extends AbstractModel
method __construct (line 42) | public function __construct($data = [])
method doMerge (line 57) | protected function doMerge($data, $overwrite = false)
method doExport (line 70) | protected function doExport(): array
method getName (line 93) | public function getName()
method getIn (line 101) | public function getIn()
method getAllowEmptyValue (line 109) | public function getAllowEmptyValue()
method setAllowEmptyValue (line 121) | public function setAllowEmptyValue($allowEmptyValue): self
FILE: src/Parts/ConsumesPart.php
type ConsumesPart (line 19) | trait ConsumesPart
method mergeConsumes (line 23) | private function mergeConsumes(array $data, bool $overwrite)
method getConsumes (line 31) | public function getConsumes()
FILE: src/Parts/DescriptionPart.php
type DescriptionPart (line 19) | trait DescriptionPart
method mergeDescription (line 24) | private function mergeDescription(array $data, bool $overwrite)
method getDescription (line 32) | public function getDescription()
method setDescription (line 42) | public function setDescription(string $description = null): self
FILE: src/Parts/ExtensionPart.php
type ExtensionPart (line 17) | trait ExtensionPart
method mergeExtensions (line 21) | private function mergeExtensions(array $data, bool $overwrite)
method getExtensions (line 35) | public function getExtensions(): array
FILE: src/Parts/ExternalDocsPart.php
type ExternalDocsPart (line 19) | trait ExternalDocsPart
method mergeExternalDocs (line 24) | private function mergeExternalDocs(array $data, bool $overwrite)
method getExternalDocs (line 34) | public function getExternalDocs(): ExternalDocs
method setExternalDocs (line 43) | public function setExternalDocs(ExternalDocs $externalDocs): self
FILE: src/Parts/ItemsPart.php
type ItemsPart (line 19) | trait ItemsPart
method mergeItems (line 24) | private function mergeItems(array $data, bool $overwrite)
method getItems (line 34) | public function getItems(): Items
FILE: src/Parts/ParametersPart.php
type ParametersPart (line 19) | trait ParametersPart
method mergeParameters (line 24) | private function mergeParameters(array $data, bool $overwrite)
method getParameters (line 34) | public function getParameters(): Parameters
FILE: src/Parts/ProducesPart.php
type ProducesPart (line 17) | trait ProducesPart
method mergeProduces (line 21) | private function mergeProduces(array $data, bool $overwrite)
method getProduces (line 31) | public function getProduces(): array
FILE: src/Parts/RefPart.php
type RefPart (line 17) | trait RefPart
method mergeRef (line 22) | private function mergeRef(array $data, bool $overwrite)
method getRef (line 30) | public function getRef()
method setRef (line 38) | public function setRef(string $ref = null): self
method hasRef (line 45) | public function hasRef(): bool
FILE: src/Parts/RequiredPart.php
type RequiredPart (line 19) | trait RequiredPart
method mergeRequired (line 24) | private function mergeRequired(array $data, bool $overwrite)
method getRequired (line 32) | public function getRequired()
method setRequired (line 40) | public function setRequired(bool $required = null): self
FILE: src/Parts/ResponsesPart.php
type ResponsesPart (line 19) | trait ResponsesPart
method mergeResponses (line 24) | private function mergeResponses(array $data, bool $overwrite)
method getResponses (line 34) | public function getResponses(): Responses
FILE: src/Parts/SchemaPart.php
type SchemaPart (line 19) | trait SchemaPart
method mergeSchema (line 24) | private function mergeSchema(array $data, bool $overwrite)
method getSchema (line 31) | public function getSchema(): Schema
FILE: src/Parts/SchemesPart.php
type SchemesPart (line 17) | trait SchemesPart
method mergeSchemes (line 21) | private function mergeSchemes(array $data, bool $overwrite)
method getSchemes (line 31) | public function getSchemes(): array
FILE: src/Parts/SecurityPart.php
type SecurityPart (line 19) | trait SecurityPart
method mergeSecurity (line 24) | private function mergeSecurity(array $data, bool $overwrite)
method getSecurity (line 32) | public function getSecurity()
method setSecurity (line 37) | public function setSecurity(array $security = null): self
FILE: src/Parts/TagsPart.php
type TagsPart (line 19) | trait TagsPart
method mergeTags (line 23) | private function mergeTags(array $data, bool $overwrite)
method getTags (line 34) | public function getTags(): array
method exportTags (line 39) | protected function exportTags(): array
FILE: src/Parts/TypePart.php
type TypePart (line 19) | trait TypePart
method mergeType (line 69) | private function mergeType(array $data, bool $overwrite)
method doExportType (line 76) | protected function doExportType(): array
method getTypeFields (line 86) | private function getTypeFields(): array
method getType (line 111) | public function getType()
method setType (line 119) | public function setType($type): self
method getFormat (line 129) | public function getFormat()
method setFormat (line 139) | public function setFormat($format): self
method getCollectionFormat (line 149) | public function getCollectionFormat()
method setCollectionFormat (line 169) | public function setCollectionFormat($collectionFormat): self
method getDefault (line 179) | public function getDefault()
method setDefault (line 187) | public function setDefault($default): self
method getMaximum (line 197) | public function getMaximum()
method setMaximum (line 205) | public function setMaximum($maximum): self
method isExclusiveMaximum (line 215) | public function isExclusiveMaximum()
method setExclusiveMaximum (line 223) | public function setExclusiveMaximum($exclusiveMaximum): self
method getMinimum (line 233) | public function getMinimum()
method setMinimum (line 241) | public function setMinimum($minimum): self
method isExclusiveMinimum (line 251) | public function isExclusiveMinimum()
method setExclusiveMinimum (line 261) | public function setExclusiveMinimum($exclusiveMinimum)
method getMaxLength (line 271) | public function getMaxLength()
method setMaxLength (line 279) | public function setMaxLength($maxLength): self
method getMinLength (line 289) | public function getMinLength()
method setMinLength (line 297) | public function setMinLength($minLength): self
method getPattern (line 307) | public function getPattern()
method setPattern (line 315) | public function setPattern($pattern): self
method getMaxItems (line 325) | public function getMaxItems()
method setMaxItems (line 333) | public function setMaxItems($maxItems): self
method getMinItems (line 343) | public function getMinItems()
method setMinItems (line 351) | public function setMinItems($minItems): self
method hasUniqueItems (line 361) | public function hasUniqueItems()
method setUniqueItems (line 369) | public function setUniqueItems($uniqueItems): self
method getEnum (line 379) | public function getEnum()
method setEnum (line 387) | public function setEnum($enum): self
method getMultipleOf (line 397) | public function getMultipleOf()
method setMultipleOf (line 405) | public function setMultipleOf($multipleOf): self
FILE: src/Parts/UrlPart.php
type UrlPart (line 19) | trait UrlPart
method mergeUrl (line 24) | private function mergeUrl(array $data, bool $overwrite)
method getUrl (line 32) | public function getUrl()
method setUrl (line 40) | public function setUrl(string $url = null): self
FILE: src/Path.php
class Path (line 17) | final class Path extends AbstractModel
method __construct (line 24) | public function __construct($data = [])
method doMerge (line 29) | protected function doMerge($data, $overwrite = false)
method doExport (line 40) | protected function doExport(): array
method getOperations (line 45) | public function getOperations(): array
method getOperation (line 53) | public function getOperation(string $method): Operation
method setOperation (line 65) | public function setOperation(string $method, Operation $operation): self
method hasOperation (line 72) | public function hasOperation(string $method): bool
method removeOperation (line 80) | public function removeOperation(string $method): self
method getMethods (line 90) | public function getMethods(): array
FILE: src/Response.php
class Response (line 21) | final class Response extends AbstractModel
method __construct (line 33) | public function __construct($data = [])
method doMerge (line 40) | protected function doMerge($data, $overwrite = false)
method doExport (line 55) | protected function doExport(): array
method getExamples (line 69) | public function getExamples(): array
method getHeaders (line 77) | public function getHeaders(): Headers
FILE: src/Schema.php
class Schema (line 23) | class Schema extends AbstractModel
method __construct (line 56) | public function __construct($data = [])
method doMerge (line 62) | protected function doMerge($data, $overwrite = false)
method doExport (line 96) | protected function doExport()
method getRequired (line 124) | public function getRequired()
method setRequired (line 134) | public function setRequired($required)
method getDiscriminator (line 144) | public function getDiscriminator()
method setDiscriminator (line 154) | public function setDiscriminator($discriminator)
method isReadOnly (line 164) | public function isReadOnly()
method setReadOnly (line 174) | public function setReadOnly($readOnly)
method getExample (line 184) | public function getExample()
method setExample (line 194) | public function setExample($example)
method getTitle (line 204) | public function getTitle()
method setTitle (line 214) | public function setTitle($title)
method getProperties (line 224) | public function getProperties()
method getAllOf (line 232) | public function getAllOf(): array
method getAdditionalProperties (line 240) | public function getAdditionalProperties()
FILE: src/SecurityScheme.php
class SecurityScheme (line 17) | class SecurityScheme extends AbstractModel
method __construct (line 42) | public function __construct($data = [])
method getName (line 52) | public function getName()
method setName (line 64) | public function setName($name)
method getType (line 76) | public function getType()
method setType (line 88) | public function setType($type)
method getIn (line 100) | public function getIn()
method setIn (line 112) | public function setIn($in)
method getFlow (line 124) | public function getFlow()
method setFlow (line 136) | public function setFlow($flow)
method getAuthorizationUrl (line 148) | public function getAuthorizationUrl()
method setAuthorizationUrl (line 160) | public function setAuthorizationUrl($authorizationUrl)
method getTokenUrl (line 172) | public function getTokenUrl()
method setTokenUrl (line 184) | public function setTokenUrl($tokenUrl)
method getScopes (line 196) | public function getScopes()
method setScopes (line 204) | public function setScopes(array $scopes = null)
method doMerge (line 211) | protected function doMerge($data, $overwrite = false)
method doExport (line 224) | protected function doExport()
FILE: src/Swagger.php
class Swagger (line 26) | final class Swagger extends AbstractModel
method fromFile (line 65) | public static function fromFile(string $filename): self
method __construct (line 70) | public function __construct($data = [])
method doMerge (line 79) | protected function doMerge($data, $overwrite = false)
method doExport (line 112) | protected function doExport(): array
method getVersion (line 136) | public function getVersion(): string
method getInfo (line 144) | public function getInfo()
method getHost (line 152) | public function getHost()
method setHost (line 160) | public function setHost($host): self
method getBasePath (line 170) | public function getBasePath()
method setBasePath (line 180) | public function setBasePath($basePath)
method getPaths (line 190) | public function getPaths()
method getDefinitions (line 198) | public function getDefinitions()
method getSecurityDefinitions (line 206) | public function getSecurityDefinitions()
method getParameters (line 214) | public function getParameters()
method setParameters (line 222) | public function setParameters(array $parameters): self
FILE: src/Tag.php
class Tag (line 18) | final class Tag extends AbstractModel
method __construct (line 26) | public function __construct($data)
method doMerge (line 37) | protected function doMerge($data, $overwrite = false)
method toArray (line 44) | public function toArray()
method doExport (line 54) | protected function doExport(): array
method getName (line 66) | public function getName(): string
method normalize (line 76) | protected function normalize($data): array
FILE: src/Util/MergeHelper.php
class MergeHelper (line 17) | class MergeHelper
method mergeFields (line 24) | public static function mergeFields(&$original, $external, $overwrite)
FILE: tests/BasicAuthTest.php
class BasicAuthTest (line 17) | class BasicAuthTest extends TestCase
method fileToArray (line 19) | private function fileToArray($filename)
method testUser (line 24) | public function testUser()
FILE: tests/CollectionsTest.php
class CollectionsTest (line 26) | class CollectionsTest extends TestCase
method testDefinitions (line 28) | public function testDefinitions()
method testPaths (line 50) | public function testPaths()
method testParameters (line 73) | public function testParameters()
method testResponses (line 116) | public function testResponses()
FILE: tests/KeekoTest.php
class KeekoTest (line 17) | class KeekoTest extends TestCase
method fileToArray (line 19) | private function fileToArray($filename)
method testUser (line 24) | public function testUser()
FILE: tests/PetstoreTest.php
class PetstoreTest (line 18) | class PetstoreTest extends TestCase
method fileToArray (line 20) | private function fileToArray($filename)
method testMinimal (line 25) | public function testMinimal()
method testSimple (line 33) | public function testSimple()
method testParameterRefs (line 41) | public function testParameterRefs()
method testPetstore (line 49) | public function testPetstore()
method testExpanded (line 74) | public function testExpanded()
method testExternalDocs (line 82) | public function testExternalDocs()
method testDictionaries (line 121) | public function testDictionaries()
FILE: tests/SwaggerTest.php
class SwaggerTest (line 17) | class SwaggerTest extends TestCase
method testVersion (line 19) | public function testVersion()
method testBasics (line 25) | public function testBasics()
Condensed preview — 60 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (136K chars).
[
{
"path": ".gitattributes",
"chars": 56,
"preview": ".* export-ignore\n*.md export-ignore\ntests export-ignore\n"
},
{
"path": ".gitignore",
"chars": 83,
"preview": ".buildpath\n.php_cs.cache\ncomposer.phar\ncomposer.lock\nphpunit.xml\nvendor/\ncoverage/\n"
},
{
"path": ".php_cs.dist",
"chars": 545,
"preview": "<?php\n\n$finder = PhpCsFixer\\Finder::create()\n ->in(__DIR__)\n ->exclude('Tests/Functional/cache')\n;\n\nreturn PhpCsFi"
},
{
"path": ".travis.yml",
"chars": 436,
"preview": "language: php\n\nphp:\n - 7.0\n - 7.1\n - 7.2\n - 7.3\n - 7.4\n\nsudo: false\n\ncache:\n directories:\n - $HOME/.composer/ca"
},
{
"path": "LICENSE",
"chars": 1083,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Thomas Gossmann\n\nPermission is hereby granted, free of charge, to any person o"
},
{
"path": "README.md",
"chars": 1442,
"preview": "# Swagger\n\n[](https://travis-ci.org/GuilhemN/sw"
},
{
"path": "composer.json",
"chars": 511,
"preview": "{\n\t\"name\" : \"exsyst/swagger\",\n\t\"description\" : \"A php library to manipulate Swagger specifications\",\n\t\"type\" : \"library\""
},
{
"path": "phpunit",
"chars": 399,
"preview": "#!/usr/bin/env php\n<?php\nif (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {\n echo \"Unab"
},
{
"path": "phpunit.xml.dist",
"chars": 785,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!-- https://phpunit.de/manual/6.5/en/appendixes.configuration.html -->\n<phpunit"
},
{
"path": "src/AbstractModel.php",
"chars": 1636,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Collections/Definitions.php",
"chars": 1747,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Collections/Headers.php",
"chars": 1729,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Collections/Parameters.php",
"chars": 2421,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Collections/Paths.php",
"chars": 1868,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Collections/Responses.php",
"chars": 1875,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Contact.php",
"chars": 1985,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/ExternalDocs.php",
"chars": 1004,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Header.php",
"chars": 1166,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Info.php",
"chars": 2964,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Items.php",
"chars": 309,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/License.php",
"chars": 1287,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Operation.php",
"chars": 4052,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parameter.php",
"chars": 3243,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ConsumesPart.php",
"chars": 652,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/DescriptionPart.php",
"chars": 930,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ExtensionPart.php",
"chars": 742,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ExternalDocsPart.php",
"chars": 1012,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ItemsPart.php",
"chars": 773,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ParametersPart.php",
"chars": 855,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ProducesPart.php",
"chars": 650,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/RefPart.php",
"chars": 811,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/RequiredPart.php",
"chars": 863,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/ResponsesPart.php",
"chars": 840,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/SchemaPart.php",
"chars": 761,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/SchemesPart.php",
"chars": 640,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/SecurityPart.php",
"chars": 811,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/TagsPart.php",
"chars": 881,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/TypePart.php",
"chars": 7427,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Parts/UrlPart.php",
"chars": 806,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Path.php",
"chars": 2166,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Response.php",
"chars": 2030,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Schema.php",
"chars": 5767,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/SecurityScheme.php",
"chars": 4929,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Swagger.php",
"chars": 5416,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Tag.php",
"chars": 1857,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "src/Util/MergeHelper.php",
"chars": 682,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/BasicAuthTest.php",
"chars": 714,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/CollectionsTest.php",
"chars": 4577,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/KeekoTest.php",
"chars": 710,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/PetstoreTest.php",
"chars": 8482,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/SwaggerTest.php",
"chars": 977,
"preview": "<?php\n\n/*\n * This file is part of the Swagger package.\n *\n * (c) EXSyst\n *\n * For the full copyright and license informa"
},
{
"path": "tests/fixtures/basic-auth.json",
"chars": 841,
"preview": "{\n\t\"swagger\": \"2.0\",\n\t\"info\": {\n\t\t\"version\": \"1.0.0\",\n\t\t\"title\": \"Basic Auth Example\",\n\t\t\"description\": \"An example for "
},
{
"path": "tests/fixtures/keeko-user.json",
"chars": 4236,
"preview": "{\n\t\"swagger\": \"2.0\",\n\t\"paths\": {\n\t\t\"/users\": {\n\t\t\t\"get\": {\n\t\t\t\t\"description\": \"List all users\",\n\t\t\t\t\"operationId\": \"user"
},
{
"path": "tests/fixtures/petstore-dictionaries.json",
"chars": 2129,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"contact\": {\n \"name\""
},
{
"path": "tests/fixtures/petstore-expanded.json",
"chars": 6446,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample "
},
{
"path": "tests/fixtures/petstore-minimal.json",
"chars": 1372,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample "
},
{
"path": "tests/fixtures/petstore-parameter-refs.json",
"chars": 5132,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample "
},
{
"path": "tests/fixtures/petstore-simple.json",
"chars": 5291,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample "
},
{
"path": "tests/fixtures/petstore-with-external-docs.json",
"chars": 5785,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample "
},
{
"path": "tests/fixtures/petstore.json",
"chars": 1731,
"preview": "{\n \"swagger\": \"2.0\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"contact\": {\n \"name\""
}
]
About this extraction
This page contains the full source code of the GuilhemN/swagger GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 60 files (120.5 KB), approximately 31.5k tokens, and a symbol index with 297 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.