forked from loafle/openapi-generator-original
[php-slim4] Move Data Mocker to external repo (#5930)
* Remove package from sources * Add Mocker package * Add BaseModel Beside setters and getters this class implements three methods required for mocking: getOpenApiSchema, createFromData and jsonSerialize. BaseModel keeps all data values in $dataContainer like PHP client does. I don't see other way to support scalar models(enum for instance). That's why I've removed class variables generation. * Update documentation * Update PHPUnit section in readme * Add constant with models namespace This constant will be required for data deserialization when handling refs. * Refresh samples * Add samples generation config
This commit is contained in:
parent
313d205f56
commit
e49804fd7f
4
bin/configs/php-slim4.yaml
Normal file
4
bin/configs/php-slim4.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
generatorName: php-slim4
|
||||
outputDir: samples/server/petstore/php-slim4
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/php-slim4-server
|
@ -32,10 +32,6 @@ public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
|
||||
public static final String PSR7_IMPLEMENTATION = "psr7Implementation";
|
||||
|
||||
protected String psr7Implementation = "slim-psr7";
|
||||
protected String mockDirName = "Mock";
|
||||
protected String mockPackage = "";
|
||||
protected String utilsDirName = "Utils";
|
||||
protected String utilsPackage = "";
|
||||
protected String interfacesDirName = "Interfaces";
|
||||
protected String interfacesPackage = "";
|
||||
|
||||
@ -46,8 +42,6 @@ public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
|
||||
.stability(Stability.STABLE)
|
||||
.build();
|
||||
|
||||
mockPackage = invokerPackage + "\\" + mockDirName;
|
||||
utilsPackage = invokerPackage + "\\" + utilsDirName;
|
||||
interfacesPackage = invokerPackage + "\\" + interfacesDirName;
|
||||
outputFolder = "generated-code" + File.separator + "slim4";
|
||||
embeddedTemplateDir = templateDir = "php-slim4-server";
|
||||
@ -84,30 +78,15 @@ public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
// Update mockPackage and utilsPackage
|
||||
mockPackage = invokerPackage + "\\" + mockDirName;
|
||||
utilsPackage = invokerPackage + "\\" + utilsDirName;
|
||||
// Update interfacesPackage
|
||||
interfacesPackage = invokerPackage + "\\" + interfacesDirName;
|
||||
}
|
||||
|
||||
// make mock src path available in mustache template
|
||||
additionalProperties.put("mockPackage", mockPackage);
|
||||
additionalProperties.put("mockSrcPath", "./" + toSrcPath(mockPackage, srcBasePath));
|
||||
additionalProperties.put("mockTestPath", "./" + toSrcPath(mockPackage, testBasePath));
|
||||
|
||||
// same for utils package
|
||||
additionalProperties.put("utilsPackage", utilsPackage);
|
||||
additionalProperties.put("utilsSrcPath", "./" + toSrcPath(utilsPackage, srcBasePath));
|
||||
additionalProperties.put("utilsTestPath", "./" + toSrcPath(utilsPackage, testBasePath));
|
||||
|
||||
// same for interfaces package
|
||||
additionalProperties.put("interfacesPackage", interfacesPackage);
|
||||
additionalProperties.put("interfacesSrcPath", "./" + toSrcPath(interfacesPackage, srcBasePath));
|
||||
additionalProperties.put("interfacesTestPath", "./" + toSrcPath(interfacesPackage, testBasePath));
|
||||
|
||||
// external docs folder
|
||||
additionalProperties.put("docsBasePath", "./" + docsBasePath);
|
||||
|
||||
if (additionalProperties.containsKey(PSR7_IMPLEMENTATION)) {
|
||||
this.setPsr7Implementation((String) additionalProperties.get(PSR7_IMPLEMENTATION));
|
||||
}
|
||||
@ -140,23 +119,8 @@ public class PhpSlim4ServerCodegen extends PhpSlimServerCodegen {
|
||||
// Slim 4 doesn't parse JSON body anymore we need to add suggested middleware
|
||||
// ref: https://www.slimframework.com/docs/v4/objects/request.html#the-request-body
|
||||
supportingFiles.add(new SupportingFile("json_body_parser_middleware.mustache", toSrcPath(invokerPackage + "\\Middleware", srcBasePath), "JsonBodyParserMiddleware.php"));
|
||||
|
||||
// mocking feature
|
||||
supportingFiles.add(new SupportingFile("openapi_data_mocker_interface.mustache", toSrcPath(mockPackage, srcBasePath), toInterfaceName("OpenApiDataMocker") + ".php"));
|
||||
supportingFiles.add(new SupportingFile("openapi_data_mocker.mustache", toSrcPath(mockPackage, srcBasePath), "OpenApiDataMocker.php"));
|
||||
supportingFiles.add(new SupportingFile("openapi_data_mocker_test.mustache", toSrcPath(mockPackage, testBasePath), "OpenApiDataMockerTest.php"));
|
||||
supportingFiles.add(new SupportingFile("openapi_data_mocker_middleware.mustache", toSrcPath(mockPackage, srcBasePath), "OpenApiDataMockerMiddleware.php"));
|
||||
supportingFiles.add(new SupportingFile("openapi_data_mocker_middleware_test.mustache", toSrcPath(mockPackage, testBasePath), "OpenApiDataMockerMiddlewareTest.php"));
|
||||
supportingFiles.add(new SupportingFile("mock_server.mustache", docsBasePath, "MockServer.md"));
|
||||
|
||||
// traits of ported utils
|
||||
supportingFiles.add(new SupportingFile("string_utils_trait.mustache", toSrcPath(utilsPackage, srcBasePath), toTraitName("StringUtils") + ".php"));
|
||||
supportingFiles.add(new SupportingFile("string_utils_trait_test.mustache", toSrcPath(utilsPackage, testBasePath), toTraitName("StringUtils") + "Test.php"));
|
||||
supportingFiles.add(new SupportingFile("model_utils_trait.mustache", toSrcPath(utilsPackage, srcBasePath), toTraitName("ModelUtils") + ".php"));
|
||||
supportingFiles.add(new SupportingFile("model_utils_trait_test.mustache", toSrcPath(utilsPackage, testBasePath), toTraitName("ModelUtils") + "Test.php"));
|
||||
|
||||
// model interface
|
||||
supportingFiles.add(new SupportingFile("model_interface.mustache", toSrcPath(interfacesPackage, srcBasePath), toInterfaceName("Model") + ".php"));
|
||||
supportingFiles.add(new SupportingFile("base_model.mustache", toSrcPath(invokerPackage, srcBasePath), "BaseModel.php"));
|
||||
supportingFiles.add(new SupportingFile("base_model_test.mustache", toSrcPath(invokerPackage, testBasePath), "BaseModelTest.php"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,9 +46,9 @@ $ php -S localhost:8888 -t php-slim-server
|
||||
|
||||
### PHPUnit
|
||||
|
||||
This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing.
|
||||
This package uses PHPUnit 8 or 9(depends from your PHP version) for unit testing.
|
||||
[Test folder]({{testBasePath}}) contains templates which you can fill with real test assertions.
|
||||
How to write tests read at [PHPUnit Manual - Chapter 2. Writing Tests for PHPUnit](https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html).
|
||||
How to write tests read at [2. Writing Tests for PHPUnit - PHPUnit 8.5 Manual](https://phpunit.readthedocs.io/en/8.5/writing-tests-for-phpunit.html).
|
||||
|
||||
#### Run
|
||||
|
||||
@ -57,14 +57,12 @@ Command | Target
|
||||
`$ composer test` | All tests
|
||||
`$ composer test-apis` | Apis tests
|
||||
`$ composer test-models` | Models tests
|
||||
`$ composer test-mock` | Mock feature tests
|
||||
`$ composer test-utils` | Utils tests
|
||||
|
||||
#### Config
|
||||
|
||||
Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it.
|
||||
|
||||
Quote from [3. The Command-Line Test Runner — PHPUnit 7.4 Manual](https://phpunit.readthedocs.io/en/7.4/textui.html#command-line-options):
|
||||
Quote from [3. The Command-Line Test Runner — PHPUnit 8.5 Manual](https://phpunit.readthedocs.io/en/8.5/textui.html#command-line-options):
|
||||
|
||||
> If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.
|
||||
|
||||
@ -112,7 +110,13 @@ Switch on option in `./index.php`:
|
||||
+++ $app->addErrorMiddleware(true, true, true);
|
||||
```
|
||||
|
||||
## [Mock Server Documentation]({{docsBasePath}}/MockServer.md)
|
||||
## Mock Server
|
||||
For a quick start uncomment [mocker middleware config](index.php#L62-L89).
|
||||
|
||||
Used packages:
|
||||
* [Openapi Data Mocker](https://github.com/ybelenko/openapi-data-mocker) - first implementation of OAS3 fake data generator.
|
||||
* [Openapi Data Mocker Server Middleware](https://github.com/ybelenko/openapi-data-mocker-server-middleware) - PSR-15 HTTP server middleware.
|
||||
* [Openapi Data Mocker Interfaces](https://github.com/ybelenko/openapi-data-mocker-interfaces) - package with mocking interfaces.
|
||||
|
||||
{{#generateApiDocs}}
|
||||
## API Endpoints
|
||||
|
@ -18,8 +18,20 @@ use Dyorg\TokenAuthentication;
|
||||
use Dyorg\TokenAuthentication\TokenSearch;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use {{invokerPackage}}\Middleware\JsonBodyParserMiddleware;
|
||||
use {{mockPackage}}\OpenApiDataMocker;
|
||||
use {{mockPackage}}\OpenApiDataMockerMiddleware;
|
||||
use OpenAPIServer\Mock\OpenApiDataMocker;
|
||||
use OpenAPIServer\Mock\OpenApiDataMockerRouteMiddleware;
|
||||
{{#isSlimPsr7}}
|
||||
use Slim\Psr7\Factory\ResponseFactory;
|
||||
{{/isSlimPsr7}}
|
||||
{{#isNyholmPsr7}}
|
||||
use Nyholm\Psr7\Factory\Psr17Factory
|
||||
{{/isNyholmPsr7}}
|
||||
{{#isGuzzlePsr7}}
|
||||
use GuzzleHttp\Psr7\HttpFactory;
|
||||
{{/isGuzzlePsr7}}
|
||||
{{#isZendDiactoros}}
|
||||
use Zend\Diactoros\ResponseFactory;
|
||||
{{/isZendDiactoros}}
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
@ -51,8 +63,6 @@ class SlimRouter
|
||||
'responses' => [
|
||||
{{#responses}}
|
||||
'{{#isDefault}}default{{/isDefault}}{{^isDefault}}{{code}}{{/isDefault}}' => [
|
||||
'code' => {{code}},
|
||||
'message' => '{{message}}',
|
||||
'jsonSchema' => '{{{jsonSchema}}}',
|
||||
],
|
||||
{{/responses}}
|
||||
@ -155,7 +165,19 @@ class SlimRouter
|
||||
// mocker options
|
||||
$mockerOptions = $this->getSetting($settings, 'mockerOptions', null);
|
||||
$dataMocker = $mockerOptions['dataMocker'] ?? new OpenApiDataMocker();
|
||||
$getMockResponseCallback = $mockerOptions['getMockResponseCallback'] ?? null;
|
||||
{{#isSlimPsr7}}
|
||||
$responseFactory = new ResponseFactory();
|
||||
{{/isSlimPsr7}}
|
||||
{{#isNyholmPsr7}}
|
||||
$responseFactory = new Psr17Factory();
|
||||
{{/isNyholmPsr7}}
|
||||
{{#isGuzzlePsr7}}
|
||||
$responseFactory = new HttpFactory();
|
||||
{{/isGuzzlePsr7}}
|
||||
{{#isZendDiactoros}}
|
||||
$responseFactory = new ResponseFactory();
|
||||
{{/isZendDiactoros}}
|
||||
$getMockStatusCodeCallback = $mockerOptions['getMockStatusCodeCallback'] ?? null;
|
||||
$mockAfterCallback = $mockerOptions['afterCallback'] ?? null;
|
||||
|
||||
foreach ($this->operations as $operation) {
|
||||
@ -223,8 +245,11 @@ class SlimRouter
|
||||
}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
if (is_callable($getMockResponseCallback)) {
|
||||
$middlewares[] = new OpenApiDataMockerMiddleware($dataMocker, $operation['responses'], $getMockResponseCallback, $mockAfterCallback);
|
||||
if (is_callable($getMockStatusCodeCallback)) {
|
||||
$mockSchemaResponses = array_map(function ($item) {
|
||||
return json_decode($item['jsonSchema'], true);
|
||||
}, $operation['responses']);
|
||||
$middlewares[] = new OpenApiDataMockerRouteMiddleware($dataMocker, $mockSchemaResponses, $responseFactory, $getMockStatusCodeCallback, $mockAfterCallback);
|
||||
}
|
||||
|
||||
$this->addRoute(
|
||||
|
319
modules/openapi-generator/src/main/resources/php-slim4-server/base_model.mustache
vendored
Normal file
319
modules/openapi-generator/src/main/resources/php-slim4-server/base_model.mustache
vendored
Normal file
@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use OpenAPIServer\Mock\OpenApiModelInterface;
|
||||
use OpenAPIServer\Mock\OpenApiDataMockerInterface as IMocker;
|
||||
use InvalidArgumentException;
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* BaseModel.
|
||||
*/
|
||||
class BaseModel implements OpenApiModelInterface
|
||||
{
|
||||
// phpcs:disable Generic.Commenting.DocComment
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA =
|
||||
<<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties": {}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string[] Valid OAS data types */
|
||||
protected const VALID_OAS_DATA_TYPES = [
|
||||
IMocker::DATA_TYPE_INTEGER,
|
||||
IMocker::DATA_TYPE_NUMBER,
|
||||
IMocker::DATA_TYPE_STRING,
|
||||
IMocker::DATA_TYPE_BOOLEAN,
|
||||
IMocker::DATA_TYPE_ARRAY,
|
||||
IMocker::DATA_TYPE_OBJECT,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\{{modelPackage}}';
|
||||
|
||||
/**
|
||||
* @var mixed Data container.
|
||||
* PHP has restrictions on variable names, while OAS is much more permissive.
|
||||
* This container helps to store unusual properties like '123_prop' without renaming.
|
||||
*/
|
||||
protected $dataContainer;
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Model constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$schema = static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
$this->validateModelType($modelType, true);
|
||||
|
||||
// set initial data
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
$this->dataContainer = [];
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
default:
|
||||
// scalar type
|
||||
$this->dataContainer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets OAS 3.0 schema mapped to current class.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema(): array
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new instance from provided data.
|
||||
*
|
||||
* @param mixed $data Data with values for new instance.
|
||||
*
|
||||
* @return OpenApiModelInterface
|
||||
*/
|
||||
public static function createFromData($data): OpenApiModelInterface
|
||||
{
|
||||
$instance = new static();
|
||||
$instance->setData($data);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets instance data.
|
||||
*
|
||||
* @param mixed $data Data with values for new instance.
|
||||
*
|
||||
* @throws \InvalidArgumentException When value for array type is invalid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setData($data): void
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
// data for array OAS type should be straight indexed array
|
||||
if (is_array($data)) {
|
||||
$arr = [];
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if (isset($data[$i])) {
|
||||
$arr[$i] = $data[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arr) === count($data)) {
|
||||
$this->dataContainer = $arr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Invalid data for %s model because it accepts straight indexed arrays only', static::class)
|
||||
);
|
||||
break;
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
foreach ($data as $key => $value) {
|
||||
// this action handles __set method
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
default:
|
||||
$this->dataContainer = $data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance data.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
$data = null;
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
// need to convert data container to object
|
||||
$data = new StdClass();
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? $schema['properties'] : null;
|
||||
if (is_array($definedProps) || is_object($definedProps)) {
|
||||
foreach ($definedProps as $propName => $propSchema) {
|
||||
if (array_key_exists($propName, $this->dataContainer)) {
|
||||
$data->{$propName} = $this->dataContainer[$propName];
|
||||
} elseif (array_key_exists('required', $schema) && in_array($propName, $schema['required'])) {
|
||||
// property is required but not set
|
||||
$data->{$propName} = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
default:
|
||||
$data = $this->dataContainer;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to inaccessible (protected or private) or non-existing properties.
|
||||
* Ref @link https://www.php.net/manual/en/language.oop5.overloading.php#object.set
|
||||
*
|
||||
* @param string $param Property name.
|
||||
* @param mixed $value Property value.
|
||||
*
|
||||
* @throws \InvalidArgumentException When property doesn't exist in related OAS schema.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set(string $param, $value): void
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? (array) $schema['properties'] : null;
|
||||
if (is_array($definedProps) && !in_array($param, array_keys($definedProps))) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot set %s property of %s model because it doesn\'t exist in related OAS schema', $param, static::class)
|
||||
);
|
||||
}
|
||||
$this->dataContainer[$param] = $value;
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
default:
|
||||
// scalar type and array cannot use property assignation
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot set %s property of %s model because it\'s %s type. Use setData method instead', $param, static::class, $modelType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from inaccessible (protected or private) or non-existing properties.
|
||||
* Ref @link https://www.php.net/manual/en/language.oop5.overloading.php#object.get
|
||||
*
|
||||
* @param string $param Property name.
|
||||
*
|
||||
* @throws \InvalidArgumentException When property doesn't exist in related OAS schema.
|
||||
*
|
||||
* @return mixed Property value
|
||||
*/
|
||||
public function __get(string $param)
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? (array) $schema['properties'] : null;
|
||||
if (!in_array($modelType, [null, IMocker::DATA_TYPE_OBJECT])) {
|
||||
// scalar type
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot get %s property of %s model because getter is for object OAS type only', $param, static::class)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
is_array($definedProps)
|
||||
&& in_array($param, array_keys($definedProps))
|
||||
) {
|
||||
return $this->dataContainer[$param];
|
||||
} elseif ($definedProps === null) {
|
||||
// props are undefined
|
||||
return (isset($this->dataContainer[$param])) ? $this->dataContainer[$param] : null;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot get %s property of %s model because it doesn\'t exist in related OAS schema', $param, static::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the object to a value that can be serialized natively by json_encode().
|
||||
* Ref @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
*
|
||||
* @return mixed Returns data which can be serialized by json_encode(), which is a value of any type other than a resource.
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if type is valid OAS data type.
|
||||
*
|
||||
* @param string|null $type Model type.
|
||||
* @param bool $throwException Throws InvalidArgumentException when set to true and processed type is invalid.
|
||||
*
|
||||
* @throws \InvalidArgumentException When $throwException set to TRUE.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateModelType(?string $type = null, bool $throwException = true): bool
|
||||
{
|
||||
$isValid = in_array($type, static::VALID_OAS_DATA_TYPES);
|
||||
if ($type !== null && $isValid === false && $throwException) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Invalid OAS schema of %s model, "type" must be one of %s',
|
||||
static::class,
|
||||
implode(', ', static::VALID_OAS_DATA_TYPES)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns models namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelsNamespace(): string
|
||||
{
|
||||
return static::MODELS_NAMESPACE . stripslashes('\\');
|
||||
}
|
||||
}
|
586
modules/openapi-generator/src/main/resources/php-slim4-server/base_model_test.mustache
vendored
Normal file
586
modules/openapi-generator/src/main/resources/php-slim4-server/base_model_test.mustache
vendored
Normal file
@ -0,0 +1,586 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use {{invokerPackage}}\BaseModel;
|
||||
use OpenAPIServer\Mock\OpenApiModelInterface;
|
||||
use InvalidArgumentException;
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* BaseModelTest
|
||||
*
|
||||
* phpcs:disable Squiz.Commenting,Generic.Commenting,PEAR.Commenting
|
||||
* @coversDefaultClass \{{invokerPackage}}\BaseModel
|
||||
*/
|
||||
class BaseModelTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::validateModelType
|
||||
* @dataProvider provideClassesAndDefaultData
|
||||
*/
|
||||
public function testConstructorAndDefaultData($className, $expectedJson)
|
||||
{
|
||||
$item = new $className();
|
||||
$this->assertEquals($expectedJson, json_encode($item->getData()));
|
||||
}
|
||||
|
||||
public function provideClassesAndDefaultData()
|
||||
{
|
||||
return [
|
||||
'boolean model' => [BasicBooleanTestClass::class, json_encode(null)],
|
||||
'integer model' => [BasicIntegerTestClass::class, json_encode(null)],
|
||||
'number model' => [BasicNumberTestClass::class, json_encode(null)],
|
||||
'string model' => [BasicStringTestClass::class, json_encode(null)],
|
||||
'array model' => [BasicArrayTestClass::class, json_encode([])],
|
||||
'object model' => [BasicObjectTestClass::class, json_encode(new StdClass())],
|
||||
'missing type model' => [MissingTypeTestClass::class, json_encode(null)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::validateModelType
|
||||
* @dataProvider provideInvalidClasses
|
||||
*/
|
||||
public function testConstructorWithInvalidTypes($className)
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$item = new $className();
|
||||
}
|
||||
|
||||
public function provideInvalidClasses()
|
||||
{
|
||||
return [
|
||||
'unknown type model' => [UnknownTypeTestClass::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getOpenApiSchema
|
||||
*/
|
||||
public function testGetOpenApiSchema()
|
||||
{
|
||||
foreach (
|
||||
[
|
||||
BaseModel::getOpenApiSchema(),
|
||||
CatRefTestClass::getOpenApiSchema(),
|
||||
DogRefTestClass::getOpenApiSchema(),
|
||||
BasicArrayTestClass::getOpenApiSchema(),
|
||||
BasicBooleanTestClass::getOpenApiSchema(),
|
||||
BasicIntegerTestClass::getOpenApiSchema(),
|
||||
BasicNumberTestClass::getOpenApiSchema(),
|
||||
BasicObjectTestClass::getOpenApiSchema(),
|
||||
BasicStringTestClass::getOpenApiSchema(),
|
||||
] as $schema
|
||||
) {
|
||||
$this->assertTrue(is_array($schema) || is_object($schema));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::createFromData
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
* @dataProvider provideCreateFromDataArguments
|
||||
*/
|
||||
public function testCreateFromData($modelClass, $data)
|
||||
{
|
||||
$item = $modelClass::createFromData($data);
|
||||
$this->assertInstanceOf($modelClass, $item);
|
||||
$this->assertInstanceOf(OpenApiModelInterface::class, $item);
|
||||
foreach ($data as $propName => $propValue) {
|
||||
$this->assertSame($propValue, $item->{$propName});
|
||||
}
|
||||
}
|
||||
|
||||
public function provideCreateFromDataArguments()
|
||||
{
|
||||
return [
|
||||
'CatRefTestClass' => [
|
||||
CatRefTestClass::class,
|
||||
[
|
||||
'className' => 'cheshire',
|
||||
'color' => 'gray',
|
||||
'declawed' => true,
|
||||
],
|
||||
],
|
||||
'DogRefTestClass' => [
|
||||
DogRefTestClass::class,
|
||||
[
|
||||
'className' => 'bulldog',
|
||||
'color' => 'black',
|
||||
'declawed' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setData
|
||||
* @covers ::getData
|
||||
* @dataProvider provideScalarModels
|
||||
*/
|
||||
public function testSetDataScalar($className, array $setDataValues, array $expectedDataValues)
|
||||
{
|
||||
$item = new $className();
|
||||
for ($i = 0; $i < count($setDataValues); $i++) {
|
||||
if ($i > 0) {
|
||||
// value should be previous
|
||||
$this->assertSame($expectedDataValues[$i - 1], $item->getData());
|
||||
} else {
|
||||
// initial value should be null
|
||||
$this->assertNull($item->getData());
|
||||
}
|
||||
$item->setData($setDataValues[$i]);
|
||||
// values should be overwritten
|
||||
$this->assertSame($expectedDataValues[$i], $item->getData());
|
||||
}
|
||||
}
|
||||
|
||||
public function provideScalarModels()
|
||||
{
|
||||
return [
|
||||
'boolean model' => [
|
||||
BasicBooleanTestClass::class,
|
||||
[false, true, false],
|
||||
[false, true, false],
|
||||
],
|
||||
'integer model' => [
|
||||
BasicIntegerTestClass::class,
|
||||
[-50, 322, 100500, -1000, 0],
|
||||
[-50, 322, 100500, -1000, 0],
|
||||
],
|
||||
'number model' => [
|
||||
BasicNumberTestClass::class,
|
||||
[-50.324, 322.756, 100500.09, -1000.43, 0],
|
||||
[-50.324, 322.756, 100500.09, -1000.43, 0],
|
||||
],
|
||||
'string model' => [
|
||||
BasicStringTestClass::class,
|
||||
['foobar', 'hello world', '100', '-56', 'true', 'null', 'false'],
|
||||
['foobar', 'hello world', '100', '-56', 'true', 'null', 'false'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setData
|
||||
* @covers ::getData
|
||||
*/
|
||||
public function testSetDataOfArray()
|
||||
{
|
||||
$basic = new BasicArrayTestClass();
|
||||
$data = ['foo', 'bar', 'baz'];
|
||||
$basic->setData($data);
|
||||
$this->assertEquals($data, $basic->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setData
|
||||
* @dataProvider provideInvalidDataForArrayModel
|
||||
*/
|
||||
public function testSetDataOfArrayWithInvalidData($className, $data)
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$item = new $className();
|
||||
$item->setData($data);
|
||||
}
|
||||
|
||||
public function provideInvalidDataForArrayModel()
|
||||
{
|
||||
$obj = new StdClass();
|
||||
$obj->foo = 'bar';
|
||||
$obj->baz = 'baf';
|
||||
$arr = [];
|
||||
$arr[5] = 'foo';
|
||||
$arr[6] = 'bar';
|
||||
return [
|
||||
'array with spaced indexes data' => [
|
||||
BasicArrayTestClass::class,
|
||||
$arr,
|
||||
],
|
||||
'assoc array data' => [
|
||||
BasicArrayTestClass::class,
|
||||
['foo' => 'bar', 'baz' => 'baf'],
|
||||
],
|
||||
'object data' => [
|
||||
BasicArrayTestClass::class,
|
||||
$obj,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setData
|
||||
* @covers ::getData
|
||||
*/
|
||||
public function testSetDataOfObject()
|
||||
{
|
||||
$basic = new BasicObjectTestClass();
|
||||
$data = ['foo' => 'bar'];
|
||||
$basic->setData($data);
|
||||
$this->assertSame('bar', $basic->foo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getData
|
||||
*/
|
||||
public function testGetDataOfObject()
|
||||
{
|
||||
$catItem = new CatRefTestClass();
|
||||
$catItem->setData([
|
||||
'color' => 'grey',
|
||||
'declawed' => false,
|
||||
]);
|
||||
$data = $catItem->getData();
|
||||
$this->assertInstanceOf(StdClass::class, $data);
|
||||
$this->assertSame('grey', $data->color);
|
||||
$this->assertSame(false, $data->declawed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
*/
|
||||
public function testSetter()
|
||||
{
|
||||
$item = new CatRefTestClass();
|
||||
$item->className = 'cheshire';
|
||||
$item->color = 'black';
|
||||
$item->declawed = false;
|
||||
$this->assertSame('cheshire', $item->className);
|
||||
$this->assertSame('black', $item->color);
|
||||
$this->assertSame(false, $item->declawed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__set
|
||||
* @dataProvider provideScalarsAndArray
|
||||
*/
|
||||
public function testSetterOfScalarAndArray($className)
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$item = new $className();
|
||||
$item->foo = 'bar';
|
||||
}
|
||||
|
||||
public function provideScalarsAndArray()
|
||||
{
|
||||
return [
|
||||
'boolean model' => [BasicBooleanTestClass::class],
|
||||
'integer model' => [BasicIntegerTestClass::class],
|
||||
'number model' => [BasicNumberTestClass::class],
|
||||
'string model' => [BasicStringTestClass::class],
|
||||
'array model' => [BasicArrayTestClass::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__set
|
||||
*/
|
||||
public function testSetterWithUnknownProp()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(
|
||||
sprintf(
|
||||
'Cannot set unknownProp property of %s model because it doesn\'t exist in related OAS schema',
|
||||
CatRefTestClass::class
|
||||
)
|
||||
);
|
||||
$item = new CatRefTestClass();
|
||||
$item->unknownProp = 'foobar';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__get
|
||||
*/
|
||||
public function testGetterWithUnknownProp()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage(
|
||||
sprintf(
|
||||
'Cannot get unknownProp property of %s model because it doesn\'t exist in related OAS schema',
|
||||
CatRefTestClass::class
|
||||
)
|
||||
);
|
||||
$item = new CatRefTestClass();
|
||||
$unknownProp = $item->unknownProp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__get
|
||||
* @dataProvider provideScalarsAndArray
|
||||
*/
|
||||
public function testGetterOfScalarAndArray($className)
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$item = new $className();
|
||||
$bar = $item->foo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
*/
|
||||
public function testSetterAndGetterOfBasicObject()
|
||||
{
|
||||
$item = new BasicObjectTestClass();
|
||||
$item->unknown = 'foo';
|
||||
$this->assertEquals('foo', $item->unknown);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::jsonSerialize
|
||||
* @dataProvider provideJsonSerializeArguments
|
||||
*/
|
||||
public function testJsonSerialize($className, $data, $expectedJson)
|
||||
{
|
||||
$item = $className::createFromData($data);
|
||||
$this->assertEquals($expectedJson, json_encode($item));
|
||||
}
|
||||
|
||||
public function provideJsonSerializeArguments()
|
||||
{
|
||||
return [
|
||||
'model with all props' => [
|
||||
CatRefTestClass::class,
|
||||
[
|
||||
'className' => 'cheshire',
|
||||
'color' => 'black',
|
||||
'declawed' => false,
|
||||
],
|
||||
json_encode([
|
||||
'className' => 'cheshire',
|
||||
'color' => 'black',
|
||||
'declawed' => false,
|
||||
]),
|
||||
],
|
||||
'model with required props' => [
|
||||
CatRefTestClass::class,
|
||||
[
|
||||
'className' => 'cheshire',
|
||||
],
|
||||
json_encode([
|
||||
'className' => 'cheshire',
|
||||
]),
|
||||
],
|
||||
'model with missed required prop' => [
|
||||
CatRefTestClass::class,
|
||||
[
|
||||
'color' => 'black',
|
||||
],
|
||||
json_encode([
|
||||
'className' => null,
|
||||
'color' => 'black',
|
||||
]),
|
||||
],
|
||||
'model with schema serialized as assoc array' => [
|
||||
DogRefTestClass::class,
|
||||
[
|
||||
'className' => 'bulldog',
|
||||
'color' => 'gray',
|
||||
'declawed' => false,
|
||||
],
|
||||
json_encode([
|
||||
'className' => 'bulldog',
|
||||
'color' => 'gray',
|
||||
'declawed' => false,
|
||||
]),
|
||||
],
|
||||
'model of basic array' => [
|
||||
BasicArrayTestClass::class,
|
||||
['hello', 'world'],
|
||||
json_encode(['hello', 'world']),
|
||||
],
|
||||
'model of basic boolean' => [
|
||||
BasicBooleanTestClass::class,
|
||||
false,
|
||||
json_encode(false),
|
||||
],
|
||||
'model of basic integer' => [
|
||||
BasicIntegerTestClass::class,
|
||||
-500,
|
||||
json_encode(-500),
|
||||
],
|
||||
'model of basic number' => [
|
||||
BasicNumberTestClass::class,
|
||||
-3.1434,
|
||||
json_encode(-3.1434),
|
||||
],
|
||||
'model of basic object' => [
|
||||
BasicObjectTestClass::class,
|
||||
new \StdClass(),
|
||||
json_encode(new \StdClass()),
|
||||
],
|
||||
'model of basic string' => [
|
||||
BasicStringTestClass::class,
|
||||
'foobar',
|
||||
json_encode('foobar'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getModelsNamespace
|
||||
* @dataProvider provideTestClasses
|
||||
*/
|
||||
public function testGetModelsNamespace($classname)
|
||||
{
|
||||
$this->assertTrue(method_exists($classname, 'getModelsNamespace'));
|
||||
$getModelsNamespace = $classname . '::getModelsNamespace';
|
||||
$namespace = $getModelsNamespace();
|
||||
$this->assertIsString($namespace);
|
||||
}
|
||||
|
||||
public function provideTestClasses()
|
||||
{
|
||||
return [
|
||||
[BasicArrayTestClass::class],
|
||||
[BasicBooleanTestClass::class],
|
||||
[BasicIntegerTestClass::class],
|
||||
[BasicNumberTestClass::class],
|
||||
[BasicObjectTestClass::class],
|
||||
[BasicStringTestClass::class],
|
||||
[CatRefTestClass::class],
|
||||
[DogRefTestClass::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
|
||||
class BasicArrayTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "array"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class BasicBooleanTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "boolean"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class BasicIntegerTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "integer"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class BasicNumberTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "number"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class BasicObjectTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class BasicStringTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "string"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class CatRefTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "className" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"className" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"color" : {
|
||||
"type" : "string",
|
||||
"default" : "red"
|
||||
},
|
||||
"declawed" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
},
|
||||
"discriminator" : {
|
||||
"propertyName" : "className"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class ClassWithoutGetSchemaMethod
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class DogRefTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "className" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"className" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"color" : {
|
||||
"type" : "string",
|
||||
"default" : "black"
|
||||
},
|
||||
"declawed" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
},
|
||||
"discriminator" : {
|
||||
"propertyName" : "className"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class MissingTypeTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{}
|
||||
SCHEMA;
|
||||
}
|
||||
|
||||
class UnknownTypeTestClass extends BaseModel
|
||||
{
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "foobar"
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
"php": "^7.2",
|
||||
"slim/slim": "^4.5.0",
|
||||
"dyorg/slim-token-authentication": "dev-slim4",
|
||||
"ybelenko/openapi-data-mocker": "^1.0",
|
||||
"ybelenko/openapi-data-mocker-server-middleware": "^1.0",
|
||||
{{#isSlimPsr7}}
|
||||
"slim/psr7": "^1.1.0"
|
||||
{{/isSlimPsr7}}
|
||||
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/vendor/autoload.php';
|
||||
use {{invokerPackage}}\SlimRouter;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use {{mockPackage}}\OpenApiDataMocker;
|
||||
use OpenAPIServer\Mock\OpenApiDataMocker;
|
||||
{{/apiInfo}}
|
||||
|
||||
$config = [];
|
||||
@ -53,21 +53,28 @@ $config['tokenAuthenticationOptions'] = [
|
||||
/**
|
||||
* Mocker Middleware options.
|
||||
*/
|
||||
$mocker = new OpenApiDataMocker();
|
||||
$mocker->setModelsNamespace('{{modelPackage}}\\');
|
||||
$config['mockerOptions'] = [
|
||||
// 'dataMocker' => new OpenApiDataMocker(),
|
||||
// 'dataMocker' => $mocker,
|
||||
|
||||
// 'getMockResponseCallback' => function (ServerRequestInterface $request, array $responses) {
|
||||
// 'getMockStatusCodeCallback' => function (ServerRequestInterface $request, $responses) {
|
||||
// // check if client clearly asks for mocked response
|
||||
// $pingHeader = 'X-{{invokerPackage}}-Mock';
|
||||
// $pingHeaderCode = 'X-{{invokerPackage}}-Mock-Code';
|
||||
// if (
|
||||
// $request->hasHeader('X-{{invokerPackage}}-Mock')
|
||||
// && $request->getHeader('X-{{invokerPackage}}-Mock')[0] === 'ping'
|
||||
// $request->hasHeader($pingHeader)
|
||||
// && $request->getHeader($pingHeader)[0] === 'ping'
|
||||
// ) {
|
||||
// if (array_key_exists('default', $responses)) {
|
||||
// return $responses['default'];
|
||||
// $responses = (array) $responses;
|
||||
// $requestedResponseCode = ($request->hasHeader($pingHeaderCode)) ? $request->getHeader($pingHeaderCode)[0] : 'default';
|
||||
// if (array_key_exists($requestedResponseCode, $responses)) {
|
||||
// return $requestedResponseCode;
|
||||
// }
|
||||
|
||||
// // return first response
|
||||
// return $responses[array_key_first($responses)];
|
||||
// // return first response key
|
||||
// reset($responses);
|
||||
// return key($responses);
|
||||
// }
|
||||
|
||||
// return false;
|
||||
|
@ -1,135 +0,0 @@
|
||||
# {{packageName}} - PHP Slim 4 Server library for {{appName}}
|
||||
|
||||
## Mock Server Documentation
|
||||
|
||||
### Mocker Options
|
||||
To enable mock server uncomment these lines in `index.php` config file:
|
||||
|
||||
```php
|
||||
/**
|
||||
* Mocker Middleware options.
|
||||
*/
|
||||
$config['mockerOptions'] = [
|
||||
'dataMocker' => new OpenApiDataMocker(),
|
||||
|
||||
'getMockResponseCallback' => function (ServerRequestInterface $request, array $responses) {
|
||||
// check if client clearly asks for mocked response
|
||||
if (
|
||||
$request->hasHeader('X-{{invokerPackage}}-Mock')
|
||||
&& $request->getHeader('X-{{invokerPackage}}-Mock')[0] === 'ping'
|
||||
) {
|
||||
if (array_key_exists('default', $responses)) {
|
||||
return $responses['default'];
|
||||
}
|
||||
|
||||
// return first response
|
||||
return $responses[array_key_first($responses)];
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
'afterCallback' => function ($request, $response) {
|
||||
// mark mocked response to distinguish real and fake responses
|
||||
return $response->withHeader('X-{{invokerPackage}}-Mock', 'pong');
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
* `dataMocker` is mocker class instance. To create custom data mocker extend `{{mockPackage}}\{{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}}`.
|
||||
* `getMockResponseCallback` is callback before mock data generation. Above example shows how to enable mock feature for only requests with `{{X-{{invokerPackage}}}}-mock: ping` HTTP header. Adjust requests filtering to fit your project requirements. This function must return single response schema from `$responses` array parameter. **Mock feature is disabled when callback returns anything beside array.**
|
||||
* `afterCallback` is callback executed after mock data generation. Most obvious use case is append specific HTTP headers to distinguish real and fake responses. **This function must always return response instance.**
|
||||
|
||||
### Supported features
|
||||
|
||||
All data types supported except specific string formats: `email`, `uuid`, `password` which are poorly implemented.
|
||||
|
||||
#### Data Types Support
|
||||
|
||||
| Data Type | Data Format | Supported |
|
||||
|:---------:|:-----------:|:------------------:|
|
||||
| `integer` | `int32` | :white_check_mark: |
|
||||
| `integer` | `int64` | :white_check_mark: |
|
||||
| `number` | `float` | :white_check_mark: |
|
||||
| `number` | `double` | |
|
||||
| `string` | `byte` | :white_check_mark: |
|
||||
| `string` | `binary` | :white_check_mark: |
|
||||
| `boolean` | | :white_check_mark: |
|
||||
| `string` | `date` | :white_check_mark: |
|
||||
| `string` | `date-time` | :white_check_mark: |
|
||||
| `string` | `password` | :white_check_mark: |
|
||||
| `string` | `email` | :white_check_mark: |
|
||||
| `string` | `uuid` | :white_check_mark: |
|
||||
|
||||
#### Data Options Support
|
||||
|
||||
| Data Type | Option | Supported |
|
||||
|:-----------:|:----------------------:|:------------------:|
|
||||
| `string` | `minLength` | :white_check_mark: |
|
||||
| `string` | `maxLength` | :white_check_mark: |
|
||||
| `string` | `enum` | :white_check_mark: |
|
||||
| `string` | `pattern` | |
|
||||
| `integer` | `minimum` | :white_check_mark: |
|
||||
| `integer` | `maximum` | :white_check_mark: |
|
||||
| `integer` | `exclusiveMinimum` | :white_check_mark: |
|
||||
| `integer` | `exclusiveMaximum` | :white_check_mark: |
|
||||
| `number` | `minimum` | :white_check_mark: |
|
||||
| `number` | `maximum` | :white_check_mark: |
|
||||
| `number` | `exclusiveMinimum` | :white_check_mark: |
|
||||
| `number` | `exclusiveMaximum` | :white_check_mark: |
|
||||
| `array` | `items` | :white_check_mark: |
|
||||
| `array` | `additionalItems` | |
|
||||
| `array` | `minItems` | :white_check_mark: |
|
||||
| `array` | `maxItems` | :white_check_mark: |
|
||||
| `array` | `uniqueItems` | |
|
||||
| `object` | `properties` | :white_check_mark: |
|
||||
| `object` | `maxProperties` | |
|
||||
| `object` | `minProperties` | |
|
||||
| `object` | `patternProperties` | |
|
||||
| `object` | `additionalProperties` | |
|
||||
| `object` | `required` | |
|
||||
| `*` | `$ref` | :white_check_mark: |
|
||||
| `*` | `allOf` | |
|
||||
| `*` | `anyOf` | |
|
||||
| `*` | `oneOf` | |
|
||||
| `*` | `not` | |
|
||||
|
||||
### Known Limitations
|
||||
|
||||
Avoid circular refs in your schema. Schema below can cause infinite loop and `Out of Memory` PHP error:
|
||||
```yml
|
||||
# ModelA has reference to ModelB while ModelB has reference to ModelA.
|
||||
# Mock server will produce huge nested JSON example and ended with `Out of Memory` error.
|
||||
definitions:
|
||||
ModelA:
|
||||
type: object
|
||||
properties:
|
||||
model_b:
|
||||
$ref: '#/definitions/ModelB'
|
||||
ModelB:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/ModelA'
|
||||
```
|
||||
|
||||
Don't ref scalar types, because generator will not produce models which mock server can find. So schema below will cause error:
|
||||
```yml
|
||||
# generated build contains only `OuterComposite` model class which referenced to not existed `OuterNumber`, `OuterString`, `OuterBoolean` classes
|
||||
# mock server cannot mock `OuterComposite` model and throws exception
|
||||
definitions:
|
||||
OuterComposite:
|
||||
type: object
|
||||
properties:
|
||||
my_number:
|
||||
$ref: '#/definitions/OuterNumber'
|
||||
my_string:
|
||||
$ref: '#/definitions/OuterString'
|
||||
my_boolean:
|
||||
$ref: '#/definitions/OuterBoolean'
|
||||
OuterNumber:
|
||||
type: number
|
||||
OuterString:
|
||||
type: string
|
||||
OuterBoolean:
|
||||
type: boolean
|
||||
```
|
@ -8,7 +8,7 @@
|
||||
*/{{#models}}{{#model}}
|
||||
namespace {{modelPackage}};
|
||||
|
||||
use {{interfacesPackage}}\{{interfaceNamePrefix}}Model{{interfaceNameSuffix}};
|
||||
use {{invokerPackage}}\BaseModel;
|
||||
|
||||
/**
|
||||
* {{classname}}
|
||||
@ -17,27 +17,20 @@ use {{interfacesPackage}}\{{interfaceNamePrefix}}Model{{interfaceNameSuffix}};
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class {{classname}} implements {{interfaceNamePrefix}}Model{{interfaceNameSuffix}}
|
||||
class {{classname}} extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{{{modelJson}}}
|
||||
SCHEMA;
|
||||
{{#vars}}
|
||||
|
||||
/** @var {{dataType}} ${{name}} {{#description}}{{description}}{{/description}}*/
|
||||
private ${{name}};
|
||||
{{/vars}}
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\{{modelPackage}}';
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{{{modelJson}}}
|
||||
SCHEMA;
|
||||
}
|
||||
{{/model}}{{/models}}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{interfacesPackage}};
|
||||
|
||||
/**
|
||||
* {{interfaceNamePrefix}}Model{{interfaceNameSuffix}} Class Doc Comment
|
||||
*
|
||||
* @package {{interfacesPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
interface {{interfaceNamePrefix}}Model{{interfaceNameSuffix}}
|
||||
{
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false);
|
||||
}
|
||||
{{/apiInfo}}
|
@ -59,6 +59,12 @@ class {{classname}}Test extends TestCase
|
||||
public function test{{classname}}()
|
||||
{
|
||||
$test{{classname}} = new {{classname}}();
|
||||
$namespacedClassname = {{classname}}::getModelsNamespace() . '\\{{classname}}';
|
||||
$this->assertSame('\\' . {{classname}}::class, $namespacedClassname);
|
||||
$this->assertTrue(
|
||||
class_exists($namespacedClassname),
|
||||
sprintf('Assertion failed that "%s" class exists', $namespacedClassname)
|
||||
);
|
||||
$this->markTestIncomplete(
|
||||
'Test of "{{classname}}" model has not been implemented yet.'
|
||||
);
|
||||
@ -82,9 +88,7 @@ class {{classname}}Test extends TestCase
|
||||
*/
|
||||
public function testGetOpenApiSchema()
|
||||
{
|
||||
$schemaObject = {{classname}}::getOpenApiSchema();
|
||||
$schemaArr = {{classname}}::getOpenApiSchema(true);
|
||||
$this->assertIsObject($schemaObject);
|
||||
$schemaArr = {{classname}}::getOpenApiSchema();
|
||||
$this->assertIsArray($schemaArr);
|
||||
}
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{utilsPackage}};
|
||||
|
||||
use {{utilsPackage}}\{{traitNamePrefix}}StringUtils{{traitNameSuffix}};
|
||||
|
||||
/**
|
||||
* {{traitNamePrefix}}ModelUtils{{traitNameSuffix}} Class Doc Comment
|
||||
* This class duplicates functionality of ModelUtils.java and AbstractPhpCodegen.java classes.
|
||||
*
|
||||
* @package {{utilsPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
trait {{traitNamePrefix}}ModelUtils{{traitNameSuffix}}
|
||||
{
|
||||
use {{traitNamePrefix}}StringUtils{{traitNameSuffix}};
|
||||
|
||||
/**
|
||||
* Parses model class name from provided ref.
|
||||
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#reference-object
|
||||
* This method doesn't check that class exists and autoloaded.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java class.
|
||||
*
|
||||
* @param string $ref Reference, eg. #/components/schemas/Pet
|
||||
*
|
||||
* @return string|null classname or null on fail
|
||||
*/
|
||||
public static function getSimpleRef($ref)
|
||||
{
|
||||
$model = null;
|
||||
if (stripos($ref, '#/components/') === 0) {
|
||||
// starts with #/components/
|
||||
$model = substr($ref, strrpos($ref, '/') + 1);
|
||||
} elseif (stripos($ref, '#/definitions/') === 0) {
|
||||
// starts with #/definitions/
|
||||
$model = substr($ref, strrpos($ref, '/') + 1);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the proper model name (capitalized).
|
||||
* In case the name belongs to the TypeSystem it won't be renamed.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java class.
|
||||
*
|
||||
* @param string $name the name of the model
|
||||
* @param string|null $modelNamePrefix modelNamePrefix generator option
|
||||
* @param string|null $modelNameSuffix modelNameSuffix generator option
|
||||
*
|
||||
* @return string capitalized model name
|
||||
*/
|
||||
public static function toModelName(
|
||||
$name,
|
||||
$modelNamePrefix = {{#modelNamePrefix}}'{{modelNamePrefix}}'{{/modelNamePrefix}}{{^modelNamePrefix}}null{{/modelNamePrefix}},
|
||||
$modelNameSuffix = {{#modelNameSuffix}}'{{modelNameSuffix}}'{{/modelNameSuffix}}{{^modelNameSuffix}}null{{/modelNameSuffix}}
|
||||
) {
|
||||
if (is_string($name) === false || empty($name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// remove [
|
||||
$name = str_replace(']', '', $name);
|
||||
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
$name = preg_replace('/[^\w\\\\]+/', '_', $name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove underscores from start and end
|
||||
$name = trim($name, '_');
|
||||
|
||||
// remove dollar sign
|
||||
$name = str_replace('$', '', $name);
|
||||
|
||||
// model name cannot use reserved keyword
|
||||
if (self::isReservedWord($name)) {
|
||||
$name = 'model_' . $name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (preg_match('/^\d.*/', $name) === 1) {
|
||||
$name = 'model_' . $name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
|
||||
if (preg_match('/^\\\\.*/', $name) !== 1) {
|
||||
if (is_string($modelNamePrefix) && !empty($modelNamePrefix)) {
|
||||
$name = $modelNamePrefix . '_' . $name;
|
||||
}
|
||||
|
||||
if (is_string($modelNameSuffix) && !empty($modelNameSuffix)) {
|
||||
$name = $name . '_' . $modelNameSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return self::camelize($name);
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{utilsPackage}};
|
||||
|
||||
use {{utilsPackage}}\{{traitNamePrefix}}ModelUtils{{traitNameSuffix}} as ModelUtils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* {{traitNamePrefix}}ModelUtils{{traitNameSuffix}}Test Class Doc Comment
|
||||
*
|
||||
* @package {{utilsPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
* @coversDefaultClass \{{utilsPackage}}\{{traitNamePrefix}}ModelUtils{{traitNameSuffix}}
|
||||
*/
|
||||
class {{traitNamePrefix}}ModelUtils{{traitNameSuffix}}Test extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers ::getSimpleRef
|
||||
* @dataProvider provideRefs
|
||||
*/
|
||||
public function testGetSimpleRef($ref, $expectedRef)
|
||||
{
|
||||
$this->assertSame($expectedRef, ModelUtils::getSimpleRef($ref));
|
||||
}
|
||||
|
||||
public function provideRefs()
|
||||
{
|
||||
return [
|
||||
'Reference Object OAS 3.0' => [
|
||||
'#/components/schemas/Pet', 'Pet',
|
||||
],
|
||||
'Reference Object Swagger 2.0' => [
|
||||
'#/definitions/Pet', 'Pet',
|
||||
],
|
||||
'Underscored classname' => [
|
||||
'#/components/schemas/_foobar_Objects', '_foobar_Objects',
|
||||
],
|
||||
'Relative Documents With Embedded Schema' => [
|
||||
'definitions.json#/Pet', null,
|
||||
],
|
||||
'null as argument' => [
|
||||
null, null,
|
||||
],
|
||||
'number as argument' => [
|
||||
156, null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::toModelName
|
||||
* @dataProvider provideModelNames
|
||||
*/
|
||||
public function testToModelName($name, $prefix, $suffix, $expectedModel)
|
||||
{
|
||||
$this->assertSame($expectedModel, ModelUtils::toModelName($name, $prefix, $suffix));
|
||||
}
|
||||
|
||||
public function provideModelNames()
|
||||
{
|
||||
return [
|
||||
// fixtures from modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/StringUtilsTest.java
|
||||
['abcd', null, null, 'Abcd'],
|
||||
['some-value', null, null, 'SomeValue'],
|
||||
['some_value', null, null, 'SomeValue'],
|
||||
['$type', null, null, 'Type'],
|
||||
['123', null, null, 'Model123'],
|
||||
['$123', null, null, 'Model123'],
|
||||
['return', null, null, 'ModelReturn'],
|
||||
['200Response', null, null, 'Model200Response'],
|
||||
['abcd', 'SuperModel', null, 'SuperModelAbcd'],
|
||||
['abcd', null, 'WithEnd', 'AbcdWithEnd'],
|
||||
['abcd', 'WithStart', 'AndEnd', 'WithStartAbcdAndEnd'],
|
||||
['_foobar_Objects', null, null, 'FoobarObjects'],
|
||||
[null, null, null, null],
|
||||
];
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,609 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{mockPackage}};
|
||||
|
||||
use {{mockPackage}}\{{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} as IMocker;
|
||||
use {{utilsPackage}}\{{traitNamePrefix}}ModelUtils{{traitNameSuffix}};
|
||||
use StdClass;
|
||||
use DateTime;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* OpenApiDataMocker Class Doc Comment
|
||||
*
|
||||
* @package {{mockPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
final class OpenApiDataMocker implements IMocker
|
||||
{
|
||||
use {{traitNamePrefix}}ModelUtils{{traitNameSuffix}};
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data.
|
||||
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types
|
||||
*
|
||||
* @param $dataType string OpenApi data type. Use constants from {{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} class
|
||||
* @param $dataFormat string (optional) OpenApi data format
|
||||
* @param $options array|null (optional) OpenApi data options
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mock($dataType, $dataFormat = null, $options = [])
|
||||
{
|
||||
switch ($dataType) {
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
$minimum = $options['minimum'] ?? null;
|
||||
$maximum = $options['maximum'] ?? null;
|
||||
$exclusiveMinimum = $options['exclusiveMinimum'] ?? false;
|
||||
$exclusiveMaximum = $options['exclusiveMaximum'] ?? false;
|
||||
if ($dataType === IMocker::DATA_TYPE_INTEGER) {
|
||||
return $this->mockInteger($dataFormat, $minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum);
|
||||
}
|
||||
return $this->mockNumber($dataFormat, $minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum);
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
$minLength = $options['minLength'] ?? 0;
|
||||
$maxLength = $options['maxLength'] ?? null;
|
||||
$enum = $options['enum'] ?? null;
|
||||
return $this->mockString($dataFormat, $minLength, $maxLength, $enum);
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
return $this->mockBoolean();
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
$items = $options['items'] ?? null;
|
||||
$minItems = $options['minItems'] ?? 0;
|
||||
$maxItems = $options['maxItems'] ?? null;
|
||||
$uniqueItems = $options['uniqueItems'] ?? false;
|
||||
return $this->mockArray($items, $minItems, $maxItems, $uniqueItems);
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
$properties = $options['properties'] ?? null;
|
||||
$minProperties = $options['minProperties'] ?? 0;
|
||||
$maxProperties = $options['maxProperties'] ?? null;
|
||||
$additionalProperties = $options['additionalProperties'] ?? null;
|
||||
$required = $options['required'] ?? null;
|
||||
return $this->mockObject($properties, $minProperties, $maxProperties, $additionalProperties, $required);
|
||||
default:
|
||||
throw new InvalidArgumentException('"dataType" must be one of ' . implode(', ', [
|
||||
IMocker::DATA_TYPE_INTEGER,
|
||||
IMocker::DATA_TYPE_NUMBER,
|
||||
IMocker::DATA_TYPE_STRING,
|
||||
IMocker::DATA_TYPE_BOOLEAN,
|
||||
IMocker::DATA_TYPE_ARRAY,
|
||||
IMocker::DATA_TYPE_OBJECT,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock integer type
|
||||
* Equivalent to mockData(DATA_TYPE_INTEGER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) int32 or int64
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function mockInteger(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
) {
|
||||
$dataFormat = is_string($dataFormat) ? strtolower($dataFormat) : $dataFormat;
|
||||
switch ($dataFormat) {
|
||||
case IMocker::DATA_FORMAT_INT32:
|
||||
// -2147483647..2147483647
|
||||
$minimum = is_numeric($minimum) ? max($minimum, -2147483647) : -2147483647;
|
||||
$maximum = is_numeric($maximum) ? min($maximum, 2147483647) : 2147483647;
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_INT64:
|
||||
// -9223372036854775807..9223372036854775807
|
||||
$minimum = is_numeric($minimum) ? max($minimum, -9223372036854775807) : -9223372036854775807;
|
||||
$maximum = is_numeric($maximum) ? min($maximum, 9223372036854775807) : 9223372036854775807;
|
||||
break;
|
||||
default:
|
||||
// do nothing, unsupported format
|
||||
}
|
||||
|
||||
return $this->getRandomNumber($minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock number type
|
||||
* Equivalent to mockData(DATA_TYPE_NUMBER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) float or double
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function mockNumber(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
) {
|
||||
return $this->getRandomNumber($minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock string type
|
||||
* Equivalent to mockData(DATA_TYPE_STRING);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) one of byte, binary, date, date-time, password
|
||||
* @param int|null $minLength (optional) Default is 0
|
||||
* @param int|null $maxLength (optional) Default is 100 chars
|
||||
* @param array $enum (optional) This array should have at least one element.
|
||||
* Elements in the array should be unique.
|
||||
* @param string|null $pattern (optional) This string should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
||||
* Recall: regular expressions are not implicitly anchored.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mockString(
|
||||
$dataFormat = null,
|
||||
$minLength = 0,
|
||||
$maxLength = null,
|
||||
$enum = null,
|
||||
$pattern = null
|
||||
) {
|
||||
$str = '';
|
||||
$getLoremIpsum = function ($length) {
|
||||
return str_pad(
|
||||
'',
|
||||
$length,
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
|
||||
\STR_PAD_RIGHT
|
||||
);
|
||||
};
|
||||
$truncateOrPad = function ($text, $min = null, $max = null, $glue = '') {
|
||||
if ($max !== null && mb_strlen($text) > $max) {
|
||||
// truncate
|
||||
$text = substr($text, 0, $max);
|
||||
} elseif ($min !== null && mb_strlen($text) < $min) {
|
||||
// pad
|
||||
$text = str_pad('', $min, $text . $glue, \STR_PAD_RIGHT);
|
||||
}
|
||||
return $text;
|
||||
};
|
||||
|
||||
if ($enum !== null) {
|
||||
if (
|
||||
is_array($enum) === false
|
||||
|| empty($enum)
|
||||
|| count($enum) > count(array_unique($enum))
|
||||
) {
|
||||
throw new InvalidArgumentException('"enum" must be an array. This array should have at least one element. Elements in the array should be unique.');
|
||||
}
|
||||
|
||||
// return random variant
|
||||
return $enum[mt_rand(0, count($enum) - 1)];
|
||||
}
|
||||
|
||||
if ($minLength !== 0 && $minLength !== null) {
|
||||
if (is_int($minLength) === false) {
|
||||
throw new InvalidArgumentException('"minLength" must be an integer');
|
||||
} elseif ($minLength < 0) {
|
||||
throw new InvalidArgumentException('"minLength" must be greater than, or equal to, 0');
|
||||
}
|
||||
} else {
|
||||
$minLength = 0;
|
||||
}
|
||||
|
||||
if ($maxLength !== null) {
|
||||
if (is_int($maxLength) === false) {
|
||||
throw new InvalidArgumentException('"maxLength" must be an integer');
|
||||
} elseif ($maxLength < 0) {
|
||||
throw new InvalidArgumentException('"maxLength" must be greater than, or equal to, 0');
|
||||
}
|
||||
} else {
|
||||
// since we don't need huge texts by default, lets cut them down to 100 chars
|
||||
$maxLength = 100;
|
||||
}
|
||||
|
||||
if ($maxLength < $minLength) {
|
||||
throw new InvalidArgumentException('"maxLength" value cannot be less than "minLength"');
|
||||
}
|
||||
|
||||
switch ($dataFormat) {
|
||||
case IMocker::DATA_FORMAT_BYTE:
|
||||
case IMocker::DATA_FORMAT_BINARY:
|
||||
// base64 encoded string
|
||||
$inputLength = 1;
|
||||
$str = base64_encode($getLoremIpsum($inputLength));
|
||||
while (mb_strlen($str) < $minLength) {
|
||||
$inputLength++;
|
||||
$str = base64_encode($getLoremIpsum($inputLength));
|
||||
}
|
||||
|
||||
// base64 encoding produces strings devided by 4, so resulted string can exceed maxLength parameter
|
||||
// I think truncated(invalid) base64 string is better than oversized, cause this data is fake anyway
|
||||
$str = $truncateOrPad($str, null, $maxLength, '. ');
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_DATE:
|
||||
case IMocker::DATA_FORMAT_DATE_TIME:
|
||||
// min unix timestamp is 0 and max is 2147483647 for 32bit systems which equals 2038-01-19 03:14:07
|
||||
$date = DateTime::createFromFormat('U', mt_rand(0, 2147483647));
|
||||
$str = ($dataFormat === IMocker::DATA_FORMAT_DATE) ? $date->format('Y-m-d') : $date->format('Y-m-d\TH:i:sP');
|
||||
|
||||
// truncate or pad datestring to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength, ' ');
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_PASSWORD:
|
||||
// use list of most popular passwords
|
||||
$obviousPassList = [
|
||||
'qwerty',
|
||||
'qwerty12345',
|
||||
'hello',
|
||||
'12345',
|
||||
'0000',
|
||||
'qwerty12345!',
|
||||
'qwertyuiop[]',
|
||||
];
|
||||
$str = $obviousPassList[mt_rand(0, count($obviousPassList) - 1)];
|
||||
|
||||
// truncate or pad password to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_UUID:
|
||||
// use php built-in uniqid function
|
||||
$str = uniqid();
|
||||
|
||||
// truncate or pad password to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_EMAIL:
|
||||
// just for visionary purpose, not related to real persons
|
||||
$fakeEmailList = [
|
||||
'johndoe',
|
||||
'lhoswald',
|
||||
'ojsimpson',
|
||||
'mlking',
|
||||
'jfkennedy',
|
||||
];
|
||||
$str = $fakeEmailList[mt_rand(0, count($fakeEmailList) - 1)] . '@example.com';
|
||||
|
||||
// truncate or pad email to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
default:
|
||||
$str = $getLoremIpsum(mt_rand($minLength, $maxLength));
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock boolean type
|
||||
* Equivalent to mockData(DATA_TYPE_BOOLEAN);
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mockBoolean()
|
||||
{
|
||||
return (bool) mt_rand(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock array type
|
||||
* Equivalent to mockData(DATA_TYPE_ARRAY);
|
||||
*
|
||||
* @param object|array $items Object or assoc array of described items
|
||||
* @param int|null $minItems (optional) An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxItems (optional) An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword
|
||||
* @param bool|null $uniqueItems (optional) If it has boolean value true, the instance validates successfully if all of its elements are unique
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mockArray(
|
||||
$items,
|
||||
$minItems = 0,
|
||||
$maxItems = null,
|
||||
$uniqueItems = false
|
||||
) {
|
||||
$arr = [];
|
||||
$minSize = 0;
|
||||
$maxSize = \PHP_INT_MAX;
|
||||
|
||||
if (
|
||||
(is_array($items) === false && is_object($items) === false)
|
||||
|| (is_array($items) && array_key_exists('type', $items) === false)
|
||||
|| (is_object($items) && isset($items->type) === false)
|
||||
) {
|
||||
new InvalidArgumentException('"items" must be object or assoc array with "type" key');
|
||||
}
|
||||
|
||||
if ($minItems !== null) {
|
||||
if (is_integer($minItems) === false || $minItems < 0) {
|
||||
throw new InvalidArgumentException('"mitItems" must be an integer. This integer must be greater than, or equal to, 0');
|
||||
}
|
||||
$minSize = $minItems;
|
||||
}
|
||||
|
||||
if ($maxItems !== null) {
|
||||
if (is_integer($maxItems) === false || $maxItems < 0) {
|
||||
throw new InvalidArgumentException('"maxItems" must be an integer. This integer must be greater than, or equal to, 0.');
|
||||
}
|
||||
if ($maxItems < $minItems) {
|
||||
throw new InvalidArgumentException('"maxItems" value cannot be less than "minItems"');
|
||||
}
|
||||
$maxSize = $maxItems;
|
||||
}
|
||||
|
||||
$options = $this->extractSchemaProperties($items);
|
||||
$dataType = $options['type'];
|
||||
$dataFormat = $options['format'] ?? null;
|
||||
$ref = $options['$ref'] ?? null;
|
||||
|
||||
// always generate smallest possible array to avoid huge JSON responses
|
||||
$arrSize = ($maxSize < 1) ? $maxSize : max($minSize, 1);
|
||||
while (count($arr) < $arrSize) {
|
||||
$data = $this->mockFromRef($ref);
|
||||
$arr[] = ($data) ? $data : $this->mock($dataType, $dataFormat, $options);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock object type.
|
||||
* Equivalent to mockData(DATA_TYPE_OBJECT);
|
||||
*
|
||||
* @param object|array $properties Object or array of described properties
|
||||
* @param int|null $minProperties (optional) An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxProperties (optional) An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
||||
* @param bool|object|array|null $additionalProperties (optional) If "additionalProperties" is true, validation always succeeds.
|
||||
* If "additionalProperties" is false, validation succeeds only if the instance is an object and all properties on the instance were covered by "properties" and/or "patternProperties".
|
||||
* If "additionalProperties" is an object, validate the value as a schema to all of the properties that weren't validated by "properties" nor "patternProperties".
|
||||
* @param array|null $required (optional) This array MUST have at least one element. Elements of this array must be strings, and MUST be unique.
|
||||
* An object instance is valid if its property set contains all elements in this array value.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function mockObject(
|
||||
$properties,
|
||||
$minProperties = 0,
|
||||
$maxProperties = null,
|
||||
$additionalProperties = null,
|
||||
$required = null
|
||||
) {
|
||||
$obj = new StdClass();
|
||||
|
||||
if (is_object($properties) === false && is_array($properties) === false) {
|
||||
throw new InvalidArgumentException('The value of "properties" must be an array or object');
|
||||
}
|
||||
|
||||
foreach ($properties as $propName => $propValue) {
|
||||
if (is_object($propValue) === false && is_array($propValue) === false) {
|
||||
throw new InvalidArgumentException('Each value of "properties" must be an array or object');
|
||||
}
|
||||
}
|
||||
|
||||
if ($minProperties !== null) {
|
||||
if (is_integer($minProperties) === false || $minProperties < 0) {
|
||||
throw new InvalidArgumentException('"minProperties" must be an integer. This integer must be greater than, or equal to, 0');
|
||||
}
|
||||
}
|
||||
|
||||
if ($maxProperties !== null) {
|
||||
if (is_integer($maxProperties) === false || $maxProperties < 0) {
|
||||
throw new InvalidArgumentException('"maxProperties" must be an integer. This integer must be greater than, or equal to, 0.');
|
||||
}
|
||||
if ($maxProperties < $minProperties) {
|
||||
throw new InvalidArgumentException('"maxProperties" value cannot be less than "minProperties"');
|
||||
}
|
||||
}
|
||||
|
||||
if ($additionalProperties !== null) {
|
||||
if (is_bool($additionalProperties) === false && is_object($additionalProperties) === false && is_array($additionalProperties) === false) {
|
||||
throw new InvalidArgumentException('The value of "additionalProperties" must be a boolean or object or array.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($required !== null) {
|
||||
if (
|
||||
is_array($required) === false
|
||||
|| count($required) > count(array_unique($required))
|
||||
) {
|
||||
throw new InvalidArgumentException('The value of "required" must be an array. Elements of this array must be unique.');
|
||||
}
|
||||
foreach ($required as $requiredPropName) {
|
||||
if (is_string($requiredPropName) === false) {
|
||||
throw new InvalidArgumentException('Elements of "required" array must be strings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($properties as $propName => $propValue) {
|
||||
$options = $this->extractSchemaProperties($propValue);
|
||||
$dataType = $options['type'];
|
||||
$dataFormat = $options['format'] ?? null;
|
||||
$ref = $options['$ref'] ?? null;
|
||||
$data = $this->mockFromRef($ref);
|
||||
$obj->$propName = ($data) ? $data : $this->mock($dataType, $dataFormat, $options);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data from schema.
|
||||
*
|
||||
* @param array|object $schema OpenAPI schema
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromSchema($schema)
|
||||
{
|
||||
$props = $this->extractSchemaProperties($schema);
|
||||
if (array_key_exists('$ref', $props) && !empty($props['$ref'])) {
|
||||
return $this->mockFromRef($props['$ref']);
|
||||
} elseif ($props['type'] === null) {
|
||||
throw new InvalidArgumentException('"schema" must be object or assoc array with "type" property');
|
||||
}
|
||||
return $this->mock($props['type'], $props['format'], $props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock data by referenced schema.
|
||||
* TODO: this method will return model instance, not an StdClass
|
||||
*
|
||||
* @param string|null $ref Ref to model, eg. #/components/schemas/User
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromRef($ref)
|
||||
{
|
||||
$data = null;
|
||||
if (is_string($ref) && !empty($ref)) {
|
||||
$refName = static::getSimpleRef($ref);
|
||||
$modelName = static::toModelName($refName);
|
||||
$modelClass = '{{modelPackage}}\\' . $modelName;
|
||||
if (!class_exists($modelClass) || !method_exists($modelClass, 'getOpenApiSchema')) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Model %s not found or method %s doesn\'t exist',
|
||||
$modelClass,
|
||||
$modelClass . '::getOpenApiSchema'
|
||||
));
|
||||
}
|
||||
$data = $this->mockFromSchema($modelClass::getOpenApiSchema(true));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Extract OAS properties from array or object.
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param array|object $val Processed array or object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractSchemaProperties($val)
|
||||
{
|
||||
$props = [
|
||||
'type' => null,
|
||||
'format' => null,
|
||||
];
|
||||
foreach (
|
||||
[
|
||||
'type',
|
||||
'format',
|
||||
'minimum',
|
||||
'maximum',
|
||||
'exclusiveMinimum',
|
||||
'exclusiveMaximum',
|
||||
'minLength',
|
||||
'maxLength',
|
||||
'pattern',
|
||||
'enum',
|
||||
'items',
|
||||
'minItems',
|
||||
'maxItems',
|
||||
'uniqueItems',
|
||||
'properties',
|
||||
'minProperties',
|
||||
'maxProperties',
|
||||
'additionalProperties',
|
||||
'required',
|
||||
'example',
|
||||
'$ref',
|
||||
] as $propName
|
||||
) {
|
||||
if (is_array($val) && array_key_exists($propName, $val)) {
|
||||
$props[$propName] = $val[$propName];
|
||||
} elseif (is_object($val) && isset($val->$propName)) {
|
||||
$props[$propName] = $val->$propName;
|
||||
}
|
||||
}
|
||||
return $props;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
protected function getRandomNumber(
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false,
|
||||
$maxDecimals = 4
|
||||
) {
|
||||
$min = 0;
|
||||
$max = mt_getrandmax();
|
||||
|
||||
if ($minimum !== null) {
|
||||
if (is_numeric($minimum) === false) {
|
||||
throw new InvalidArgumentException('"minimum" must be a number');
|
||||
}
|
||||
$min = $minimum;
|
||||
}
|
||||
|
||||
if ($maximum !== null) {
|
||||
if (is_numeric($maximum) === false) {
|
||||
throw new InvalidArgumentException('"maximum" must be a number');
|
||||
}
|
||||
$max = $maximum;
|
||||
}
|
||||
|
||||
if ($exclusiveMinimum !== false) {
|
||||
if (is_bool($exclusiveMinimum) === false) {
|
||||
throw new InvalidArgumentException('"exclusiveMinimum" must be a boolean');
|
||||
} elseif ($minimum === null) {
|
||||
throw new InvalidArgumentException('If "exclusiveMinimum" is present, "minimum" must also be present');
|
||||
}
|
||||
$min += 1;
|
||||
}
|
||||
|
||||
if ($exclusiveMaximum !== false) {
|
||||
if (is_bool($exclusiveMaximum) === false) {
|
||||
throw new InvalidArgumentException('"exclusiveMaximum" must be a boolean');
|
||||
} elseif ($maximum === null) {
|
||||
throw new InvalidArgumentException('If "exclusiveMaximum" is present, "maximum" must also be present');
|
||||
}
|
||||
$max -= 1;
|
||||
}
|
||||
|
||||
if ($max < $min) {
|
||||
throw new InvalidArgumentException('"maximum" value cannot be less than "minimum"');
|
||||
}
|
||||
|
||||
if ($maxDecimals > 0) {
|
||||
return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $maxDecimals);
|
||||
}
|
||||
return mt_rand((int) $min, (int) $max);
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,239 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{mockPackage}};
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* {{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} Class Doc Comment
|
||||
*
|
||||
* @package {{mockPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
interface {{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}}
|
||||
{
|
||||
/** @var string DATA_TYPE_INTEGER */
|
||||
public const DATA_TYPE_INTEGER = 'integer';
|
||||
|
||||
/** @var string DATA_TYPE_NUMBER */
|
||||
public const DATA_TYPE_NUMBER = 'number';
|
||||
|
||||
/** @var string DATA_TYPE_STRING */
|
||||
public const DATA_TYPE_STRING = 'string';
|
||||
|
||||
/** @var string DATA_TYPE_BOOLEAN */
|
||||
public const DATA_TYPE_BOOLEAN = 'boolean';
|
||||
|
||||
/** @var string DATA_TYPE_FILE */
|
||||
public const DATA_TYPE_FILE = 'file';
|
||||
|
||||
/** @var string DATA_TYPE_ARRAY */
|
||||
public const DATA_TYPE_ARRAY = 'array';
|
||||
|
||||
/** @var string DATA_TYPE_OBJECT */
|
||||
public const DATA_TYPE_OBJECT = 'object';
|
||||
|
||||
/** @var string DATA_FORMAT_INT32 Signed 32 bits */
|
||||
public const DATA_FORMAT_INT32 = 'int32';
|
||||
|
||||
/** @var string DATA_FORMAT_INT64 Signed 64 bits */
|
||||
public const DATA_FORMAT_INT64 = 'int64';
|
||||
|
||||
/** @var string DATA_FORMAT_FLOAT */
|
||||
public const DATA_FORMAT_FLOAT = 'float';
|
||||
|
||||
/** @var string DATA_FORMAT_DOUBLE */
|
||||
public const DATA_FORMAT_DOUBLE = 'double';
|
||||
|
||||
/** @var string DATA_FORMAT_BYTE base64 encoded characters */
|
||||
public const DATA_FORMAT_BYTE = 'byte';
|
||||
|
||||
/** @var string DATA_FORMAT_BINARY Any sequence of octets */
|
||||
public const DATA_FORMAT_BINARY = 'binary';
|
||||
|
||||
/** @var string DATA_FORMAT_DATE As defined by full-date [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14) */
|
||||
public const DATA_FORMAT_DATE = 'date';
|
||||
|
||||
/** @var string DATA_FORMAT_DATE_TIME As defined by date-time [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14) */
|
||||
public const DATA_FORMAT_DATE_TIME = 'date-time';
|
||||
|
||||
/** @var string DATA_FORMAT_PASSWORD Used to hint UIs the input needs to be obscured. */
|
||||
public const DATA_FORMAT_PASSWORD = 'password';
|
||||
|
||||
/** @var string DATA_FORMAT_EMAIL */
|
||||
public const DATA_FORMAT_EMAIL = 'email';
|
||||
|
||||
/** @var string DATA_FORMAT_UUID */
|
||||
public const DATA_FORMAT_UUID = 'uuid';
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data.
|
||||
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types
|
||||
*
|
||||
* @param $dataType string OpenApi data type. Use constants from this class
|
||||
* @param $dataFormat string (optional) OpenApi data format
|
||||
* @param $options array|null (optional) OpenApi data options
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mock(
|
||||
$dataType,
|
||||
$dataFormat = null,
|
||||
$options = []
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock integer type
|
||||
* Equivalent to mockData(DATA_TYPE_INTEGER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) int32 or int64
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function mockInteger(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock number type
|
||||
* Equivalent to mockData(DATA_TYPE_NUMBER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) float or double
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function mockNumber(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock string type
|
||||
* Equivalent to mockData(DATA_TYPE_STRING);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) one of byte, binary, date, date-time, password
|
||||
* @param int|null $minLength (optional) Default is 0
|
||||
* @param int|null $maxLength (optional) Default is 100 chars
|
||||
* @param array $enum (optional) This array should have at least one element.
|
||||
* Elements in the array should be unique.
|
||||
* @param string|null $pattern (optional) This string should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
||||
* Recall: regular expressions are not implicitly anchored.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mockString(
|
||||
$dataFormat = null,
|
||||
$minLength = 0,
|
||||
$maxLength = null,
|
||||
$enum = null,
|
||||
$pattern = null
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock boolean type
|
||||
* Equivalent to mockData(DATA_TYPE_BOOLEAN);
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mockBoolean();
|
||||
|
||||
/**
|
||||
* Shortcut to mock array type
|
||||
* Equivalent to mockData(DATA_TYPE_ARRAY);
|
||||
*
|
||||
* @param object|array $items Object or assoc array of described items
|
||||
* @param int|null $minItems (optional) An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxItems (optional) An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword
|
||||
* @param bool|null $uniqueItems (optional) If it has boolean value true, the instance validates successfully if all of its elements are unique
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mockArray(
|
||||
$items,
|
||||
$minItems = 0,
|
||||
$maxItems = null,
|
||||
$uniqueItems = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock object type.
|
||||
* Equivalent to mockData(DATA_TYPE_OBJECT);
|
||||
*
|
||||
* @param object|array $properties Object or array of described properties
|
||||
* @param int|null $minProperties (optional) An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxProperties (optional) An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
||||
* @param bool|object|array|null $additionalProperties (optional) If "additionalProperties" is true, validation always succeeds.
|
||||
* If "additionalProperties" is false, validation succeeds only if the instance is an object and all properties on the instance were covered by "properties" and/or "patternProperties".
|
||||
* If "additionalProperties" is an object, validate the value as a schema to all of the properties that weren't validated by "properties" nor "patternProperties".
|
||||
* @param array|null $required (optional) This array MUST have at least one element. Elements of this array must be strings, and MUST be unique.
|
||||
* An object instance is valid if its property set contains all elements in this array value.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function mockObject(
|
||||
$properties,
|
||||
$minProperties = 0,
|
||||
$maxProperties = null,
|
||||
$additionalProperties = null,
|
||||
$required = null
|
||||
);
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data from schema.
|
||||
*
|
||||
* @param array|object $schema OpenAPI schema
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromSchema($schema);
|
||||
|
||||
/**
|
||||
* Mock data by referenced schema.
|
||||
* TODO: this method will return model instance, not an StdClass
|
||||
*
|
||||
* @param string|null $ref Ref to model, eg. #/components/schemas/User
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromRef($ref);
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,171 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{mockPackage}};
|
||||
|
||||
use Slim\Factory\AppFactory;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use {{mockPackage}}\{{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}};
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* OpenApiDataMockerMiddleware Class Doc Comment
|
||||
*
|
||||
* @package {{mockPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
final class OpenApiDataMockerMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @var {{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} DataMocker.
|
||||
*/
|
||||
private $mocker;
|
||||
|
||||
/**
|
||||
* @var array Array of responses schemas.
|
||||
*/
|
||||
private $responses;
|
||||
|
||||
/**
|
||||
* @var callable|null Custom callback to select mocked response.
|
||||
*/
|
||||
private $getMockResponseCallback;
|
||||
|
||||
/**
|
||||
* @var callable|null Custom after callback.
|
||||
*/
|
||||
private $afterCallback;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param {{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} $mocker DataMocker.
|
||||
* @param array $responses Array of responses schemas.
|
||||
* @param callable|null $getMockResponseCallback Custom callback to select mocked response.
|
||||
* Mock feature is disabled when this argument is null.
|
||||
* @example $getMockResponseCallback = function (ServerRequestInterface $request, array $responses) {
|
||||
* // check if client clearly asks for mocked response
|
||||
* if (
|
||||
* $request->hasHeader('X-{{invokerPackage}}-Mock')
|
||||
* && $request->header('X-{{invokerPackage}}-Mock')[0] === 'ping'
|
||||
* ) {
|
||||
* return $responses[array_key_first($responses)];
|
||||
* }
|
||||
* return false;
|
||||
* };
|
||||
* @param callable|null $afterCallback After callback.
|
||||
* Function must return response instance.
|
||||
* @example $afterCallback = function (ServerRequestInterface $request, ResponseInterface $response) {
|
||||
* // mark mocked response to distinguish real and fake responses
|
||||
* return $response->withHeader('X-{{invokerPackage}}-Mock', 'pong');
|
||||
* };
|
||||
*/
|
||||
public function __construct(
|
||||
{{interfaceNamePrefix}}OpenApiDataMocker{{interfaceNameSuffix}} $mocker,
|
||||
array $responses,
|
||||
$getMockResponseCallback = null,
|
||||
$afterCallback = null
|
||||
) {
|
||||
$this->mocker = $mocker;
|
||||
$this->responses = $responses;
|
||||
if (is_callable($getMockResponseCallback)) {
|
||||
$this->getMockResponseCallback = $getMockResponseCallback;
|
||||
} elseif ($getMockResponseCallback !== null) {
|
||||
// wrong argument type
|
||||
throw new InvalidArgumentException('\$getMockResponseCallback must be closure or null');
|
||||
}
|
||||
|
||||
if (is_callable($afterCallback)) {
|
||||
$this->afterCallback = $afterCallback;
|
||||
} elseif ($afterCallback !== null) {
|
||||
// wrong argument type
|
||||
throw new InvalidArgumentException('\$afterCallback must be closure or null');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse incoming JSON input into a native PHP format
|
||||
*
|
||||
* @param ServerRequestInterface $request HTTP request
|
||||
* @param RequestHandlerInterface $handler Request handler
|
||||
*
|
||||
* @return ResponseInterface HTTP response
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$customCallback = $this->getMockResponseCallback;
|
||||
$customAfterCallback = $this->afterCallback;
|
||||
$mockedResponse = (is_callable($customCallback)) ? $customCallback($request, $this->responses) : null;
|
||||
if (
|
||||
is_array($mockedResponse)
|
||||
&& array_key_exists('code', $mockedResponse)
|
||||
&& array_key_exists('jsonSchema', $mockedResponse)
|
||||
) {
|
||||
// response schema succesfully selected, we can mock it now
|
||||
$statusCode = ($mockedResponse['code'] === 0) ? 200 : $mockedResponse['code'];
|
||||
$contentType = '*/*';
|
||||
$response = AppFactory::determineResponseFactory()->createResponse($statusCode);
|
||||
$responseSchema = json_decode($mockedResponse['jsonSchema'], true);
|
||||
|
||||
if (is_array($responseSchema) && array_key_exists('headers', $responseSchema)) {
|
||||
// response schema contains headers definitions, apply them one by one
|
||||
foreach ($responseSchema['headers'] as $headerName => $headerDefinition) {
|
||||
$response = $response->withHeader($headerName, $this->mocker->mockFromSchema($headerDefinition['schema']));
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
is_array($responseSchema)
|
||||
&& array_key_exists('content', $responseSchema)
|
||||
&& !empty($responseSchema['content'])
|
||||
) {
|
||||
// response schema contains body definition
|
||||
$responseContentSchema = null;
|
||||
foreach ($responseSchema['content'] as $schemaContentType => $schemaDefinition) {
|
||||
// we can respond in JSON format when any(*/*) content-type allowed
|
||||
// or JSON(application/json) content-type specifically defined
|
||||
if (
|
||||
$schemaContentType === '*/*'
|
||||
|| strtolower(substr($schemaContentType, 0, 16)) === 'application/json'
|
||||
) {
|
||||
$contentType = 'application/json';
|
||||
$responseContentSchema = $schemaDefinition['schema'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($contentType === 'application/json') {
|
||||
$responseBody = $this->mocker->mockFromSchema($responseContentSchema);
|
||||
$response->getBody()->write(json_encode($responseBody));
|
||||
} else {
|
||||
// notify developer that only application/json response supported so far
|
||||
$response->getBody()->write('Mock feature supports only "application/json" content-type!');
|
||||
}
|
||||
}
|
||||
|
||||
// after callback applied only when mocked response schema has been selected
|
||||
if (is_callable($customAfterCallback)) {
|
||||
$response = $customAfterCallback($request, $response);
|
||||
}
|
||||
|
||||
// no reason to execute following middlewares (auth, validation etc.)
|
||||
// return mocked response and end connection
|
||||
return $response
|
||||
->withHeader('Content-Type', $contentType);
|
||||
}
|
||||
|
||||
// no response selected, mock feature disabled
|
||||
// execute following middlewares
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,258 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{mockPackage}};
|
||||
|
||||
use {{mockPackage}}\OpenApiDataMockerMiddleware;
|
||||
use {{mockPackage}}\OpenApiDataMocker;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\Factory\ServerRequestCreatorFactory;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* OpenApiDataMockerMiddlewareTest Class Doc Comment
|
||||
*
|
||||
* @package {{mockPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
* @coversDefaultClass \{{mockPackage}}\OpenApiDataMockerMiddleware
|
||||
*/
|
||||
class OpenApiDataMockerMiddlewareTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @dataProvider provideConstructCorrectArguments
|
||||
*/
|
||||
public function testConstructor(
|
||||
$mocker,
|
||||
$responses,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback
|
||||
) {
|
||||
$middleware = new OpenApiDataMockerMiddleware($mocker, $responses, $getMockResponseCallback, $afterCallback);
|
||||
$this->assertInstanceOf(OpenApiDataMockerMiddleware::class, $middleware);
|
||||
$this->assertNotNull($middleware);
|
||||
}
|
||||
|
||||
public function provideConstructCorrectArguments()
|
||||
{
|
||||
$getMockResponseCallback = function () {
|
||||
return false;
|
||||
};
|
||||
$afterCallback = function () {
|
||||
return false;
|
||||
};
|
||||
return [
|
||||
[new OpenApiDataMocker(), [], null, null],
|
||||
[new OpenApiDataMocker(), [], $getMockResponseCallback, $afterCallback],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @dataProvider provideConstructInvalidArguments
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedException \TypeError
|
||||
*/
|
||||
public function testConstructorWithInvalidArguments(
|
||||
$mocker,
|
||||
$responses,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback
|
||||
) {
|
||||
$middleware = new OpenApiDataMockerMiddleware($mocker, $responses, $getMockResponseCallback, $afterCallback);
|
||||
}
|
||||
|
||||
public function provideConstructInvalidArguments()
|
||||
{
|
||||
return [
|
||||
'getMockResponseCallback not callable' => [
|
||||
new OpenApiDataMocker(), [], 'foobar', null,
|
||||
],
|
||||
'afterCallback not callable' => [
|
||||
new OpenApiDataMocker(), [], null, 'foobar',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::process
|
||||
* @dataProvider provideProcessArguments
|
||||
*/
|
||||
public function testProcess(
|
||||
$mocker,
|
||||
$responses,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback,
|
||||
$request,
|
||||
$expectedStatusCode,
|
||||
$expectedHeaders,
|
||||
$notExpectedHeaders,
|
||||
$expectedBody
|
||||
) {
|
||||
|
||||
// Create a stub for the RequestHandlerInterface interface.
|
||||
$handler = $this->createMock(RequestHandlerInterface::class);
|
||||
$handler->method('handle')
|
||||
->willReturn(AppFactory::determineResponseFactory()->createResponse());
|
||||
|
||||
$middleware = new OpenApiDataMockerMiddleware(
|
||||
$mocker,
|
||||
$responses,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback
|
||||
);
|
||||
$response = $middleware->process($request, $handler);
|
||||
|
||||
// check status code
|
||||
$this->assertSame($expectedStatusCode, $response->getStatusCode());
|
||||
|
||||
// check http headers in request
|
||||
foreach ($expectedHeaders as $expectedHeader => $expectedHeaderValue) {
|
||||
$this->assertTrue($response->hasHeader($expectedHeader));
|
||||
if ($expectedHeaderValue !== '*') {
|
||||
$this->assertSame($expectedHeaderValue, $response->getHeader($expectedHeader)[0]);
|
||||
}
|
||||
}
|
||||
foreach ($notExpectedHeaders as $notExpectedHeader) {
|
||||
$this->assertFalse($response->hasHeader($notExpectedHeader));
|
||||
}
|
||||
|
||||
// check body
|
||||
if (is_array($expectedBody)) {
|
||||
// random values, check keys only
|
||||
foreach ($expectedBody as $attribute => $value) {
|
||||
$this->assertObjectHasAttribute($attribute, json_decode((string) $response->getBody(), false));
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals($expectedBody, (string) $response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
public function provideProcessArguments()
|
||||
{
|
||||
$mocker = new OpenApiDataMocker();
|
||||
$isMockResponseRequired = function (ServerRequestInterface $request) {
|
||||
$mockHttpHeader = 'X-{{invokerPackage}}-Mock';
|
||||
return $request->hasHeader($mockHttpHeader)
|
||||
&& $request->getHeader($mockHttpHeader)[0] === 'ping';
|
||||
};
|
||||
|
||||
$getMockResponseCallback = function (ServerRequestInterface $request, array $responses) use ($isMockResponseRequired) {
|
||||
if ($isMockResponseRequired($request)) {
|
||||
if (array_key_exists('default', $responses)) {
|
||||
return $responses['default'];
|
||||
}
|
||||
|
||||
// return first response
|
||||
return $responses[array_key_first($responses)];
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
$afterCallback = function ($request, $response) use ($isMockResponseRequired) {
|
||||
if ($isMockResponseRequired($request)) {
|
||||
$response = $response->withHeader('X-{{invokerPackage}}-Mock', 'pong');
|
||||
}
|
||||
|
||||
return $response;
|
||||
};
|
||||
|
||||
$responses = [
|
||||
'400' => [
|
||||
'code' => 400,
|
||||
'jsonSchema' => json_encode([
|
||||
'description' => 'Bad Request Response',
|
||||
'content' => new StdClass(),
|
||||
]),
|
||||
],
|
||||
'default' => [
|
||||
'code' => 201,
|
||||
'jsonSchema' => json_encode([
|
||||
'description' => 'Success Response',
|
||||
'headers' => [
|
||||
'X-Location' => ['schema' => ['type' => 'string']],
|
||||
'X-Created-Id' => ['schema' => ['type' => 'integer']],
|
||||
],
|
||||
'content' => [
|
||||
'application/json;encoding=utf-8' => ['schema' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer'], 'className' => ['type' => 'string'], 'declawed' => ['type' => 'boolean']]]],
|
||||
],
|
||||
]),
|
||||
],
|
||||
];
|
||||
|
||||
$responsesXmlOnly = [
|
||||
'default' => [
|
||||
'code' => 201,
|
||||
'jsonSchema' => json_encode([
|
||||
'description' => 'Success Response',
|
||||
'content' => [
|
||||
'application/xml' => [
|
||||
'schema' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
];
|
||||
|
||||
$requestFactory = ServerRequestCreatorFactory::create();
|
||||
|
||||
return [
|
||||
'callbacks null' => [
|
||||
$mocker,
|
||||
$responses,
|
||||
null,
|
||||
null,
|
||||
$requestFactory->createServerRequestFromGlobals(),
|
||||
200,
|
||||
[],
|
||||
['X-{{invokerPackage}}-Mock', 'x-location', 'x-created-id'],
|
||||
'',
|
||||
],
|
||||
'xml not supported' => [
|
||||
$mocker,
|
||||
$responsesXmlOnly,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback,
|
||||
$requestFactory
|
||||
->createServerRequestFromGlobals()
|
||||
->withHeader('X-{{invokerPackage}}-Mock', 'ping'),
|
||||
201,
|
||||
['X-{{invokerPackage}}-Mock' => 'pong', 'content-type' => '*/*'],
|
||||
['x-location', 'x-created-id'],
|
||||
'Mock feature supports only "application/json" content-type!',
|
||||
],
|
||||
'mock response default schema' => [
|
||||
$mocker,
|
||||
$responses,
|
||||
$getMockResponseCallback,
|
||||
$afterCallback,
|
||||
$requestFactory
|
||||
->createServerRequestFromGlobals()
|
||||
->withHeader('X-{{invokerPackage}}-Mock', 'ping'),
|
||||
201,
|
||||
['X-{{invokerPackage}}-Mock' => 'pong', 'content-type' => 'application/json', 'x-location' => '*', 'x-created-id' => '*'],
|
||||
[],
|
||||
[
|
||||
'id' => 1,
|
||||
'className' => 'cat',
|
||||
'declawed' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
File diff suppressed because it is too large
Load Diff
@ -15,12 +15,14 @@
|
||||
<directory>{{apiTestPath}}</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Models">
|
||||
<file>./{{testBasePath}}/BaseModelTest.php</file>
|
||||
<directory>{{modelTestPath}}</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">{{apiSrcPath}}</directory>
|
||||
<file>./{{srcBasePath}}/BaseModel.php</file>
|
||||
<directory suffix=".php">{{modelSrcPath}}</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{utilsPackage}};
|
||||
|
||||
/**
|
||||
* {{traitNamePrefix}}StringUtils{{traitNameSuffix}} Class Doc Comment
|
||||
* This class duplicates functionality of StringUtils.java and AbstractPhpCodegen.java classes.
|
||||
*
|
||||
* @package {{utilsPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
trait {{traitNamePrefix}}StringUtils{{traitNameSuffix}}
|
||||
{
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc)
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/StringUtils.java class.
|
||||
*
|
||||
* @param string $word string to be camelize
|
||||
* @param bool $lowercaseFirstLetter lower case for first letter if set to true
|
||||
*
|
||||
* @return string camelized string
|
||||
*/
|
||||
public static function camelize($word, $lowercaseFirstLetter = false)
|
||||
{
|
||||
// Replace all slashes with dots (package separator)
|
||||
$p = '/\/(.?)/';
|
||||
$word = preg_replace($p, '.$1', $word);
|
||||
|
||||
// case out dots
|
||||
$parts = explode('.', $word);
|
||||
$str = '';
|
||||
foreach ($parts as $z) {
|
||||
if (strlen($z) > 0) {
|
||||
$str .= strtoupper(substr($z, 0, 1)) . substr($z, 1);
|
||||
}
|
||||
}
|
||||
$word = $str;
|
||||
|
||||
// Uppercase the class name.
|
||||
$p = '/(\.?)(\w)([^\.]*)$/';
|
||||
$word = preg_replace_callback($p, function ($matches) {
|
||||
$rep = $matches[1] . strtoupper($matches[2]) . $matches[3];
|
||||
$rep = preg_replace('/\$/', '\\\$', $rep);
|
||||
return $rep;
|
||||
}, $word);
|
||||
|
||||
// Remove all underscores (underscore_case to camelCase)
|
||||
$p = '/(_)(.)/';
|
||||
while (preg_match($p, $word, $matches) === 1) {
|
||||
$original = $matches[2][0];
|
||||
$upperCase = strtoupper($original);
|
||||
if ($original === $upperCase) {
|
||||
$word = preg_replace($p, '$2', $word);
|
||||
} else {
|
||||
$word = preg_replace($p, $upperCase, $word);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all hyphens (hyphen-case to camelCase)
|
||||
$p = '/(-)(.)/';
|
||||
while (preg_match($p, $word, $matches) === 1) {
|
||||
$upperCase = strtoupper($matches[2][0]);
|
||||
$word = preg_replace($p, $upperCase, $word);
|
||||
}
|
||||
|
||||
if ($lowercaseFirstLetter === true && strlen($word) > 0) {
|
||||
$i = 0;
|
||||
$charAt = substr($word, $i, 1);
|
||||
while (
|
||||
$i + 1 < strlen($word)
|
||||
&& !(
|
||||
($charAt >= 'a' && $charAt <= 'z')
|
||||
|| ($charAt >= 'A' && $charAt <= 'Z')
|
||||
)
|
||||
) {
|
||||
$i++;
|
||||
$charAt = substr($word, $i, 1);
|
||||
}
|
||||
$i++;
|
||||
$word = strtolower(substr($word, 0, $i)) . substr($word, $i);
|
||||
}
|
||||
|
||||
// remove all underscore
|
||||
$word = str_replace('_', '', $word);
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether string is reserved php keyword.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java class.
|
||||
*
|
||||
* @param string $word Checked string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isReservedWord($word)
|
||||
{
|
||||
if (is_string($word) === false) {
|
||||
return false;
|
||||
}
|
||||
// __halt_compiler is ommited because class names with underscores not allowed anyway
|
||||
return in_array(
|
||||
strtolower($word),
|
||||
['abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor']
|
||||
);
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
{{>licenseInfo}}
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/{{#apiInfo}}
|
||||
namespace {{utilsPackage}};
|
||||
|
||||
use {{utilsPackage}}\{{traitNamePrefix}}StringUtils{{traitNameSuffix}} as StringUtils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* {{traitNamePrefix}}StringUtils{{traitNameSuffix}}Test Class Doc Comment
|
||||
*
|
||||
* @package {{utilsPackage}}
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
* @coversDefaultClass \{{utilsPackage}}\{{traitNamePrefix}}StringUtils{{traitNameSuffix}}
|
||||
*/
|
||||
class {{traitNamePrefix}}StringUtils{{traitNameSuffix}}Test extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers ::camelize
|
||||
* @dataProvider provideWordsForCamelizeTest
|
||||
*/
|
||||
public function testCamelize($word, $lowercaseFirstLetter, $expectedWord)
|
||||
{
|
||||
$this->assertSame($expectedWord, StringUtils::camelize($word, $lowercaseFirstLetter));
|
||||
}
|
||||
|
||||
public function provideWordsForCamelizeTest()
|
||||
{
|
||||
return [
|
||||
// fixtures from modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/StringUtilsTest.java
|
||||
['openApiServer/model/pet', null, 'OpenApiServerModelPet'],
|
||||
['abcd', null, 'Abcd'],
|
||||
['some-value', null, 'SomeValue'],
|
||||
['some-Value', null, 'SomeValue'],
|
||||
['some_value', null, 'SomeValue'],
|
||||
['some_Value', null, 'SomeValue'],
|
||||
['$type', null, '$Type'],
|
||||
|
||||
['abcd', true, 'abcd'],
|
||||
['some-value', true, 'someValue'],
|
||||
['some_value', true, 'someValue'],
|
||||
['Abcd', true, 'abcd'],
|
||||
['$type', true, '$type'],
|
||||
|
||||
['123', true, '123'],
|
||||
['$123', true, '$123'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::isReservedWord
|
||||
* @dataProvider provideWordsForIsReservedTest
|
||||
*/
|
||||
public function testisReservedWord($word, $expected)
|
||||
{
|
||||
$this->assertSame($expected, StringUtils::isReservedWord($word));
|
||||
}
|
||||
|
||||
public function provideWordsForIsReservedTest()
|
||||
{
|
||||
return [
|
||||
['return', true],
|
||||
['switch', true],
|
||||
['class', true],
|
||||
['interface', true],
|
||||
['ABSTRACT', true],
|
||||
['Trait', true],
|
||||
['final', true],
|
||||
['foobar', false],
|
||||
['DateTime', false],
|
||||
['Pet', false],
|
||||
[123, false],
|
||||
[null, false],
|
||||
];
|
||||
}
|
||||
}
|
||||
{{/apiInfo}}
|
@ -2,11 +2,7 @@
|
||||
.htaccess
|
||||
README.md
|
||||
composer.json
|
||||
docs/MockServer.md
|
||||
index.php
|
||||
lib/Api/AbstractAnotherFakeApi.php
|
||||
lib/Api/AbstractFakeApi.php
|
||||
lib/Api/AbstractFakeClassnameTags123Api.php
|
||||
lib/Api/AbstractPetApi.php
|
||||
lib/Api/AbstractStoreApi.php
|
||||
lib/Api/AbstractUserApi.php
|
||||
@ -23,65 +19,31 @@ lib/Auth/AbstractAuthenticator.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/Interfaces/ModelInterface.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/Auth/AbstractAuthenticator.php
|
||||
lib/BaseModel.php
|
||||
lib/Middleware/JsonBodyParserMiddleware.php
|
||||
lib/Mock/OpenApiDataMocker.php
|
||||
lib/Mock/OpenApiDataMockerInterface.php
|
||||
lib/Mock/OpenApiDataMockerMiddleware.php
|
||||
lib/Model/AdditionalPropertiesAnyType.php
|
||||
lib/Model/AdditionalPropertiesArray.php
|
||||
lib/Model/AdditionalPropertiesBoolean.php
|
||||
lib/Model/AdditionalPropertiesClass.php
|
||||
lib/Model/AdditionalPropertiesInteger.php
|
||||
lib/Model/AdditionalPropertiesNumber.php
|
||||
lib/Model/AdditionalPropertiesObject.php
|
||||
lib/Model/AdditionalPropertiesString.php
|
||||
lib/Model/Animal.php
|
||||
lib/Model/ApiResponse.php
|
||||
lib/Model/ArrayOfArrayOfNumberOnly.php
|
||||
lib/Model/ArrayOfNumberOnly.php
|
||||
lib/Model/ArrayTest.php
|
||||
lib/Model/BigCat.php
|
||||
lib/Model/BigCatAllOf.php
|
||||
lib/Model/Capitalization.php
|
||||
lib/Model/Cat.php
|
||||
lib/Model/CatAllOf.php
|
||||
lib/Model/Category.php
|
||||
lib/Model/ClassModel.php
|
||||
lib/Model/Client.php
|
||||
lib/Model/Dog.php
|
||||
lib/Model/DogAllOf.php
|
||||
lib/Model/EnumArrays.php
|
||||
lib/Model/EnumClass.php
|
||||
lib/Model/EnumTest.php
|
||||
lib/Model/File.php
|
||||
lib/Model/FileSchemaTestClass.php
|
||||
lib/Model/FormatTest.php
|
||||
lib/Model/HasOnlyReadOnly.php
|
||||
lib/Model/MapTest.php
|
||||
lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php
|
||||
lib/Model/Model200Response.php
|
||||
lib/Model/ModelList.php
|
||||
lib/Model/ModelReturn.php
|
||||
lib/Model/Name.php
|
||||
lib/Model/NumberOnly.php
|
||||
lib/Model/InlineObject.php
|
||||
lib/Model/InlineObject1.php
|
||||
lib/Model/Order.php
|
||||
lib/Model/OuterComposite.php
|
||||
lib/Model/OuterEnum.php
|
||||
lib/Model/Pet.php
|
||||
lib/Model/ReadOnlyFirst.php
|
||||
lib/Model/SpecialModelName.php
|
||||
lib/Model/Tag.php
|
||||
lib/Model/TypeHolderDefault.php
|
||||
lib/Model/TypeHolderExample.php
|
||||
lib/Model/User.php
|
||||
lib/Model/XmlItem.php
|
||||
lib/SlimRouter.php
|
||||
lib/Utils/ModelUtilsTrait.php
|
||||
lib/Utils/StringUtilsTrait.php
|
||||
phpcs.xml.dist
|
||||
phpunit.xml.dist
|
||||
test/Mock/OpenApiDataMockerMiddlewareTest.php
|
||||
test/Mock/OpenApiDataMockerTest.php
|
||||
test/Utils/ModelUtilsTraitTest.php
|
||||
test/Utils/StringUtilsTraitTest.php
|
||||
test/Api/PetApiTest.php
|
||||
test/Api/StoreApiTest.php
|
||||
test/Api/UserApiTest.php
|
||||
test/BaseModelTest.php
|
||||
test/Model/ApiResponseTest.php
|
||||
test/Model/CategoryTest.php
|
||||
test/Model/InlineObject1Test.php
|
||||
test/Model/InlineObjectTest.php
|
||||
test/Model/OrderTest.php
|
||||
test/Model/PetTest.php
|
||||
test/Model/TagTest.php
|
||||
test/Model/UserTest.php
|
||||
|
@ -35,9 +35,9 @@ $ php -S localhost:8888 -t php-slim-server
|
||||
|
||||
### PHPUnit
|
||||
|
||||
This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing.
|
||||
This package uses PHPUnit 8 or 9(depends from your PHP version) for unit testing.
|
||||
[Test folder](test) contains templates which you can fill with real test assertions.
|
||||
How to write tests read at [PHPUnit Manual - Chapter 2. Writing Tests for PHPUnit](https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html).
|
||||
How to write tests read at [2. Writing Tests for PHPUnit - PHPUnit 8.5 Manual](https://phpunit.readthedocs.io/en/8.5/writing-tests-for-phpunit.html).
|
||||
|
||||
#### Run
|
||||
|
||||
@ -46,14 +46,12 @@ Command | Target
|
||||
`$ composer test` | All tests
|
||||
`$ composer test-apis` | Apis tests
|
||||
`$ composer test-models` | Models tests
|
||||
`$ composer test-mock` | Mock feature tests
|
||||
`$ composer test-utils` | Utils tests
|
||||
|
||||
#### Config
|
||||
|
||||
Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it.
|
||||
|
||||
Quote from [3. The Command-Line Test Runner — PHPUnit 7.4 Manual](https://phpunit.readthedocs.io/en/7.4/textui.html#command-line-options):
|
||||
Quote from [3. The Command-Line Test Runner — PHPUnit 8.5 Manual](https://phpunit.readthedocs.io/en/8.5/textui.html#command-line-options):
|
||||
|
||||
> If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.
|
||||
|
||||
@ -101,11 +99,17 @@ Switch on option in `./index.php`:
|
||||
+++ $app->addErrorMiddleware(true, true, true);
|
||||
```
|
||||
|
||||
## [Mock Server Documentation](./docs/MockServer.md)
|
||||
## Mock Server
|
||||
For a quick start uncomment [mocker middleware config](index.php#L62-L89).
|
||||
|
||||
Used packages:
|
||||
* [Openapi Data Mocker](https://github.com/ybelenko/openapi-data-mocker) - first implementation of OAS3 fake data generator.
|
||||
* [Openapi Data Mocker Server Middleware](https://github.com/ybelenko/openapi-data-mocker-server-middleware) - PSR-15 HTTP server middleware.
|
||||
* [Openapi Data Mocker Interfaces](https://github.com/ybelenko/openapi-data-mocker-interfaces) - package with mocking interfaces.
|
||||
|
||||
## API Endpoints
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io:80/v2*
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
> Important! Do not modify abstract API controllers directly! Instead extend them by implementation classes like:
|
||||
|
||||
@ -131,22 +135,6 @@ For instance, when abstract class located at `./lib/Api/AbstractPetApi.php` you
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*AbstractAnotherFakeApi* | **call123TestSpecialTags** | **PATCH** /another-fake/dummy | To test special tags
|
||||
*AbstractFakeApi* | **createXmlItem** | **POST** /fake/create_xml_item | creates an XmlItem
|
||||
*AbstractFakeApi* | **fakeOuterBooleanSerialize** | **POST** /fake/outer/boolean |
|
||||
*AbstractFakeApi* | **fakeOuterCompositeSerialize** | **POST** /fake/outer/composite |
|
||||
*AbstractFakeApi* | **fakeOuterNumberSerialize** | **POST** /fake/outer/number |
|
||||
*AbstractFakeApi* | **fakeOuterStringSerialize** | **POST** /fake/outer/string |
|
||||
*AbstractFakeApi* | **testBodyWithFileSchema** | **PUT** /fake/body-with-file-schema |
|
||||
*AbstractFakeApi* | **testBodyWithQueryParams** | **PUT** /fake/body-with-query-params |
|
||||
*AbstractFakeApi* | **testClientModel** | **PATCH** /fake | To test \"client\" model
|
||||
*AbstractFakeApi* | **testEndpointParameters** | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
*AbstractFakeApi* | **testEnumParameters** | **GET** /fake | To test enum parameters
|
||||
*AbstractFakeApi* | **testGroupParameters** | **DELETE** /fake | Fake endpoint to test group parameters (optional)
|
||||
*AbstractFakeApi* | **testInlineAdditionalProperties** | **POST** /fake/inline-additionalProperties | test inline additionalProperties
|
||||
*AbstractFakeApi* | **testJsonFormData** | **GET** /fake/jsonFormData | test json serialization of form data
|
||||
*AbstractFakeApi* | **testQueryParameterCollectionFormat** | **PUT** /fake/test-query-paramters |
|
||||
*AbstractFakeClassnameTags123Api* | **testClassname** | **PATCH** /fake_classname_test | To test class name in snake case
|
||||
*AbstractPetApi* | **addPet** | **POST** /pet | Add a new pet to the store
|
||||
*AbstractPetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
|
||||
*AbstractPetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags
|
||||
@ -155,11 +143,10 @@ Class | Method | HTTP request | Description
|
||||
*AbstractPetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID
|
||||
*AbstractPetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
*AbstractPetApi* | **uploadFile** | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
*AbstractPetApi* | **uploadFileWithRequiredFile** | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required)
|
||||
*AbstractStoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status
|
||||
*AbstractStoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet
|
||||
*AbstractStoreApi* | **deleteOrder** | **DELETE** /store/order/{order_id} | Delete purchase order by ID
|
||||
*AbstractStoreApi* | **getOrderById** | **GET** /store/order/{order_id} | Find purchase order by ID
|
||||
*AbstractStoreApi* | **deleteOrder** | **DELETE** /store/order/{orderId} | Delete purchase order by ID
|
||||
*AbstractStoreApi* | **getOrderById** | **GET** /store/order/{orderId} | Find purchase order by ID
|
||||
*AbstractUserApi* | **createUser** | **POST** /user | Create user
|
||||
*AbstractUserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array
|
||||
*AbstractUserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array
|
||||
@ -172,54 +159,14 @@ Class | Method | HTTP request | Description
|
||||
|
||||
## Models
|
||||
|
||||
* OpenAPIServer\Model\AdditionalPropertiesAnyType
|
||||
* OpenAPIServer\Model\AdditionalPropertiesArray
|
||||
* OpenAPIServer\Model\AdditionalPropertiesBoolean
|
||||
* OpenAPIServer\Model\AdditionalPropertiesClass
|
||||
* OpenAPIServer\Model\AdditionalPropertiesInteger
|
||||
* OpenAPIServer\Model\AdditionalPropertiesNumber
|
||||
* OpenAPIServer\Model\AdditionalPropertiesObject
|
||||
* OpenAPIServer\Model\AdditionalPropertiesString
|
||||
* OpenAPIServer\Model\Animal
|
||||
* OpenAPIServer\Model\ApiResponse
|
||||
* OpenAPIServer\Model\ArrayOfArrayOfNumberOnly
|
||||
* OpenAPIServer\Model\ArrayOfNumberOnly
|
||||
* OpenAPIServer\Model\ArrayTest
|
||||
* OpenAPIServer\Model\BigCat
|
||||
* OpenAPIServer\Model\BigCatAllOf
|
||||
* OpenAPIServer\Model\Capitalization
|
||||
* OpenAPIServer\Model\Cat
|
||||
* OpenAPIServer\Model\CatAllOf
|
||||
* OpenAPIServer\Model\Category
|
||||
* OpenAPIServer\Model\ClassModel
|
||||
* OpenAPIServer\Model\Client
|
||||
* OpenAPIServer\Model\Dog
|
||||
* OpenAPIServer\Model\DogAllOf
|
||||
* OpenAPIServer\Model\EnumArrays
|
||||
* OpenAPIServer\Model\EnumClass
|
||||
* OpenAPIServer\Model\EnumTest
|
||||
* OpenAPIServer\Model\File
|
||||
* OpenAPIServer\Model\FileSchemaTestClass
|
||||
* OpenAPIServer\Model\FormatTest
|
||||
* OpenAPIServer\Model\HasOnlyReadOnly
|
||||
* OpenAPIServer\Model\MapTest
|
||||
* OpenAPIServer\Model\MixedPropertiesAndAdditionalPropertiesClass
|
||||
* OpenAPIServer\Model\Model200Response
|
||||
* OpenAPIServer\Model\ModelList
|
||||
* OpenAPIServer\Model\ModelReturn
|
||||
* OpenAPIServer\Model\Name
|
||||
* OpenAPIServer\Model\NumberOnly
|
||||
* OpenAPIServer\Model\InlineObject
|
||||
* OpenAPIServer\Model\InlineObject1
|
||||
* OpenAPIServer\Model\Order
|
||||
* OpenAPIServer\Model\OuterComposite
|
||||
* OpenAPIServer\Model\OuterEnum
|
||||
* OpenAPIServer\Model\Pet
|
||||
* OpenAPIServer\Model\ReadOnlyFirst
|
||||
* OpenAPIServer\Model\SpecialModelName
|
||||
* OpenAPIServer\Model\Tag
|
||||
* OpenAPIServer\Model\TypeHolderDefault
|
||||
* OpenAPIServer\Model\TypeHolderExample
|
||||
* OpenAPIServer\Model\User
|
||||
* OpenAPIServer\Model\XmlItem
|
||||
|
||||
|
||||
## Authentication
|
||||
@ -227,12 +174,6 @@ Class | Method | HTTP request | Description
|
||||
### Security schema `api_key`
|
||||
> Important! To make ApiKey authentication work you need to extend [\OpenAPIServer\Auth\AbstractAuthenticator](./lib/Auth/AbstractAuthenticator.php) class by [\OpenAPIServer\Auth\ApiKeyAuthenticator](./src/Auth/ApiKeyAuthenticator.php) class.
|
||||
|
||||
### Security schema `api_key_query`
|
||||
> Important! To make ApiKey authentication work you need to extend [\OpenAPIServer\Auth\AbstractAuthenticator](./lib/Auth/AbstractAuthenticator.php) class by [\OpenAPIServer\Auth\ApiKeyAuthenticator](./src/Auth/ApiKeyAuthenticator.php) class.
|
||||
|
||||
### Security schema `http_basic_test`
|
||||
> Important! To make Basic authentication work you need to extend [\OpenAPIServer\Auth\AbstractAuthenticator](./lib/Auth/AbstractAuthenticator.php) class by [\OpenAPIServer\Auth\BasicAuthenticator](./src/Auth/BasicAuthenticator.php) class.
|
||||
|
||||
### Security schema `petstore_auth`
|
||||
> Important! To make OAuth authentication work you need to extend [\OpenAPIServer\Auth\AbstractAuthenticator](./lib/Auth/AbstractAuthenticator.php) class by [\OpenAPIServer\Auth\OAuthAuthenticator](./src/Auth/OAuthAuthenticator.php) class.
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
"php": "^7.2",
|
||||
"slim/slim": "^4.5.0",
|
||||
"dyorg/slim-token-authentication": "dev-slim4",
|
||||
"ybelenko/openapi-data-mocker": "^1.0",
|
||||
"ybelenko/openapi-data-mocker-server-middleware": "^1.0",
|
||||
"slim/psr7": "^1.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -1,135 +0,0 @@
|
||||
# php-base - PHP Slim 4 Server library for OpenAPI Petstore
|
||||
|
||||
## Mock Server Documentation
|
||||
|
||||
### Mocker Options
|
||||
To enable mock server uncomment these lines in `index.php` config file:
|
||||
|
||||
```php
|
||||
/**
|
||||
* Mocker Middleware options.
|
||||
*/
|
||||
$config['mockerOptions'] = [
|
||||
'dataMocker' => new OpenApiDataMocker(),
|
||||
|
||||
'getMockResponseCallback' => function (ServerRequestInterface $request, array $responses) {
|
||||
// check if client clearly asks for mocked response
|
||||
if (
|
||||
$request->hasHeader('X-OpenAPIServer-Mock')
|
||||
&& $request->getHeader('X-OpenAPIServer-Mock')[0] === 'ping'
|
||||
) {
|
||||
if (array_key_exists('default', $responses)) {
|
||||
return $responses['default'];
|
||||
}
|
||||
|
||||
// return first response
|
||||
return $responses[array_key_first($responses)];
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
'afterCallback' => function ($request, $response) {
|
||||
// mark mocked response to distinguish real and fake responses
|
||||
return $response->withHeader('X-OpenAPIServer-Mock', 'pong');
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
* `dataMocker` is mocker class instance. To create custom data mocker extend `OpenAPIServer\Mock\OpenApiDataMockerInterface`.
|
||||
* `getMockResponseCallback` is callback before mock data generation. Above example shows how to enable mock feature for only requests with `{{X-OpenAPIServer}}-mock: ping` HTTP header. Adjust requests filtering to fit your project requirements. This function must return single response schema from `$responses` array parameter. **Mock feature is disabled when callback returns anything beside array.**
|
||||
* `afterCallback` is callback executed after mock data generation. Most obvious use case is append specific HTTP headers to distinguish real and fake responses. **This function must always return response instance.**
|
||||
|
||||
### Supported features
|
||||
|
||||
All data types supported except specific string formats: `email`, `uuid`, `password` which are poorly implemented.
|
||||
|
||||
#### Data Types Support
|
||||
|
||||
| Data Type | Data Format | Supported |
|
||||
|:---------:|:-----------:|:------------------:|
|
||||
| `integer` | `int32` | :white_check_mark: |
|
||||
| `integer` | `int64` | :white_check_mark: |
|
||||
| `number` | `float` | :white_check_mark: |
|
||||
| `number` | `double` | |
|
||||
| `string` | `byte` | :white_check_mark: |
|
||||
| `string` | `binary` | :white_check_mark: |
|
||||
| `boolean` | | :white_check_mark: |
|
||||
| `string` | `date` | :white_check_mark: |
|
||||
| `string` | `date-time` | :white_check_mark: |
|
||||
| `string` | `password` | :white_check_mark: |
|
||||
| `string` | `email` | :white_check_mark: |
|
||||
| `string` | `uuid` | :white_check_mark: |
|
||||
|
||||
#### Data Options Support
|
||||
|
||||
| Data Type | Option | Supported |
|
||||
|:-----------:|:----------------------:|:------------------:|
|
||||
| `string` | `minLength` | :white_check_mark: |
|
||||
| `string` | `maxLength` | :white_check_mark: |
|
||||
| `string` | `enum` | :white_check_mark: |
|
||||
| `string` | `pattern` | |
|
||||
| `integer` | `minimum` | :white_check_mark: |
|
||||
| `integer` | `maximum` | :white_check_mark: |
|
||||
| `integer` | `exclusiveMinimum` | :white_check_mark: |
|
||||
| `integer` | `exclusiveMaximum` | :white_check_mark: |
|
||||
| `number` | `minimum` | :white_check_mark: |
|
||||
| `number` | `maximum` | :white_check_mark: |
|
||||
| `number` | `exclusiveMinimum` | :white_check_mark: |
|
||||
| `number` | `exclusiveMaximum` | :white_check_mark: |
|
||||
| `array` | `items` | :white_check_mark: |
|
||||
| `array` | `additionalItems` | |
|
||||
| `array` | `minItems` | :white_check_mark: |
|
||||
| `array` | `maxItems` | :white_check_mark: |
|
||||
| `array` | `uniqueItems` | |
|
||||
| `object` | `properties` | :white_check_mark: |
|
||||
| `object` | `maxProperties` | |
|
||||
| `object` | `minProperties` | |
|
||||
| `object` | `patternProperties` | |
|
||||
| `object` | `additionalProperties` | |
|
||||
| `object` | `required` | |
|
||||
| `*` | `$ref` | :white_check_mark: |
|
||||
| `*` | `allOf` | |
|
||||
| `*` | `anyOf` | |
|
||||
| `*` | `oneOf` | |
|
||||
| `*` | `not` | |
|
||||
|
||||
### Known Limitations
|
||||
|
||||
Avoid circular refs in your schema. Schema below can cause infinite loop and `Out of Memory` PHP error:
|
||||
```yml
|
||||
# ModelA has reference to ModelB while ModelB has reference to ModelA.
|
||||
# Mock server will produce huge nested JSON example and ended with `Out of Memory` error.
|
||||
definitions:
|
||||
ModelA:
|
||||
type: object
|
||||
properties:
|
||||
model_b:
|
||||
$ref: '#/definitions/ModelB'
|
||||
ModelB:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/ModelA'
|
||||
```
|
||||
|
||||
Don't ref scalar types, because generator will not produce models which mock server can find. So schema below will cause error:
|
||||
```yml
|
||||
# generated build contains only `OuterComposite` model class which referenced to not existed `OuterNumber`, `OuterString`, `OuterBoolean` classes
|
||||
# mock server cannot mock `OuterComposite` model and throws exception
|
||||
definitions:
|
||||
OuterComposite:
|
||||
type: object
|
||||
properties:
|
||||
my_number:
|
||||
$ref: '#/definitions/OuterNumber'
|
||||
my_string:
|
||||
$ref: '#/definitions/OuterString'
|
||||
my_boolean:
|
||||
$ref: '#/definitions/OuterBoolean'
|
||||
OuterNumber:
|
||||
type: number
|
||||
OuterString:
|
||||
type: string
|
||||
OuterBoolean:
|
||||
type: boolean
|
||||
```
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -65,21 +65,28 @@ $config['tokenAuthenticationOptions'] = [
|
||||
/**
|
||||
* Mocker Middleware options.
|
||||
*/
|
||||
$mocker = new OpenApiDataMocker();
|
||||
$mocker->setModelsNamespace('OpenAPIServer\Model\\');
|
||||
$config['mockerOptions'] = [
|
||||
// 'dataMocker' => new OpenApiDataMocker(),
|
||||
// 'dataMocker' => $mocker,
|
||||
|
||||
// 'getMockResponseCallback' => function (ServerRequestInterface $request, array $responses) {
|
||||
// 'getMockStatusCodeCallback' => function (ServerRequestInterface $request, $responses) {
|
||||
// // check if client clearly asks for mocked response
|
||||
// $pingHeader = 'X-OpenAPIServer-Mock';
|
||||
// $pingHeaderCode = 'X-OpenAPIServer-Mock-Code';
|
||||
// if (
|
||||
// $request->hasHeader('X-OpenAPIServer-Mock')
|
||||
// && $request->getHeader('X-OpenAPIServer-Mock')[0] === 'ping'
|
||||
// $request->hasHeader($pingHeader)
|
||||
// && $request->getHeader($pingHeader)[0] === 'ping'
|
||||
// ) {
|
||||
// if (array_key_exists('default', $responses)) {
|
||||
// return $responses['default'];
|
||||
// $responses = (array) $responses;
|
||||
// $requestedResponseCode = ($request->hasHeader($pingHeaderCode)) ? $request->getHeader($pingHeaderCode)[0] : 'default';
|
||||
// if (array_key_exists($requestedResponseCode, $responses)) {
|
||||
// return $requestedResponseCode;
|
||||
// }
|
||||
|
||||
// // return first response
|
||||
// return $responses[array_key_first($responses)];
|
||||
// // return first response key
|
||||
// reset($responses);
|
||||
// return key($responses);
|
||||
// }
|
||||
|
||||
// return false;
|
||||
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Exception\HttpNotImplementedException;
|
||||
|
||||
/**
|
||||
* AbstractAnotherFakeApi Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
abstract class AbstractAnotherFakeApi
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ContainerInterface|null Slim app container instance
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Route Controller constructor receives container
|
||||
*
|
||||
* @param ContainerInterface|null $container Slim app container instance
|
||||
*/
|
||||
public function __construct(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PATCH call123TestSpecialTags
|
||||
* Summary: To test special tags
|
||||
* Notes: To test special tags and operation ID starting with number
|
||||
* Output-Formats: [application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function call123TestSpecialTags(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing call123TestSpecialTags as a PATCH method in OpenAPIServer\Api\AnotherFakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
}
|
@ -1,356 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Exception\HttpNotImplementedException;
|
||||
|
||||
/**
|
||||
* AbstractFakeApi Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
abstract class AbstractFakeApi
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ContainerInterface|null Slim app container instance
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Route Controller constructor receives container
|
||||
*
|
||||
* @param ContainerInterface|null $container Slim app container instance
|
||||
*/
|
||||
public function __construct(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST createXmlItem
|
||||
* Summary: creates an XmlItem
|
||||
* Notes: this route creates an XmlItem
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function createXmlItem(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing createXmlItem as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST fakeOuterBooleanSerialize
|
||||
* Notes: Test serialization of outer boolean types
|
||||
* Output-Formats: [*_/_*]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function fakeOuterBooleanSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing fakeOuterBooleanSerialize as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST fakeOuterCompositeSerialize
|
||||
* Notes: Test serialization of object with outer number type
|
||||
* Output-Formats: [*_/_*]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function fakeOuterCompositeSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing fakeOuterCompositeSerialize as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST fakeOuterNumberSerialize
|
||||
* Notes: Test serialization of outer number types
|
||||
* Output-Formats: [*_/_*]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function fakeOuterNumberSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing fakeOuterNumberSerialize as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST fakeOuterStringSerialize
|
||||
* Notes: Test serialization of outer string types
|
||||
* Output-Formats: [*_/_*]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function fakeOuterStringSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing fakeOuterStringSerialize as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT testBodyWithFileSchema
|
||||
* Notes: For this test, the body for this request much reference a schema named `File`.
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testBodyWithFileSchema(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing testBodyWithFileSchema as a PUT method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT testBodyWithQueryParams
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testBodyWithQueryParams(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$queryParams = $request->getQueryParams();
|
||||
$query = (key_exists('query', $queryParams)) ? $queryParams['query'] : null;
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing testBodyWithQueryParams as a PUT method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH testClientModel
|
||||
* Summary: To test \"client\" model
|
||||
* Notes: To test \"client\" model
|
||||
* Output-Formats: [application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testClientModel(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing testClientModel as a PATCH method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST testEndpointParameters
|
||||
* Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
* Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testEndpointParameters(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$integer = (isset($body['integer'])) ? $body['integer'] : null;
|
||||
$int32 = (isset($body['int32'])) ? $body['int32'] : null;
|
||||
$int64 = (isset($body['int64'])) ? $body['int64'] : null;
|
||||
$number = (isset($body['number'])) ? $body['number'] : null;
|
||||
$float = (isset($body['float'])) ? $body['float'] : null;
|
||||
$double = (isset($body['double'])) ? $body['double'] : null;
|
||||
$string = (isset($body['string'])) ? $body['string'] : null;
|
||||
$patternWithoutDelimiter = (isset($body['pattern_without_delimiter'])) ? $body['pattern_without_delimiter'] : null;
|
||||
$byte = (isset($body['byte'])) ? $body['byte'] : null;
|
||||
$binary = (isset($body['binary'])) ? $body['binary'] : null;
|
||||
$date = (isset($body['date'])) ? $body['date'] : null;
|
||||
$dateTime = (isset($body['dateTime'])) ? $body['dateTime'] : null;
|
||||
$password = (isset($body['password'])) ? $body['password'] : null;
|
||||
$callback = (isset($body['callback'])) ? $body['callback'] : null;
|
||||
$message = "How about implementing testEndpointParameters as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET testEnumParameters
|
||||
* Summary: To test enum parameters
|
||||
* Notes: To test enum parameters
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testEnumParameters(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$headers = $request->getHeaders();
|
||||
$enumHeaderStringArray = $request->hasHeader('enum_header_string_array') ? $headers['enum_header_string_array'] : null;
|
||||
$enumHeaderString = $request->hasHeader('enum_header_string') ? $headers['enum_header_string'] : null;
|
||||
$queryParams = $request->getQueryParams();
|
||||
$enumQueryStringArray = (key_exists('enum_query_string_array', $queryParams)) ? $queryParams['enum_query_string_array'] : null;
|
||||
$enumQueryString = (key_exists('enum_query_string', $queryParams)) ? $queryParams['enum_query_string'] : null;
|
||||
$enumQueryInteger = (key_exists('enum_query_integer', $queryParams)) ? $queryParams['enum_query_integer'] : null;
|
||||
$enumQueryDouble = (key_exists('enum_query_double', $queryParams)) ? $queryParams['enum_query_double'] : null;
|
||||
$body = $request->getParsedBody();
|
||||
$enumFormStringArray = (isset($body['enum_form_string_array'])) ? $body['enum_form_string_array'] : null;
|
||||
$enumFormString = (isset($body['enum_form_string'])) ? $body['enum_form_string'] : null;
|
||||
$message = "How about implementing testEnumParameters as a GET method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE testGroupParameters
|
||||
* Summary: Fake endpoint to test group parameters (optional)
|
||||
* Notes: Fake endpoint to test group parameters (optional)
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testGroupParameters(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$headers = $request->getHeaders();
|
||||
$requiredBooleanGroup = $request->hasHeader('required_boolean_group') ? $headers['required_boolean_group'] : null;
|
||||
$booleanGroup = $request->hasHeader('boolean_group') ? $headers['boolean_group'] : null;
|
||||
$queryParams = $request->getQueryParams();
|
||||
$requiredStringGroup = (key_exists('required_string_group', $queryParams)) ? $queryParams['required_string_group'] : null;
|
||||
$requiredInt64Group = (key_exists('required_int64_group', $queryParams)) ? $queryParams['required_int64_group'] : null;
|
||||
$stringGroup = (key_exists('string_group', $queryParams)) ? $queryParams['string_group'] : null;
|
||||
$int64Group = (key_exists('int64_group', $queryParams)) ? $queryParams['int64_group'] : null;
|
||||
$message = "How about implementing testGroupParameters as a DELETE method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST testInlineAdditionalProperties
|
||||
* Summary: test inline additionalProperties
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testInlineAdditionalProperties(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing testInlineAdditionalProperties as a POST method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET testJsonFormData
|
||||
* Summary: test json serialization of form data
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testJsonFormData(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$param = (isset($body['param'])) ? $body['param'] : null;
|
||||
$param2 = (isset($body['param2'])) ? $body['param2'] : null;
|
||||
$message = "How about implementing testJsonFormData as a GET method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT testQueryParameterCollectionFormat
|
||||
* Notes: To test the collection format in query parameters
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testQueryParameterCollectionFormat(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$queryParams = $request->getQueryParams();
|
||||
$pipe = (key_exists('pipe', $queryParams)) ? $queryParams['pipe'] : null;
|
||||
$ioutil = (key_exists('ioutil', $queryParams)) ? $queryParams['ioutil'] : null;
|
||||
$http = (key_exists('http', $queryParams)) ? $queryParams['http'] : null;
|
||||
$url = (key_exists('url', $queryParams)) ? $queryParams['url'] : null;
|
||||
$context = (key_exists('context', $queryParams)) ? $queryParams['context'] : null;
|
||||
$message = "How about implementing testQueryParameterCollectionFormat as a PUT method in OpenAPIServer\Api\FakeApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Exception\HttpNotImplementedException;
|
||||
|
||||
/**
|
||||
* AbstractFakeClassnameTags123Api Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
abstract class AbstractFakeClassnameTags123Api
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ContainerInterface|null Slim app container instance
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Route Controller constructor receives container
|
||||
*
|
||||
* @param ContainerInterface|null $container Slim app container instance
|
||||
*/
|
||||
public function __construct(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PATCH testClassname
|
||||
* Summary: To test class name in snake case
|
||||
* Notes: To test class name in snake case
|
||||
* Output-Formats: [application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function testClassname(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$message = "How about implementing testClassname as a PATCH method in OpenAPIServer\Api\FakeClassnameTags123Api class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -56,6 +56,7 @@ abstract class AbstractPetApi
|
||||
/**
|
||||
* POST addPet
|
||||
* Summary: Add a new pet to the store
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
@ -156,6 +157,7 @@ abstract class AbstractPetApi
|
||||
/**
|
||||
* PUT updatePet
|
||||
* Summary: Update an existing pet
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
@ -213,26 +215,4 @@ abstract class AbstractPetApi
|
||||
$message = "How about implementing uploadFile as a POST method in OpenAPIServer\Api\PetApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST uploadFileWithRequiredFile
|
||||
* Summary: uploads an image (required)
|
||||
* Output-Formats: [application/json]
|
||||
*
|
||||
* @param ServerRequestInterface $request Request
|
||||
* @param ResponseInterface $response Response
|
||||
* @param array|null $args Path arguments
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws HttpNotImplementedException to force implementation class to override this method
|
||||
*/
|
||||
public function uploadFileWithRequiredFile(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$petId = $args['petId'];
|
||||
$body = $request->getParsedBody();
|
||||
$additionalMetadata = (isset($body['additionalMetadata'])) ? $body['additionalMetadata'] : null;
|
||||
$requiredFile = (key_exists('requiredFile', $request->getUploadedFiles())) ? $request->getUploadedFiles()['requiredFile'] : null;
|
||||
$message = "How about implementing uploadFileWithRequiredFile as a POST method in OpenAPIServer\Api\PetApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -67,7 +67,7 @@ abstract class AbstractStoreApi
|
||||
*/
|
||||
public function deleteOrder(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$orderId = $args['order_id'];
|
||||
$orderId = $args['orderId'];
|
||||
$message = "How about implementing deleteOrder as a DELETE method in OpenAPIServer\Api\StoreApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
@ -106,7 +106,7 @@ abstract class AbstractStoreApi
|
||||
*/
|
||||
public function getOrderById(ServerRequestInterface $request, ResponseInterface $response, array $args)
|
||||
{
|
||||
$orderId = $args['order_id'];
|
||||
$orderId = $args['orderId'];
|
||||
$message = "How about implementing getOrderById as a GET method in OpenAPIServer\Api\StoreApi class?";
|
||||
throw new HttpNotImplementedException($request, $message);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
332
samples/server/petstore/php-slim4/lib/BaseModel.php
Normal file
332
samples/server/petstore/php-slim4/lib/BaseModel.php
Normal file
@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OpenAPIServer;
|
||||
|
||||
use OpenAPIServer\Mock\OpenApiModelInterface;
|
||||
use OpenAPIServer\Mock\OpenApiDataMockerInterface as IMocker;
|
||||
use InvalidArgumentException;
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* BaseModel.
|
||||
*/
|
||||
class BaseModel implements OpenApiModelInterface
|
||||
{
|
||||
// phpcs:disable Generic.Commenting.DocComment
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA =
|
||||
<<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties": {}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string[] Valid OAS data types */
|
||||
protected const VALID_OAS_DATA_TYPES = [
|
||||
IMocker::DATA_TYPE_INTEGER,
|
||||
IMocker::DATA_TYPE_NUMBER,
|
||||
IMocker::DATA_TYPE_STRING,
|
||||
IMocker::DATA_TYPE_BOOLEAN,
|
||||
IMocker::DATA_TYPE_ARRAY,
|
||||
IMocker::DATA_TYPE_OBJECT,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var mixed Data container.
|
||||
* PHP has restrictions on variable names, while OAS is much more permissive.
|
||||
* This container helps to store unusual properties like '123_prop' without renaming.
|
||||
*/
|
||||
protected $dataContainer;
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Model constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$schema = static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
$this->validateModelType($modelType, true);
|
||||
|
||||
// set initial data
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
$this->dataContainer = [];
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
default:
|
||||
// scalar type
|
||||
$this->dataContainer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets OAS 3.0 schema mapped to current class.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema(): array
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new instance from provided data.
|
||||
*
|
||||
* @param mixed $data Data with values for new instance.
|
||||
*
|
||||
* @return OpenApiModelInterface
|
||||
*/
|
||||
public static function createFromData($data): OpenApiModelInterface
|
||||
{
|
||||
$instance = new static();
|
||||
$instance->setData($data);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets instance data.
|
||||
*
|
||||
* @param mixed $data Data with values for new instance.
|
||||
*
|
||||
* @throws \InvalidArgumentException When value for array type is invalid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setData($data): void
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
// data for array OAS type should be straight indexed array
|
||||
if (is_array($data)) {
|
||||
$arr = [];
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if (isset($data[$i])) {
|
||||
$arr[$i] = $data[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arr) === count($data)) {
|
||||
$this->dataContainer = $arr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Invalid data for %s model because it accepts straight indexed arrays only', static::class)
|
||||
);
|
||||
break;
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
foreach ($data as $key => $value) {
|
||||
// this action handles __set method
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
default:
|
||||
$this->dataContainer = $data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance data.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
$data = null;
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
// need to convert data container to object
|
||||
$data = new StdClass();
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? $schema['properties'] : null;
|
||||
if (is_array($definedProps) || is_object($definedProps)) {
|
||||
foreach ($definedProps as $propName => $propSchema) {
|
||||
if (array_key_exists($propName, $this->dataContainer)) {
|
||||
$data->{$propName} = $this->dataContainer[$propName];
|
||||
} elseif (array_key_exists('required', $schema) && in_array($propName, $schema['required'])) {
|
||||
// property is required but not set
|
||||
$data->{$propName} = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
default:
|
||||
$data = $this->dataContainer;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to inaccessible (protected or private) or non-existing properties.
|
||||
* Ref @link https://www.php.net/manual/en/language.oop5.overloading.php#object.set
|
||||
*
|
||||
* @param string $param Property name.
|
||||
* @param mixed $value Property value.
|
||||
*
|
||||
* @throws \InvalidArgumentException When property doesn't exist in related OAS schema.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set(string $param, $value): void
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
switch ($modelType) {
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? (array) $schema['properties'] : null;
|
||||
if (is_array($definedProps) && !in_array($param, array_keys($definedProps))) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot set %s property of %s model because it doesn\'t exist in related OAS schema', $param, static::class)
|
||||
);
|
||||
}
|
||||
$this->dataContainer[$param] = $value;
|
||||
break;
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
default:
|
||||
// scalar type and array cannot use property assignation
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot set %s property of %s model because it\'s %s type. Use setData method instead', $param, static::class, $modelType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from inaccessible (protected or private) or non-existing properties.
|
||||
* Ref @link https://www.php.net/manual/en/language.oop5.overloading.php#object.get
|
||||
*
|
||||
* @param string $param Property name.
|
||||
*
|
||||
* @throws \InvalidArgumentException When property doesn't exist in related OAS schema.
|
||||
*
|
||||
* @return mixed Property value
|
||||
*/
|
||||
public function __get(string $param)
|
||||
{
|
||||
$schema = (array) static::getOpenApiSchema();
|
||||
$modelType = (array_key_exists('type', $schema)) ? $schema['type'] : null;
|
||||
$definedProps = (array_key_exists('properties', $schema)) ? (array) $schema['properties'] : null;
|
||||
if (!in_array($modelType, [null, IMocker::DATA_TYPE_OBJECT])) {
|
||||
// scalar type
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot get %s property of %s model because getter is for object OAS type only', $param, static::class)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
is_array($definedProps)
|
||||
&& in_array($param, array_keys($definedProps))
|
||||
) {
|
||||
return $this->dataContainer[$param];
|
||||
} elseif ($definedProps === null) {
|
||||
// props are undefined
|
||||
return (isset($this->dataContainer[$param])) ? $this->dataContainer[$param] : null;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Cannot get %s property of %s model because it doesn\'t exist in related OAS schema', $param, static::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the object to a value that can be serialized natively by json_encode().
|
||||
* Ref @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
*
|
||||
* @return mixed Returns data which can be serialized by json_encode(), which is a value of any type other than a resource.
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if type is valid OAS data type.
|
||||
*
|
||||
* @param string|null $type Model type.
|
||||
* @param bool $throwException Throws InvalidArgumentException when set to true and processed type is invalid.
|
||||
*
|
||||
* @throws \InvalidArgumentException When $throwException set to TRUE.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateModelType(?string $type = null, bool $throwException = true): bool
|
||||
{
|
||||
$isValid = in_array($type, static::VALID_OAS_DATA_TYPES);
|
||||
if ($type !== null && $isValid === false && $throwException) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Invalid OAS schema of %s model, "type" must be one of %s',
|
||||
static::class,
|
||||
implode(', ', static::VALID_OAS_DATA_TYPES)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns models namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getModelsNamespace(): string
|
||||
{
|
||||
return static::MODELS_NAMESPACE . stripslashes('\\');
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Interfaces;
|
||||
|
||||
/**
|
||||
* ModelInterface Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Interfaces
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false);
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
@ -1,621 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Mock;
|
||||
|
||||
use OpenAPIServer\Mock\OpenApiDataMockerInterface as IMocker;
|
||||
use OpenAPIServer\Utils\ModelUtilsTrait;
|
||||
use StdClass;
|
||||
use DateTime;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* OpenApiDataMocker Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Mock
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
final class OpenApiDataMocker implements IMocker
|
||||
{
|
||||
use ModelUtilsTrait;
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data.
|
||||
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types
|
||||
*
|
||||
* @param $dataType string OpenApi data type. Use constants from OpenApiDataMockerInterface class
|
||||
* @param $dataFormat string (optional) OpenApi data format
|
||||
* @param $options array|null (optional) OpenApi data options
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mock($dataType, $dataFormat = null, $options = [])
|
||||
{
|
||||
switch ($dataType) {
|
||||
case IMocker::DATA_TYPE_INTEGER:
|
||||
case IMocker::DATA_TYPE_NUMBER:
|
||||
$minimum = $options['minimum'] ?? null;
|
||||
$maximum = $options['maximum'] ?? null;
|
||||
$exclusiveMinimum = $options['exclusiveMinimum'] ?? false;
|
||||
$exclusiveMaximum = $options['exclusiveMaximum'] ?? false;
|
||||
if ($dataType === IMocker::DATA_TYPE_INTEGER) {
|
||||
return $this->mockInteger($dataFormat, $minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum);
|
||||
}
|
||||
return $this->mockNumber($dataFormat, $minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum);
|
||||
case IMocker::DATA_TYPE_STRING:
|
||||
$minLength = $options['minLength'] ?? 0;
|
||||
$maxLength = $options['maxLength'] ?? null;
|
||||
$enum = $options['enum'] ?? null;
|
||||
return $this->mockString($dataFormat, $minLength, $maxLength, $enum);
|
||||
case IMocker::DATA_TYPE_BOOLEAN:
|
||||
return $this->mockBoolean();
|
||||
case IMocker::DATA_TYPE_ARRAY:
|
||||
$items = $options['items'] ?? null;
|
||||
$minItems = $options['minItems'] ?? 0;
|
||||
$maxItems = $options['maxItems'] ?? null;
|
||||
$uniqueItems = $options['uniqueItems'] ?? false;
|
||||
return $this->mockArray($items, $minItems, $maxItems, $uniqueItems);
|
||||
case IMocker::DATA_TYPE_OBJECT:
|
||||
$properties = $options['properties'] ?? null;
|
||||
$minProperties = $options['minProperties'] ?? 0;
|
||||
$maxProperties = $options['maxProperties'] ?? null;
|
||||
$additionalProperties = $options['additionalProperties'] ?? null;
|
||||
$required = $options['required'] ?? null;
|
||||
return $this->mockObject($properties, $minProperties, $maxProperties, $additionalProperties, $required);
|
||||
default:
|
||||
throw new InvalidArgumentException('"dataType" must be one of ' . implode(', ', [
|
||||
IMocker::DATA_TYPE_INTEGER,
|
||||
IMocker::DATA_TYPE_NUMBER,
|
||||
IMocker::DATA_TYPE_STRING,
|
||||
IMocker::DATA_TYPE_BOOLEAN,
|
||||
IMocker::DATA_TYPE_ARRAY,
|
||||
IMocker::DATA_TYPE_OBJECT,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock integer type
|
||||
* Equivalent to mockData(DATA_TYPE_INTEGER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) int32 or int64
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function mockInteger(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
) {
|
||||
$dataFormat = is_string($dataFormat) ? strtolower($dataFormat) : $dataFormat;
|
||||
switch ($dataFormat) {
|
||||
case IMocker::DATA_FORMAT_INT32:
|
||||
// -2147483647..2147483647
|
||||
$minimum = is_numeric($minimum) ? max($minimum, -2147483647) : -2147483647;
|
||||
$maximum = is_numeric($maximum) ? min($maximum, 2147483647) : 2147483647;
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_INT64:
|
||||
// -9223372036854775807..9223372036854775807
|
||||
$minimum = is_numeric($minimum) ? max($minimum, -9223372036854775807) : -9223372036854775807;
|
||||
$maximum = is_numeric($maximum) ? min($maximum, 9223372036854775807) : 9223372036854775807;
|
||||
break;
|
||||
default:
|
||||
// do nothing, unsupported format
|
||||
}
|
||||
|
||||
return $this->getRandomNumber($minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock number type
|
||||
* Equivalent to mockData(DATA_TYPE_NUMBER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) float or double
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function mockNumber(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
) {
|
||||
return $this->getRandomNumber($minimum, $maximum, $exclusiveMinimum, $exclusiveMaximum, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock string type
|
||||
* Equivalent to mockData(DATA_TYPE_STRING);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) one of byte, binary, date, date-time, password
|
||||
* @param int|null $minLength (optional) Default is 0
|
||||
* @param int|null $maxLength (optional) Default is 100 chars
|
||||
* @param array $enum (optional) This array should have at least one element.
|
||||
* Elements in the array should be unique.
|
||||
* @param string|null $pattern (optional) This string should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
||||
* Recall: regular expressions are not implicitly anchored.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mockString(
|
||||
$dataFormat = null,
|
||||
$minLength = 0,
|
||||
$maxLength = null,
|
||||
$enum = null,
|
||||
$pattern = null
|
||||
) {
|
||||
$str = '';
|
||||
$getLoremIpsum = function ($length) {
|
||||
return str_pad(
|
||||
'',
|
||||
$length,
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
|
||||
\STR_PAD_RIGHT
|
||||
);
|
||||
};
|
||||
$truncateOrPad = function ($text, $min = null, $max = null, $glue = '') {
|
||||
if ($max !== null && mb_strlen($text) > $max) {
|
||||
// truncate
|
||||
$text = substr($text, 0, $max);
|
||||
} elseif ($min !== null && mb_strlen($text) < $min) {
|
||||
// pad
|
||||
$text = str_pad('', $min, $text . $glue, \STR_PAD_RIGHT);
|
||||
}
|
||||
return $text;
|
||||
};
|
||||
|
||||
if ($enum !== null) {
|
||||
if (
|
||||
is_array($enum) === false
|
||||
|| empty($enum)
|
||||
|| count($enum) > count(array_unique($enum))
|
||||
) {
|
||||
throw new InvalidArgumentException('"enum" must be an array. This array should have at least one element. Elements in the array should be unique.');
|
||||
}
|
||||
|
||||
// return random variant
|
||||
return $enum[mt_rand(0, count($enum) - 1)];
|
||||
}
|
||||
|
||||
if ($minLength !== 0 && $minLength !== null) {
|
||||
if (is_int($minLength) === false) {
|
||||
throw new InvalidArgumentException('"minLength" must be an integer');
|
||||
} elseif ($minLength < 0) {
|
||||
throw new InvalidArgumentException('"minLength" must be greater than, or equal to, 0');
|
||||
}
|
||||
} else {
|
||||
$minLength = 0;
|
||||
}
|
||||
|
||||
if ($maxLength !== null) {
|
||||
if (is_int($maxLength) === false) {
|
||||
throw new InvalidArgumentException('"maxLength" must be an integer');
|
||||
} elseif ($maxLength < 0) {
|
||||
throw new InvalidArgumentException('"maxLength" must be greater than, or equal to, 0');
|
||||
}
|
||||
} else {
|
||||
// since we don't need huge texts by default, lets cut them down to 100 chars
|
||||
$maxLength = 100;
|
||||
}
|
||||
|
||||
if ($maxLength < $minLength) {
|
||||
throw new InvalidArgumentException('"maxLength" value cannot be less than "minLength"');
|
||||
}
|
||||
|
||||
switch ($dataFormat) {
|
||||
case IMocker::DATA_FORMAT_BYTE:
|
||||
case IMocker::DATA_FORMAT_BINARY:
|
||||
// base64 encoded string
|
||||
$inputLength = 1;
|
||||
$str = base64_encode($getLoremIpsum($inputLength));
|
||||
while (mb_strlen($str) < $minLength) {
|
||||
$inputLength++;
|
||||
$str = base64_encode($getLoremIpsum($inputLength));
|
||||
}
|
||||
|
||||
// base64 encoding produces strings devided by 4, so resulted string can exceed maxLength parameter
|
||||
// I think truncated(invalid) base64 string is better than oversized, cause this data is fake anyway
|
||||
$str = $truncateOrPad($str, null, $maxLength, '. ');
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_DATE:
|
||||
case IMocker::DATA_FORMAT_DATE_TIME:
|
||||
// min unix timestamp is 0 and max is 2147483647 for 32bit systems which equals 2038-01-19 03:14:07
|
||||
$date = DateTime::createFromFormat('U', mt_rand(0, 2147483647));
|
||||
$str = ($dataFormat === IMocker::DATA_FORMAT_DATE) ? $date->format('Y-m-d') : $date->format('Y-m-d\TH:i:sP');
|
||||
|
||||
// truncate or pad datestring to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength, ' ');
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_PASSWORD:
|
||||
// use list of most popular passwords
|
||||
$obviousPassList = [
|
||||
'qwerty',
|
||||
'qwerty12345',
|
||||
'hello',
|
||||
'12345',
|
||||
'0000',
|
||||
'qwerty12345!',
|
||||
'qwertyuiop[]',
|
||||
];
|
||||
$str = $obviousPassList[mt_rand(0, count($obviousPassList) - 1)];
|
||||
|
||||
// truncate or pad password to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_UUID:
|
||||
// use php built-in uniqid function
|
||||
$str = uniqid();
|
||||
|
||||
// truncate or pad password to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
case IMocker::DATA_FORMAT_EMAIL:
|
||||
// just for visionary purpose, not related to real persons
|
||||
$fakeEmailList = [
|
||||
'johndoe',
|
||||
'lhoswald',
|
||||
'ojsimpson',
|
||||
'mlking',
|
||||
'jfkennedy',
|
||||
];
|
||||
$str = $fakeEmailList[mt_rand(0, count($fakeEmailList) - 1)] . '@example.com';
|
||||
|
||||
// truncate or pad email to fit minLength and maxLength
|
||||
$str = $truncateOrPad($str, $minLength, $maxLength);
|
||||
break;
|
||||
default:
|
||||
$str = $getLoremIpsum(mt_rand($minLength, $maxLength));
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock boolean type
|
||||
* Equivalent to mockData(DATA_TYPE_BOOLEAN);
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mockBoolean()
|
||||
{
|
||||
return (bool) mt_rand(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock array type
|
||||
* Equivalent to mockData(DATA_TYPE_ARRAY);
|
||||
*
|
||||
* @param object|array $items Object or assoc array of described items
|
||||
* @param int|null $minItems (optional) An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxItems (optional) An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword
|
||||
* @param bool|null $uniqueItems (optional) If it has boolean value true, the instance validates successfully if all of its elements are unique
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mockArray(
|
||||
$items,
|
||||
$minItems = 0,
|
||||
$maxItems = null,
|
||||
$uniqueItems = false
|
||||
) {
|
||||
$arr = [];
|
||||
$minSize = 0;
|
||||
$maxSize = \PHP_INT_MAX;
|
||||
|
||||
if (
|
||||
(is_array($items) === false && is_object($items) === false)
|
||||
|| (is_array($items) && array_key_exists('type', $items) === false)
|
||||
|| (is_object($items) && isset($items->type) === false)
|
||||
) {
|
||||
new InvalidArgumentException('"items" must be object or assoc array with "type" key');
|
||||
}
|
||||
|
||||
if ($minItems !== null) {
|
||||
if (is_integer($minItems) === false || $minItems < 0) {
|
||||
throw new InvalidArgumentException('"mitItems" must be an integer. This integer must be greater than, or equal to, 0');
|
||||
}
|
||||
$minSize = $minItems;
|
||||
}
|
||||
|
||||
if ($maxItems !== null) {
|
||||
if (is_integer($maxItems) === false || $maxItems < 0) {
|
||||
throw new InvalidArgumentException('"maxItems" must be an integer. This integer must be greater than, or equal to, 0.');
|
||||
}
|
||||
if ($maxItems < $minItems) {
|
||||
throw new InvalidArgumentException('"maxItems" value cannot be less than "minItems"');
|
||||
}
|
||||
$maxSize = $maxItems;
|
||||
}
|
||||
|
||||
$options = $this->extractSchemaProperties($items);
|
||||
$dataType = $options['type'];
|
||||
$dataFormat = $options['format'] ?? null;
|
||||
$ref = $options['$ref'] ?? null;
|
||||
|
||||
// always generate smallest possible array to avoid huge JSON responses
|
||||
$arrSize = ($maxSize < 1) ? $maxSize : max($minSize, 1);
|
||||
while (count($arr) < $arrSize) {
|
||||
$data = $this->mockFromRef($ref);
|
||||
$arr[] = ($data) ? $data : $this->mock($dataType, $dataFormat, $options);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to mock object type.
|
||||
* Equivalent to mockData(DATA_TYPE_OBJECT);
|
||||
*
|
||||
* @param object|array $properties Object or array of described properties
|
||||
* @param int|null $minProperties (optional) An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxProperties (optional) An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
||||
* @param bool|object|array|null $additionalProperties (optional) If "additionalProperties" is true, validation always succeeds.
|
||||
* If "additionalProperties" is false, validation succeeds only if the instance is an object and all properties on the instance were covered by "properties" and/or "patternProperties".
|
||||
* If "additionalProperties" is an object, validate the value as a schema to all of the properties that weren't validated by "properties" nor "patternProperties".
|
||||
* @param array|null $required (optional) This array MUST have at least one element. Elements of this array must be strings, and MUST be unique.
|
||||
* An object instance is valid if its property set contains all elements in this array value.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function mockObject(
|
||||
$properties,
|
||||
$minProperties = 0,
|
||||
$maxProperties = null,
|
||||
$additionalProperties = null,
|
||||
$required = null
|
||||
) {
|
||||
$obj = new StdClass();
|
||||
|
||||
if (is_object($properties) === false && is_array($properties) === false) {
|
||||
throw new InvalidArgumentException('The value of "properties" must be an array or object');
|
||||
}
|
||||
|
||||
foreach ($properties as $propName => $propValue) {
|
||||
if (is_object($propValue) === false && is_array($propValue) === false) {
|
||||
throw new InvalidArgumentException('Each value of "properties" must be an array or object');
|
||||
}
|
||||
}
|
||||
|
||||
if ($minProperties !== null) {
|
||||
if (is_integer($minProperties) === false || $minProperties < 0) {
|
||||
throw new InvalidArgumentException('"minProperties" must be an integer. This integer must be greater than, or equal to, 0');
|
||||
}
|
||||
}
|
||||
|
||||
if ($maxProperties !== null) {
|
||||
if (is_integer($maxProperties) === false || $maxProperties < 0) {
|
||||
throw new InvalidArgumentException('"maxProperties" must be an integer. This integer must be greater than, or equal to, 0.');
|
||||
}
|
||||
if ($maxProperties < $minProperties) {
|
||||
throw new InvalidArgumentException('"maxProperties" value cannot be less than "minProperties"');
|
||||
}
|
||||
}
|
||||
|
||||
if ($additionalProperties !== null) {
|
||||
if (is_bool($additionalProperties) === false && is_object($additionalProperties) === false && is_array($additionalProperties) === false) {
|
||||
throw new InvalidArgumentException('The value of "additionalProperties" must be a boolean or object or array.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($required !== null) {
|
||||
if (
|
||||
is_array($required) === false
|
||||
|| count($required) > count(array_unique($required))
|
||||
) {
|
||||
throw new InvalidArgumentException('The value of "required" must be an array. Elements of this array must be unique.');
|
||||
}
|
||||
foreach ($required as $requiredPropName) {
|
||||
if (is_string($requiredPropName) === false) {
|
||||
throw new InvalidArgumentException('Elements of "required" array must be strings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($properties as $propName => $propValue) {
|
||||
$options = $this->extractSchemaProperties($propValue);
|
||||
$dataType = $options['type'];
|
||||
$dataFormat = $options['format'] ?? null;
|
||||
$ref = $options['$ref'] ?? null;
|
||||
$data = $this->mockFromRef($ref);
|
||||
$obj->$propName = ($data) ? $data : $this->mock($dataType, $dataFormat, $options);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data from schema.
|
||||
*
|
||||
* @param array|object $schema OpenAPI schema
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromSchema($schema)
|
||||
{
|
||||
$props = $this->extractSchemaProperties($schema);
|
||||
if (array_key_exists('$ref', $props) && !empty($props['$ref'])) {
|
||||
return $this->mockFromRef($props['$ref']);
|
||||
} elseif ($props['type'] === null) {
|
||||
throw new InvalidArgumentException('"schema" must be object or assoc array with "type" property');
|
||||
}
|
||||
return $this->mock($props['type'], $props['format'], $props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock data by referenced schema.
|
||||
* TODO: this method will return model instance, not an StdClass
|
||||
*
|
||||
* @param string|null $ref Ref to model, eg. #/components/schemas/User
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromRef($ref)
|
||||
{
|
||||
$data = null;
|
||||
if (is_string($ref) && !empty($ref)) {
|
||||
$refName = static::getSimpleRef($ref);
|
||||
$modelName = static::toModelName($refName);
|
||||
$modelClass = 'OpenAPIServer\Model\\' . $modelName;
|
||||
if (!class_exists($modelClass) || !method_exists($modelClass, 'getOpenApiSchema')) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'Model %s not found or method %s doesn\'t exist',
|
||||
$modelClass,
|
||||
$modelClass . '::getOpenApiSchema'
|
||||
));
|
||||
}
|
||||
$data = $this->mockFromSchema($modelClass::getOpenApiSchema(true));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Extract OAS properties from array or object.
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param array|object $val Processed array or object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractSchemaProperties($val)
|
||||
{
|
||||
$props = [
|
||||
'type' => null,
|
||||
'format' => null,
|
||||
];
|
||||
foreach (
|
||||
[
|
||||
'type',
|
||||
'format',
|
||||
'minimum',
|
||||
'maximum',
|
||||
'exclusiveMinimum',
|
||||
'exclusiveMaximum',
|
||||
'minLength',
|
||||
'maxLength',
|
||||
'pattern',
|
||||
'enum',
|
||||
'items',
|
||||
'minItems',
|
||||
'maxItems',
|
||||
'uniqueItems',
|
||||
'properties',
|
||||
'minProperties',
|
||||
'maxProperties',
|
||||
'additionalProperties',
|
||||
'required',
|
||||
'example',
|
||||
'$ref',
|
||||
] as $propName
|
||||
) {
|
||||
if (is_array($val) && array_key_exists($propName, $val)) {
|
||||
$props[$propName] = $val[$propName];
|
||||
} elseif (is_object($val) && isset($val->$propName)) {
|
||||
$props[$propName] = $val->$propName;
|
||||
}
|
||||
}
|
||||
return $props;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
protected function getRandomNumber(
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false,
|
||||
$maxDecimals = 4
|
||||
) {
|
||||
$min = 0;
|
||||
$max = mt_getrandmax();
|
||||
|
||||
if ($minimum !== null) {
|
||||
if (is_numeric($minimum) === false) {
|
||||
throw new InvalidArgumentException('"minimum" must be a number');
|
||||
}
|
||||
$min = $minimum;
|
||||
}
|
||||
|
||||
if ($maximum !== null) {
|
||||
if (is_numeric($maximum) === false) {
|
||||
throw new InvalidArgumentException('"maximum" must be a number');
|
||||
}
|
||||
$max = $maximum;
|
||||
}
|
||||
|
||||
if ($exclusiveMinimum !== false) {
|
||||
if (is_bool($exclusiveMinimum) === false) {
|
||||
throw new InvalidArgumentException('"exclusiveMinimum" must be a boolean');
|
||||
} elseif ($minimum === null) {
|
||||
throw new InvalidArgumentException('If "exclusiveMinimum" is present, "minimum" must also be present');
|
||||
}
|
||||
$min += 1;
|
||||
}
|
||||
|
||||
if ($exclusiveMaximum !== false) {
|
||||
if (is_bool($exclusiveMaximum) === false) {
|
||||
throw new InvalidArgumentException('"exclusiveMaximum" must be a boolean');
|
||||
} elseif ($maximum === null) {
|
||||
throw new InvalidArgumentException('If "exclusiveMaximum" is present, "maximum" must also be present');
|
||||
}
|
||||
$max -= 1;
|
||||
}
|
||||
|
||||
if ($max < $min) {
|
||||
throw new InvalidArgumentException('"maximum" value cannot be less than "minimum"');
|
||||
}
|
||||
|
||||
if ($maxDecimals > 0) {
|
||||
return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $maxDecimals);
|
||||
}
|
||||
return mt_rand((int) $min, (int) $max);
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Mock;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* OpenApiDataMockerInterface Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Mock
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
interface OpenApiDataMockerInterface
|
||||
{
|
||||
/** @var string DATA_TYPE_INTEGER */
|
||||
public const DATA_TYPE_INTEGER = 'integer';
|
||||
|
||||
/** @var string DATA_TYPE_NUMBER */
|
||||
public const DATA_TYPE_NUMBER = 'number';
|
||||
|
||||
/** @var string DATA_TYPE_STRING */
|
||||
public const DATA_TYPE_STRING = 'string';
|
||||
|
||||
/** @var string DATA_TYPE_BOOLEAN */
|
||||
public const DATA_TYPE_BOOLEAN = 'boolean';
|
||||
|
||||
/** @var string DATA_TYPE_FILE */
|
||||
public const DATA_TYPE_FILE = 'file';
|
||||
|
||||
/** @var string DATA_TYPE_ARRAY */
|
||||
public const DATA_TYPE_ARRAY = 'array';
|
||||
|
||||
/** @var string DATA_TYPE_OBJECT */
|
||||
public const DATA_TYPE_OBJECT = 'object';
|
||||
|
||||
/** @var string DATA_FORMAT_INT32 Signed 32 bits */
|
||||
public const DATA_FORMAT_INT32 = 'int32';
|
||||
|
||||
/** @var string DATA_FORMAT_INT64 Signed 64 bits */
|
||||
public const DATA_FORMAT_INT64 = 'int64';
|
||||
|
||||
/** @var string DATA_FORMAT_FLOAT */
|
||||
public const DATA_FORMAT_FLOAT = 'float';
|
||||
|
||||
/** @var string DATA_FORMAT_DOUBLE */
|
||||
public const DATA_FORMAT_DOUBLE = 'double';
|
||||
|
||||
/** @var string DATA_FORMAT_BYTE base64 encoded characters */
|
||||
public const DATA_FORMAT_BYTE = 'byte';
|
||||
|
||||
/** @var string DATA_FORMAT_BINARY Any sequence of octets */
|
||||
public const DATA_FORMAT_BINARY = 'binary';
|
||||
|
||||
/** @var string DATA_FORMAT_DATE As defined by full-date [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14) */
|
||||
public const DATA_FORMAT_DATE = 'date';
|
||||
|
||||
/** @var string DATA_FORMAT_DATE_TIME As defined by date-time [RFC3339](http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14) */
|
||||
public const DATA_FORMAT_DATE_TIME = 'date-time';
|
||||
|
||||
/** @var string DATA_FORMAT_PASSWORD Used to hint UIs the input needs to be obscured. */
|
||||
public const DATA_FORMAT_PASSWORD = 'password';
|
||||
|
||||
/** @var string DATA_FORMAT_EMAIL */
|
||||
public const DATA_FORMAT_EMAIL = 'email';
|
||||
|
||||
/** @var string DATA_FORMAT_UUID */
|
||||
public const DATA_FORMAT_UUID = 'uuid';
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data.
|
||||
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types
|
||||
*
|
||||
* @param $dataType string OpenApi data type. Use constants from this class
|
||||
* @param $dataFormat string (optional) OpenApi data format
|
||||
* @param $options array|null (optional) OpenApi data options
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mock(
|
||||
$dataType,
|
||||
$dataFormat = null,
|
||||
$options = []
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock integer type
|
||||
* Equivalent to mockData(DATA_TYPE_INTEGER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) int32 or int64
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function mockInteger(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock number type
|
||||
* Equivalent to mockData(DATA_TYPE_NUMBER);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) float or double
|
||||
* @param number|null $minimum (optional) Default is 0
|
||||
* @param number|null $maximum (optional) Default is mt_getrandmax()
|
||||
* @param bool|null $exclusiveMinimum (optional) Default is false
|
||||
* @param bool|null $exclusiveMaximum (optional) Default is false
|
||||
*
|
||||
* @throws \InvalidArgumentException when $maximum less than $minimum or invalid arguments provided
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function mockNumber(
|
||||
$dataFormat = null,
|
||||
$minimum = null,
|
||||
$maximum = null,
|
||||
$exclusiveMinimum = false,
|
||||
$exclusiveMaximum = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock string type
|
||||
* Equivalent to mockData(DATA_TYPE_STRING);
|
||||
*
|
||||
* @param string|null $dataFormat (optional) one of byte, binary, date, date-time, password
|
||||
* @param int|null $minLength (optional) Default is 0
|
||||
* @param int|null $maxLength (optional) Default is 100 chars
|
||||
* @param array $enum (optional) This array should have at least one element.
|
||||
* Elements in the array should be unique.
|
||||
* @param string|null $pattern (optional) This string should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
||||
* Recall: regular expressions are not implicitly anchored.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mockString(
|
||||
$dataFormat = null,
|
||||
$minLength = 0,
|
||||
$maxLength = null,
|
||||
$enum = null,
|
||||
$pattern = null
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock boolean type
|
||||
* Equivalent to mockData(DATA_TYPE_BOOLEAN);
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mockBoolean();
|
||||
|
||||
/**
|
||||
* Shortcut to mock array type
|
||||
* Equivalent to mockData(DATA_TYPE_ARRAY);
|
||||
*
|
||||
* @param object|array $items Object or assoc array of described items
|
||||
* @param int|null $minItems (optional) An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxItems (optional) An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword
|
||||
* @param bool|null $uniqueItems (optional) If it has boolean value true, the instance validates successfully if all of its elements are unique
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mockArray(
|
||||
$items,
|
||||
$minItems = 0,
|
||||
$maxItems = null,
|
||||
$uniqueItems = false
|
||||
);
|
||||
|
||||
/**
|
||||
* Shortcut to mock object type.
|
||||
* Equivalent to mockData(DATA_TYPE_OBJECT);
|
||||
*
|
||||
* @param object|array $properties Object or array of described properties
|
||||
* @param int|null $minProperties (optional) An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.
|
||||
* @param int|null $maxProperties (optional) An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
||||
* @param bool|object|array|null $additionalProperties (optional) If "additionalProperties" is true, validation always succeeds.
|
||||
* If "additionalProperties" is false, validation succeeds only if the instance is an object and all properties on the instance were covered by "properties" and/or "patternProperties".
|
||||
* If "additionalProperties" is an object, validate the value as a schema to all of the properties that weren't validated by "properties" nor "patternProperties".
|
||||
* @param array|null $required (optional) This array MUST have at least one element. Elements of this array must be strings, and MUST be unique.
|
||||
* An object instance is valid if its property set contains all elements in this array value.
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function mockObject(
|
||||
$properties,
|
||||
$minProperties = 0,
|
||||
$maxProperties = null,
|
||||
$additionalProperties = null,
|
||||
$required = null
|
||||
);
|
||||
|
||||
/**
|
||||
* Mocks OpenApi Data from schema.
|
||||
*
|
||||
* @param array|object $schema OpenAPI schema
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromSchema($schema);
|
||||
|
||||
/**
|
||||
* Mock data by referenced schema.
|
||||
* TODO: this method will return model instance, not an StdClass
|
||||
*
|
||||
* @param string|null $ref Ref to model, eg. #/components/schemas/User
|
||||
*
|
||||
* @throws \InvalidArgumentException when invalid arguments passed
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function mockFromRef($ref);
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Mock;
|
||||
|
||||
use Slim\Factory\AppFactory;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use OpenAPIServer\Mock\OpenApiDataMockerInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* OpenApiDataMockerMiddleware Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Mock
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
final class OpenApiDataMockerMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @var OpenApiDataMockerInterface DataMocker.
|
||||
*/
|
||||
private $mocker;
|
||||
|
||||
/**
|
||||
* @var array Array of responses schemas.
|
||||
*/
|
||||
private $responses;
|
||||
|
||||
/**
|
||||
* @var callable|null Custom callback to select mocked response.
|
||||
*/
|
||||
private $getMockResponseCallback;
|
||||
|
||||
/**
|
||||
* @var callable|null Custom after callback.
|
||||
*/
|
||||
private $afterCallback;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param OpenApiDataMockerInterface $mocker DataMocker.
|
||||
* @param array $responses Array of responses schemas.
|
||||
* @param callable|null $getMockResponseCallback Custom callback to select mocked response.
|
||||
* Mock feature is disabled when this argument is null.
|
||||
* @example $getMockResponseCallback = function (ServerRequestInterface $request, array $responses) {
|
||||
* // check if client clearly asks for mocked response
|
||||
* if (
|
||||
* $request->hasHeader('X-OpenAPIServer-Mock')
|
||||
* && $request->header('X-OpenAPIServer-Mock')[0] === 'ping'
|
||||
* ) {
|
||||
* return $responses[array_key_first($responses)];
|
||||
* }
|
||||
* return false;
|
||||
* };
|
||||
* @param callable|null $afterCallback After callback.
|
||||
* Function must return response instance.
|
||||
* @example $afterCallback = function (ServerRequestInterface $request, ResponseInterface $response) {
|
||||
* // mark mocked response to distinguish real and fake responses
|
||||
* return $response->withHeader('X-OpenAPIServer-Mock', 'pong');
|
||||
* };
|
||||
*/
|
||||
public function __construct(
|
||||
OpenApiDataMockerInterface $mocker,
|
||||
array $responses,
|
||||
$getMockResponseCallback = null,
|
||||
$afterCallback = null
|
||||
) {
|
||||
$this->mocker = $mocker;
|
||||
$this->responses = $responses;
|
||||
if (is_callable($getMockResponseCallback)) {
|
||||
$this->getMockResponseCallback = $getMockResponseCallback;
|
||||
} elseif ($getMockResponseCallback !== null) {
|
||||
// wrong argument type
|
||||
throw new InvalidArgumentException('\$getMockResponseCallback must be closure or null');
|
||||
}
|
||||
|
||||
if (is_callable($afterCallback)) {
|
||||
$this->afterCallback = $afterCallback;
|
||||
} elseif ($afterCallback !== null) {
|
||||
// wrong argument type
|
||||
throw new InvalidArgumentException('\$afterCallback must be closure or null');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse incoming JSON input into a native PHP format
|
||||
*
|
||||
* @param ServerRequestInterface $request HTTP request
|
||||
* @param RequestHandlerInterface $handler Request handler
|
||||
*
|
||||
* @return ResponseInterface HTTP response
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$customCallback = $this->getMockResponseCallback;
|
||||
$customAfterCallback = $this->afterCallback;
|
||||
$mockedResponse = (is_callable($customCallback)) ? $customCallback($request, $this->responses) : null;
|
||||
if (
|
||||
is_array($mockedResponse)
|
||||
&& array_key_exists('code', $mockedResponse)
|
||||
&& array_key_exists('jsonSchema', $mockedResponse)
|
||||
) {
|
||||
// response schema succesfully selected, we can mock it now
|
||||
$statusCode = ($mockedResponse['code'] === 0) ? 200 : $mockedResponse['code'];
|
||||
$contentType = '*/*';
|
||||
$response = AppFactory::determineResponseFactory()->createResponse($statusCode);
|
||||
$responseSchema = json_decode($mockedResponse['jsonSchema'], true);
|
||||
|
||||
if (is_array($responseSchema) && array_key_exists('headers', $responseSchema)) {
|
||||
// response schema contains headers definitions, apply them one by one
|
||||
foreach ($responseSchema['headers'] as $headerName => $headerDefinition) {
|
||||
$response = $response->withHeader($headerName, $this->mocker->mockFromSchema($headerDefinition['schema']));
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
is_array($responseSchema)
|
||||
&& array_key_exists('content', $responseSchema)
|
||||
&& !empty($responseSchema['content'])
|
||||
) {
|
||||
// response schema contains body definition
|
||||
$responseContentSchema = null;
|
||||
foreach ($responseSchema['content'] as $schemaContentType => $schemaDefinition) {
|
||||
// we can respond in JSON format when any(*/*) content-type allowed
|
||||
// or JSON(application/json) content-type specifically defined
|
||||
if (
|
||||
$schemaContentType === '*/*'
|
||||
|| strtolower(substr($schemaContentType, 0, 16)) === 'application/json'
|
||||
) {
|
||||
$contentType = 'application/json';
|
||||
$responseContentSchema = $schemaDefinition['schema'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($contentType === 'application/json') {
|
||||
$responseBody = $this->mocker->mockFromSchema($responseContentSchema);
|
||||
$response->getBody()->write(json_encode($responseBody));
|
||||
} else {
|
||||
// notify developer that only application/json response supported so far
|
||||
$response->getBody()->write('Mock feature supports only "application/json" content-type!');
|
||||
}
|
||||
}
|
||||
|
||||
// after callback applied only when mocked response schema has been selected
|
||||
if (is_callable($customAfterCallback)) {
|
||||
$response = $customAfterCallback($request, $response);
|
||||
}
|
||||
|
||||
// no reason to execute following middlewares (auth, validation etc.)
|
||||
// return mocked response and end connection
|
||||
return $response
|
||||
->withHeader('Content-Type', $contentType);
|
||||
}
|
||||
|
||||
// no response selected, mock feature disabled
|
||||
// execute following middlewares
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesAnyType
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesAnyType implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesArray
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesArray implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesBoolean
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesBoolean implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesClass
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesClass implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"map_string" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"map_number" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "number"
|
||||
}
|
||||
},
|
||||
"map_integer" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
},
|
||||
"map_boolean" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
},
|
||||
"map_array_integer" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"map_array_anytype" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
},
|
||||
"map_map_string" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"map_map_anytype" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
},
|
||||
"anytype_1" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
},
|
||||
"anytype_2" : {
|
||||
"type" : "object"
|
||||
},
|
||||
"anytype_3" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var map[string,string] $mapString */
|
||||
private $mapString;
|
||||
|
||||
/** @var map[string,float] $mapNumber */
|
||||
private $mapNumber;
|
||||
|
||||
/** @var map[string,int] $mapInteger */
|
||||
private $mapInteger;
|
||||
|
||||
/** @var map[string,bool] $mapBoolean */
|
||||
private $mapBoolean;
|
||||
|
||||
/** @var map[string,int[]] $mapArrayInteger */
|
||||
private $mapArrayInteger;
|
||||
|
||||
/** @var map[string,object[]] $mapArrayAnytype */
|
||||
private $mapArrayAnytype;
|
||||
|
||||
/** @var map[string,map[string,string]] $mapMapString */
|
||||
private $mapMapString;
|
||||
|
||||
/** @var map[string,map[string,object]] $mapMapAnytype */
|
||||
private $mapMapAnytype;
|
||||
|
||||
/** @var object $anytype1 */
|
||||
private $anytype1;
|
||||
|
||||
/** @var object $anytype2 */
|
||||
private $anytype2;
|
||||
|
||||
/** @var object $anytype3 */
|
||||
private $anytype3;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesInteger
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesInteger implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesNumber
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesNumber implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "number"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesObject
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesObject implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"properties" : { }
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* AdditionalPropertiesString
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class AdditionalPropertiesString implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Animal
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Animal implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "className" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"className" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"color" : {
|
||||
"type" : "string",
|
||||
"default" : "red"
|
||||
}
|
||||
},
|
||||
"discriminator" : {
|
||||
"propertyName" : "className"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $className */
|
||||
private $className;
|
||||
|
||||
/** @var string $color */
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* ApiResponse
|
||||
@ -30,10 +30,21 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ApiResponse implements ModelInterface
|
||||
class ApiResponse extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"title" : "An uploaded response",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"code" : {
|
||||
@ -46,28 +57,8 @@ class ApiResponse implements ModelInterface
|
||||
"message" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description" : "Describes the result of uploading an image resource"
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $code */
|
||||
private $code;
|
||||
|
||||
/** @var string $type */
|
||||
private $type;
|
||||
|
||||
/** @var string $message */
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ArrayOfArrayOfNumberOnly
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ArrayOfArrayOfNumberOnly implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"ArrayArrayNumber" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var float[][] $arrayArrayNumber */
|
||||
private $arrayArrayNumber;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ArrayOfNumberOnly
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ArrayOfNumberOnly implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"ArrayNumber" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var float[] $arrayNumber */
|
||||
private $arrayNumber;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ArrayTest
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ArrayTest implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"array_of_string" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"array_array_of_integer" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"format" : "int64"
|
||||
}
|
||||
}
|
||||
},
|
||||
"array_array_of_model" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"$ref" : "#/components/schemas/ReadOnlyFirst"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string[] $arrayOfString */
|
||||
private $arrayOfString;
|
||||
|
||||
/** @var int[][] $arrayArrayOfInteger */
|
||||
private $arrayArrayOfInteger;
|
||||
|
||||
/** @var \OpenAPIServer\Model\ReadOnlyFirst[][] $arrayArrayOfModel */
|
||||
private $arrayArrayOfModel;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* BigCat
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class BigCat implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"allOf" : [ {
|
||||
"$ref" : "#/components/schemas/Cat"
|
||||
}, {
|
||||
"$ref" : "#/components/schemas/BigCat_allOf"
|
||||
} ]
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $className */
|
||||
private $className;
|
||||
|
||||
/** @var string $color */
|
||||
private $color;
|
||||
|
||||
/** @var bool $declawed */
|
||||
private $declawed;
|
||||
|
||||
/** @var string $kind */
|
||||
private $kind;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* BigCatAllOf
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class BigCatAllOf implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"properties" : {
|
||||
"kind" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "lions", "tigers", "leopards", "jaguars" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $kind */
|
||||
private $kind;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Capitalization
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Capitalization implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"smallCamel" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"CapitalCamel" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"small_Snake" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"Capital_Snake" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"SCA_ETH_Flow_Points" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"ATT_NAME" : {
|
||||
"type" : "string",
|
||||
"description" : "Name of the pet\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $smallCamel */
|
||||
private $smallCamel;
|
||||
|
||||
/** @var string $capitalCamel */
|
||||
private $capitalCamel;
|
||||
|
||||
/** @var string $smallSnake */
|
||||
private $smallSnake;
|
||||
|
||||
/** @var string $capitalSnake */
|
||||
private $capitalSnake;
|
||||
|
||||
/** @var string $sCAETHFlowPoints */
|
||||
private $sCAETHFlowPoints;
|
||||
|
||||
/** @var string $aTTNAME Name of the pet*/
|
||||
private $aTTNAME;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Cat
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Cat implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"allOf" : [ {
|
||||
"$ref" : "#/components/schemas/Animal"
|
||||
}, {
|
||||
"$ref" : "#/components/schemas/Cat_allOf"
|
||||
} ]
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $className */
|
||||
private $className;
|
||||
|
||||
/** @var string $color */
|
||||
private $color;
|
||||
|
||||
/** @var bool $declawed */
|
||||
private $declawed;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* CatAllOf
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class CatAllOf implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"properties" : {
|
||||
"declawed" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var bool $declawed */
|
||||
private $declawed;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* Category
|
||||
@ -30,11 +30,21 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Category implements ModelInterface
|
||||
class Category extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "name" ],
|
||||
"title" : "Pet category",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"id" : {
|
||||
@ -42,31 +52,14 @@ class Category implements ModelInterface
|
||||
"format" : "int64"
|
||||
},
|
||||
"name" : {
|
||||
"type" : "string",
|
||||
"default" : "default-name"
|
||||
"pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$",
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"description" : "A category for a pet",
|
||||
"xml" : {
|
||||
"name" : "Category"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ClassModel
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ClassModel implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"_class" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"description" : "Model for testing model with \"_class\" property"
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $class */
|
||||
private $class;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Client
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Client implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"client" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $client */
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Dog
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Dog implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"allOf" : [ {
|
||||
"$ref" : "#/components/schemas/Animal"
|
||||
}, {
|
||||
"$ref" : "#/components/schemas/Dog_allOf"
|
||||
} ]
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $className */
|
||||
private $className;
|
||||
|
||||
/** @var string $color */
|
||||
private $color;
|
||||
|
||||
/** @var string $breed */
|
||||
private $breed;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* DogAllOf
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class DogAllOf implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"properties" : {
|
||||
"breed" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $breed */
|
||||
private $breed;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* EnumArrays
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class EnumArrays implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"just_symbol" : {
|
||||
"type" : "string",
|
||||
"enum" : [ ">=", "$" ]
|
||||
},
|
||||
"array_enum" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "fish", "crab" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $justSymbol */
|
||||
private $justSymbol;
|
||||
|
||||
/** @var string[] $arrayEnum */
|
||||
private $arrayEnum;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* EnumClass
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class EnumClass implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "string",
|
||||
"default" : "-efg",
|
||||
"enum" : [ "_abc", "-efg", "(xyz)" ]
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* EnumTest
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class EnumTest implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "enum_string_required" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"enum_string" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "UPPER", "lower", "" ]
|
||||
},
|
||||
"enum_string_required" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "UPPER", "lower", "" ]
|
||||
},
|
||||
"enum_integer" : {
|
||||
"type" : "integer",
|
||||
"format" : "int32",
|
||||
"enum" : [ 1, -1 ]
|
||||
},
|
||||
"enum_number" : {
|
||||
"type" : "number",
|
||||
"format" : "double",
|
||||
"enum" : [ 1.1, -1.2 ]
|
||||
},
|
||||
"outerEnum" : {
|
||||
"$ref" : "#/components/schemas/OuterEnum"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $enumString */
|
||||
private $enumString;
|
||||
|
||||
/** @var string $enumStringRequired */
|
||||
private $enumStringRequired;
|
||||
|
||||
/** @var int $enumInteger */
|
||||
private $enumInteger;
|
||||
|
||||
/** @var double $enumNumber */
|
||||
private $enumNumber;
|
||||
|
||||
/** @var \OpenAPIServer\Model\OuterEnum $outerEnum */
|
||||
private $outerEnum;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class File implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"sourceURI" : {
|
||||
"type" : "string",
|
||||
"description" : "Test capitalization"
|
||||
}
|
||||
},
|
||||
"description" : "Must be named `File` for test."
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $sourceURI Test capitalization*/
|
||||
private $sourceURI;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* FileSchemaTestClass
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class FileSchemaTestClass implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"file" : {
|
||||
"$ref" : "#/components/schemas/File"
|
||||
},
|
||||
"files" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"$ref" : "#/components/schemas/File"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var \OpenAPIServer\Model\File $file */
|
||||
private $file;
|
||||
|
||||
/** @var \OpenAPIServer\Model\File[] $files */
|
||||
private $files;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* FormatTest
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class FormatTest implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "byte", "date", "number", "password" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"integer" : {
|
||||
"maximum" : 1E+2,
|
||||
"minimum" : 1E+1,
|
||||
"type" : "integer"
|
||||
},
|
||||
"int32" : {
|
||||
"maximum" : 2E+2,
|
||||
"minimum" : 2E+1,
|
||||
"type" : "integer",
|
||||
"format" : "int32"
|
||||
},
|
||||
"int64" : {
|
||||
"type" : "integer",
|
||||
"format" : "int64"
|
||||
},
|
||||
"number" : {
|
||||
"maximum" : 543.2,
|
||||
"minimum" : 32.1,
|
||||
"type" : "number"
|
||||
},
|
||||
"float" : {
|
||||
"maximum" : 987.6,
|
||||
"minimum" : 54.3,
|
||||
"type" : "number",
|
||||
"format" : "float"
|
||||
},
|
||||
"double" : {
|
||||
"maximum" : 123.4,
|
||||
"minimum" : 67.8,
|
||||
"type" : "number",
|
||||
"format" : "double"
|
||||
},
|
||||
"string" : {
|
||||
"pattern" : "/[a-z]/i",
|
||||
"type" : "string"
|
||||
},
|
||||
"byte" : {
|
||||
"pattern" : "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
|
||||
"type" : "string",
|
||||
"format" : "byte"
|
||||
},
|
||||
"binary" : {
|
||||
"type" : "string",
|
||||
"format" : "binary"
|
||||
},
|
||||
"date" : {
|
||||
"type" : "string",
|
||||
"format" : "date"
|
||||
},
|
||||
"dateTime" : {
|
||||
"type" : "string",
|
||||
"format" : "date-time"
|
||||
},
|
||||
"uuid" : {
|
||||
"type" : "string",
|
||||
"format" : "uuid",
|
||||
"example" : "72f98069-206d-4f12-9f12-3d1e525a8e84"
|
||||
},
|
||||
"password" : {
|
||||
"maxLength" : 64,
|
||||
"minLength" : 10,
|
||||
"type" : "string",
|
||||
"format" : "password"
|
||||
},
|
||||
"BigDecimal" : {
|
||||
"type" : "string",
|
||||
"format" : "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $integer */
|
||||
private $integer;
|
||||
|
||||
/** @var int $int32 */
|
||||
private $int32;
|
||||
|
||||
/** @var int $int64 */
|
||||
private $int64;
|
||||
|
||||
/** @var float $number */
|
||||
private $number;
|
||||
|
||||
/** @var float $float */
|
||||
private $float;
|
||||
|
||||
/** @var double $double */
|
||||
private $double;
|
||||
|
||||
/** @var string $string */
|
||||
private $string;
|
||||
|
||||
/** @var string $byte */
|
||||
private $byte;
|
||||
|
||||
/** @var \SplFileObject $binary */
|
||||
private $binary;
|
||||
|
||||
/** @var \DateTime $date */
|
||||
private $date;
|
||||
|
||||
/** @var \DateTime $dateTime */
|
||||
private $dateTime;
|
||||
|
||||
/** @var string $uuid */
|
||||
private $uuid;
|
||||
|
||||
/** @var string $password */
|
||||
private $password;
|
||||
|
||||
/** @var BigDecimal $bigDecimal */
|
||||
private $bigDecimal;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* HasOnlyReadOnly
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class HasOnlyReadOnly implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"bar" : {
|
||||
"type" : "string",
|
||||
"readOnly" : true
|
||||
},
|
||||
"foo" : {
|
||||
"type" : "string",
|
||||
"readOnly" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $bar */
|
||||
private $bar;
|
||||
|
||||
/** @var string $foo */
|
||||
private $foo;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
60
samples/server/petstore/php-slim4/lib/Model/InlineObject.php
Normal file
60
samples/server/petstore/php-slim4/lib/Model/InlineObject.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* InlineObject
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class InlineObject extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string",
|
||||
"description" : "Updated name of the pet"
|
||||
},
|
||||
"status" : {
|
||||
"type" : "string",
|
||||
"description" : "Updated status of the pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* InlineObject1
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class InlineObject1 extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"additionalMetadata" : {
|
||||
"type" : "string",
|
||||
"description" : "Additional data to pass to server"
|
||||
},
|
||||
"file" : {
|
||||
"type" : "string",
|
||||
"description" : "file to upload",
|
||||
"format" : "binary"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* MapTest
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class MapTest implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"map_map_of_string" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"map_of_enum_string" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "UPPER", "lower" ]
|
||||
}
|
||||
},
|
||||
"direct_map" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
},
|
||||
"indirect_map" : {
|
||||
"$ref" : "#/components/schemas/StringBooleanMap"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var map[string,map[string,string]] $mapMapOfString */
|
||||
private $mapMapOfString;
|
||||
|
||||
/** @var map[string,string] $mapOfEnumString */
|
||||
private $mapOfEnumString;
|
||||
|
||||
/** @var map[string,bool] $directMap */
|
||||
private $directMap;
|
||||
|
||||
/** @var map[string,bool] $indirectMap */
|
||||
private $indirectMap;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class MixedPropertiesAndAdditionalPropertiesClass implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"uuid" : {
|
||||
"type" : "string",
|
||||
"format" : "uuid"
|
||||
},
|
||||
"dateTime" : {
|
||||
"type" : "string",
|
||||
"format" : "date-time"
|
||||
},
|
||||
"map" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : {
|
||||
"$ref" : "#/components/schemas/Animal"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $uuid */
|
||||
private $uuid;
|
||||
|
||||
/** @var \DateTime $dateTime */
|
||||
private $dateTime;
|
||||
|
||||
/** @var map[string,\OpenAPIServer\Model\Animal] $map */
|
||||
private $map;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Model200Response
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Model200Response implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "integer",
|
||||
"format" : "int32"
|
||||
},
|
||||
"class" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"description" : "Model for testing model name starting with number",
|
||||
"xml" : {
|
||||
"name" : "Name"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $name */
|
||||
private $name;
|
||||
|
||||
/** @var string $class */
|
||||
private $class;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ModelList
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ModelList implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"123-list" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $_123list */
|
||||
private $_123list;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ModelReturn
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ModelReturn implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"return" : {
|
||||
"type" : "integer",
|
||||
"format" : "int32"
|
||||
}
|
||||
},
|
||||
"description" : "Model for testing reserved words",
|
||||
"xml" : {
|
||||
"name" : "Return"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $return */
|
||||
private $return;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Name implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "name" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "integer",
|
||||
"format" : "int32"
|
||||
},
|
||||
"snake_case" : {
|
||||
"type" : "integer",
|
||||
"format" : "int32",
|
||||
"readOnly" : true
|
||||
},
|
||||
"property" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"123Number" : {
|
||||
"type" : "integer",
|
||||
"readOnly" : true
|
||||
}
|
||||
},
|
||||
"description" : "Model for testing model name same as property name",
|
||||
"xml" : {
|
||||
"name" : "Name"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $name */
|
||||
private $name;
|
||||
|
||||
/** @var int $snakeCase */
|
||||
private $snakeCase;
|
||||
|
||||
/** @var string $property */
|
||||
private $property;
|
||||
|
||||
/** @var int $_123number */
|
||||
private $_123number;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* NumberOnly
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class NumberOnly implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"JustNumber" : {
|
||||
"type" : "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var float $justNumber */
|
||||
private $justNumber;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* Order
|
||||
@ -30,10 +30,21 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Order implements ModelInterface
|
||||
class Order extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"title" : "Pet Order",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"id" : {
|
||||
@ -62,39 +73,10 @@ class Order implements ModelInterface
|
||||
"default" : false
|
||||
}
|
||||
},
|
||||
"description" : "An order for a pets from the pet store",
|
||||
"xml" : {
|
||||
"name" : "Order"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var int $petId */
|
||||
private $petId;
|
||||
|
||||
/** @var int $quantity */
|
||||
private $quantity;
|
||||
|
||||
/** @var \DateTime $shipDate */
|
||||
private $shipDate;
|
||||
|
||||
/** @var string $status Order Status*/
|
||||
private $status;
|
||||
|
||||
/** @var bool $complete */
|
||||
private $complete;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* OuterComposite
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class OuterComposite implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"my_number" : {
|
||||
"$ref" : "#/components/schemas/OuterNumber"
|
||||
},
|
||||
"my_string" : {
|
||||
"$ref" : "#/components/schemas/OuterString"
|
||||
},
|
||||
"my_boolean" : {
|
||||
"$ref" : "#/components/schemas/OuterBoolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var float $myNumber */
|
||||
private $myNumber;
|
||||
|
||||
/** @var string $myString */
|
||||
private $myString;
|
||||
|
||||
/** @var bool $myBoolean */
|
||||
private $myBoolean;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* OuterEnum
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class OuterEnum implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "string",
|
||||
"enum" : [ "placed", "approved", "delivered" ]
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* Pet
|
||||
@ -30,17 +30,27 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Pet implements ModelInterface
|
||||
class Pet extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"title" : "a Pet",
|
||||
"required" : [ "name", "photoUrls" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"id" : {
|
||||
"type" : "integer",
|
||||
"format" : "int64",
|
||||
"x-is-unique" : true
|
||||
"format" : "int64"
|
||||
},
|
||||
"category" : {
|
||||
"$ref" : "#/components/schemas/Category"
|
||||
@ -50,7 +60,6 @@ class Pet implements ModelInterface
|
||||
"example" : "doggie"
|
||||
},
|
||||
"photoUrls" : {
|
||||
"uniqueItems" : true,
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"name" : "photoUrl",
|
||||
@ -76,39 +85,10 @@ class Pet implements ModelInterface
|
||||
"enum" : [ "available", "pending", "sold" ]
|
||||
}
|
||||
},
|
||||
"description" : "A pet for sale in the pet store",
|
||||
"xml" : {
|
||||
"name" : "Pet"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var \OpenAPIServer\Model\Category $category */
|
||||
private $category;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/** @var string[] $photoUrls */
|
||||
private $photoUrls;
|
||||
|
||||
/** @var \OpenAPIServer\Model\Tag[] $tags */
|
||||
private $tags;
|
||||
|
||||
/** @var string $status pet status in the store*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* ReadOnlyFirst
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class ReadOnlyFirst implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"bar" : {
|
||||
"type" : "string",
|
||||
"readOnly" : true
|
||||
},
|
||||
"baz" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $bar */
|
||||
private $bar;
|
||||
|
||||
/** @var string $baz */
|
||||
private $baz;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* SpecialModelName
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class SpecialModelName implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"$special[property.name]" : {
|
||||
"type" : "integer",
|
||||
"format" : "int64"
|
||||
}
|
||||
},
|
||||
"xml" : {
|
||||
"name" : "$special[model.name]"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $specialPropertyName */
|
||||
private $specialPropertyName;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* Tag
|
||||
@ -30,10 +30,21 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class Tag implements ModelInterface
|
||||
class Tag extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"title" : "Pet Tag",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"id" : {
|
||||
@ -44,27 +55,10 @@ class Tag implements ModelInterface
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"description" : "A tag for a pet",
|
||||
"xml" : {
|
||||
"name" : "Tag"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var string $name */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* TypeHolderDefault
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class TypeHolderDefault implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "array_item", "bool_item", "integer_item", "number_item", "string_item" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"string_item" : {
|
||||
"type" : "string",
|
||||
"default" : "what"
|
||||
},
|
||||
"number_item" : {
|
||||
"type" : "number"
|
||||
},
|
||||
"integer_item" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
"bool_item" : {
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
},
|
||||
"array_item" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $stringItem */
|
||||
private $stringItem;
|
||||
|
||||
/** @var float $numberItem */
|
||||
private $numberItem;
|
||||
|
||||
/** @var int $integerItem */
|
||||
private $integerItem;
|
||||
|
||||
/** @var bool $boolItem */
|
||||
private $boolItem;
|
||||
|
||||
/** @var int[] $arrayItem */
|
||||
private $arrayItem;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* TypeHolderExample
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class TypeHolderExample implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"required" : [ "array_item", "bool_item", "float_item", "integer_item", "number_item", "string_item" ],
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"string_item" : {
|
||||
"type" : "string",
|
||||
"example" : "what"
|
||||
},
|
||||
"number_item" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234
|
||||
},
|
||||
"float_item" : {
|
||||
"type" : "number",
|
||||
"format" : "float",
|
||||
"example" : 1.234
|
||||
},
|
||||
"integer_item" : {
|
||||
"type" : "integer",
|
||||
"example" : -2
|
||||
},
|
||||
"bool_item" : {
|
||||
"type" : "boolean",
|
||||
"example" : true
|
||||
},
|
||||
"array_item" : {
|
||||
"type" : "array",
|
||||
"example" : [ 0, 1, 2, 3 ],
|
||||
"items" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $stringItem */
|
||||
private $stringItem;
|
||||
|
||||
/** @var float $numberItem */
|
||||
private $numberItem;
|
||||
|
||||
/** @var float $floatItem */
|
||||
private $floatItem;
|
||||
|
||||
/** @var int $integerItem */
|
||||
private $integerItem;
|
||||
|
||||
/** @var bool $boolItem */
|
||||
private $boolItem;
|
||||
|
||||
/** @var int[] $arrayItem */
|
||||
private $arrayItem;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* User
|
||||
@ -30,16 +30,26 @@ use OpenAPIServer\Interfaces\ModelInterface;
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class User implements ModelInterface
|
||||
class User extends BaseModel
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"title" : "a User",
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"id" : {
|
||||
"type" : "integer",
|
||||
"format" : "int64",
|
||||
"x-is-unique" : true
|
||||
"format" : "int64"
|
||||
},
|
||||
"username" : {
|
||||
"type" : "string"
|
||||
@ -65,45 +75,10 @@ class User implements ModelInterface
|
||||
"format" : "int32"
|
||||
}
|
||||
},
|
||||
"description" : "A User who is purchasing from the pet store",
|
||||
"xml" : {
|
||||
"name" : "User"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var int $id */
|
||||
private $id;
|
||||
|
||||
/** @var string $username */
|
||||
private $username;
|
||||
|
||||
/** @var string $firstName */
|
||||
private $firstName;
|
||||
|
||||
/** @var string $lastName */
|
||||
private $lastName;
|
||||
|
||||
/** @var string $email */
|
||||
private $email;
|
||||
|
||||
/** @var string $password */
|
||||
private $password;
|
||||
|
||||
/** @var string $phone */
|
||||
private $phone;
|
||||
|
||||
/** @var int $userStatus User Status*/
|
||||
private $userStatus;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -1,389 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\Interfaces\ModelInterface;
|
||||
|
||||
/**
|
||||
* XmlItem
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class XmlItem implements ModelInterface
|
||||
{
|
||||
private const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"attribute_string" : {
|
||||
"type" : "string",
|
||||
"example" : "string",
|
||||
"xml" : {
|
||||
"attribute" : true
|
||||
}
|
||||
},
|
||||
"attribute_number" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234,
|
||||
"xml" : {
|
||||
"attribute" : true
|
||||
}
|
||||
},
|
||||
"attribute_integer" : {
|
||||
"type" : "integer",
|
||||
"example" : -2,
|
||||
"xml" : {
|
||||
"attribute" : true
|
||||
}
|
||||
},
|
||||
"attribute_boolean" : {
|
||||
"type" : "boolean",
|
||||
"example" : true,
|
||||
"xml" : {
|
||||
"attribute" : true
|
||||
}
|
||||
},
|
||||
"wrapped_array" : {
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"wrapped" : true
|
||||
},
|
||||
"items" : {
|
||||
"type" : "integer"
|
||||
}
|
||||
},
|
||||
"name_string" : {
|
||||
"type" : "string",
|
||||
"example" : "string",
|
||||
"xml" : {
|
||||
"name" : "xml_name_string"
|
||||
}
|
||||
},
|
||||
"name_number" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234,
|
||||
"xml" : {
|
||||
"name" : "xml_name_number"
|
||||
}
|
||||
},
|
||||
"name_integer" : {
|
||||
"type" : "integer",
|
||||
"example" : -2,
|
||||
"xml" : {
|
||||
"name" : "xml_name_integer"
|
||||
}
|
||||
},
|
||||
"name_boolean" : {
|
||||
"type" : "boolean",
|
||||
"example" : true,
|
||||
"xml" : {
|
||||
"name" : "xml_name_boolean"
|
||||
}
|
||||
},
|
||||
"name_array" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"name" : "xml_name_array_item"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name_wrapped_array" : {
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"name" : "xml_name_wrapped_array",
|
||||
"wrapped" : true
|
||||
},
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"name" : "xml_name_wrapped_array_item"
|
||||
}
|
||||
}
|
||||
},
|
||||
"prefix_string" : {
|
||||
"type" : "string",
|
||||
"example" : "string",
|
||||
"xml" : {
|
||||
"prefix" : "ab"
|
||||
}
|
||||
},
|
||||
"prefix_number" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234,
|
||||
"xml" : {
|
||||
"prefix" : "cd"
|
||||
}
|
||||
},
|
||||
"prefix_integer" : {
|
||||
"type" : "integer",
|
||||
"example" : -2,
|
||||
"xml" : {
|
||||
"prefix" : "ef"
|
||||
}
|
||||
},
|
||||
"prefix_boolean" : {
|
||||
"type" : "boolean",
|
||||
"example" : true,
|
||||
"xml" : {
|
||||
"prefix" : "gh"
|
||||
}
|
||||
},
|
||||
"prefix_array" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"prefix" : "ij"
|
||||
}
|
||||
}
|
||||
},
|
||||
"prefix_wrapped_array" : {
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"prefix" : "kl",
|
||||
"wrapped" : true
|
||||
},
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"prefix" : "mn"
|
||||
}
|
||||
}
|
||||
},
|
||||
"namespace_string" : {
|
||||
"type" : "string",
|
||||
"example" : "string",
|
||||
"xml" : {
|
||||
"namespace" : "http://a.com/schema"
|
||||
}
|
||||
},
|
||||
"namespace_number" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234,
|
||||
"xml" : {
|
||||
"namespace" : "http://b.com/schema"
|
||||
}
|
||||
},
|
||||
"namespace_integer" : {
|
||||
"type" : "integer",
|
||||
"example" : -2,
|
||||
"xml" : {
|
||||
"namespace" : "http://c.com/schema"
|
||||
}
|
||||
},
|
||||
"namespace_boolean" : {
|
||||
"type" : "boolean",
|
||||
"example" : true,
|
||||
"xml" : {
|
||||
"namespace" : "http://d.com/schema"
|
||||
}
|
||||
},
|
||||
"namespace_array" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"namespace" : "http://e.com/schema"
|
||||
}
|
||||
}
|
||||
},
|
||||
"namespace_wrapped_array" : {
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"namespace" : "http://f.com/schema",
|
||||
"wrapped" : true
|
||||
},
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"namespace" : "http://g.com/schema"
|
||||
}
|
||||
}
|
||||
},
|
||||
"prefix_ns_string" : {
|
||||
"type" : "string",
|
||||
"example" : "string",
|
||||
"xml" : {
|
||||
"namespace" : "http://a.com/schema",
|
||||
"prefix" : "a"
|
||||
}
|
||||
},
|
||||
"prefix_ns_number" : {
|
||||
"type" : "number",
|
||||
"example" : 1.234,
|
||||
"xml" : {
|
||||
"namespace" : "http://b.com/schema",
|
||||
"prefix" : "b"
|
||||
}
|
||||
},
|
||||
"prefix_ns_integer" : {
|
||||
"type" : "integer",
|
||||
"example" : -2,
|
||||
"xml" : {
|
||||
"namespace" : "http://c.com/schema",
|
||||
"prefix" : "c"
|
||||
}
|
||||
},
|
||||
"prefix_ns_boolean" : {
|
||||
"type" : "boolean",
|
||||
"example" : true,
|
||||
"xml" : {
|
||||
"namespace" : "http://d.com/schema",
|
||||
"prefix" : "d"
|
||||
}
|
||||
},
|
||||
"prefix_ns_array" : {
|
||||
"type" : "array",
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"namespace" : "http://e.com/schema",
|
||||
"prefix" : "e"
|
||||
}
|
||||
}
|
||||
},
|
||||
"prefix_ns_wrapped_array" : {
|
||||
"type" : "array",
|
||||
"xml" : {
|
||||
"namespace" : "http://f.com/schema",
|
||||
"prefix" : "f",
|
||||
"wrapped" : true
|
||||
},
|
||||
"items" : {
|
||||
"type" : "integer",
|
||||
"xml" : {
|
||||
"namespace" : "http://g.com/schema",
|
||||
"prefix" : "g"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"xml" : {
|
||||
"namespace" : "http://a.com/schema",
|
||||
"prefix" : "pre"
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
|
||||
/** @var string $attributeString */
|
||||
private $attributeString;
|
||||
|
||||
/** @var float $attributeNumber */
|
||||
private $attributeNumber;
|
||||
|
||||
/** @var int $attributeInteger */
|
||||
private $attributeInteger;
|
||||
|
||||
/** @var bool $attributeBoolean */
|
||||
private $attributeBoolean;
|
||||
|
||||
/** @var int[] $wrappedArray */
|
||||
private $wrappedArray;
|
||||
|
||||
/** @var string $nameString */
|
||||
private $nameString;
|
||||
|
||||
/** @var float $nameNumber */
|
||||
private $nameNumber;
|
||||
|
||||
/** @var int $nameInteger */
|
||||
private $nameInteger;
|
||||
|
||||
/** @var bool $nameBoolean */
|
||||
private $nameBoolean;
|
||||
|
||||
/** @var int[] $nameArray */
|
||||
private $nameArray;
|
||||
|
||||
/** @var int[] $nameWrappedArray */
|
||||
private $nameWrappedArray;
|
||||
|
||||
/** @var string $prefixString */
|
||||
private $prefixString;
|
||||
|
||||
/** @var float $prefixNumber */
|
||||
private $prefixNumber;
|
||||
|
||||
/** @var int $prefixInteger */
|
||||
private $prefixInteger;
|
||||
|
||||
/** @var bool $prefixBoolean */
|
||||
private $prefixBoolean;
|
||||
|
||||
/** @var int[] $prefixArray */
|
||||
private $prefixArray;
|
||||
|
||||
/** @var int[] $prefixWrappedArray */
|
||||
private $prefixWrappedArray;
|
||||
|
||||
/** @var string $namespaceString */
|
||||
private $namespaceString;
|
||||
|
||||
/** @var float $namespaceNumber */
|
||||
private $namespaceNumber;
|
||||
|
||||
/** @var int $namespaceInteger */
|
||||
private $namespaceInteger;
|
||||
|
||||
/** @var bool $namespaceBoolean */
|
||||
private $namespaceBoolean;
|
||||
|
||||
/** @var int[] $namespaceArray */
|
||||
private $namespaceArray;
|
||||
|
||||
/** @var int[] $namespaceWrappedArray */
|
||||
private $namespaceWrappedArray;
|
||||
|
||||
/** @var string $prefixNsString */
|
||||
private $prefixNsString;
|
||||
|
||||
/** @var float $prefixNsNumber */
|
||||
private $prefixNsNumber;
|
||||
|
||||
/** @var int $prefixNsInteger */
|
||||
private $prefixNsInteger;
|
||||
|
||||
/** @var bool $prefixNsBoolean */
|
||||
private $prefixNsBoolean;
|
||||
|
||||
/** @var int[] $prefixNsArray */
|
||||
private $prefixNsArray;
|
||||
|
||||
/** @var int[] $prefixNsWrappedArray */
|
||||
private $prefixNsWrappedArray;
|
||||
|
||||
/**
|
||||
* Returns model schema.
|
||||
*
|
||||
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays. Default FALSE.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOpenApiSchema($assoc = false)
|
||||
{
|
||||
return json_decode(static::MODEL_SCHEMA, $assoc);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,120 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Utils;
|
||||
|
||||
use OpenAPIServer\Utils\StringUtilsTrait;
|
||||
|
||||
/**
|
||||
* ModelUtilsTrait Class Doc Comment
|
||||
* This class duplicates functionality of ModelUtils.java and AbstractPhpCodegen.java classes.
|
||||
*
|
||||
* @package OpenAPIServer\Utils
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
trait ModelUtilsTrait
|
||||
{
|
||||
use StringUtilsTrait;
|
||||
|
||||
/**
|
||||
* Parses model class name from provided ref.
|
||||
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#reference-object
|
||||
* This method doesn't check that class exists and autoloaded.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java class.
|
||||
*
|
||||
* @param string $ref Reference, eg. #/components/schemas/Pet
|
||||
*
|
||||
* @return string|null classname or null on fail
|
||||
*/
|
||||
public static function getSimpleRef($ref)
|
||||
{
|
||||
$model = null;
|
||||
if (stripos($ref, '#/components/') === 0) {
|
||||
// starts with #/components/
|
||||
$model = substr($ref, strrpos($ref, '/') + 1);
|
||||
} elseif (stripos($ref, '#/definitions/') === 0) {
|
||||
// starts with #/definitions/
|
||||
$model = substr($ref, strrpos($ref, '/') + 1);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the proper model name (capitalized).
|
||||
* In case the name belongs to the TypeSystem it won't be renamed.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java class.
|
||||
*
|
||||
* @param string $name the name of the model
|
||||
* @param string|null $modelNamePrefix modelNamePrefix generator option
|
||||
* @param string|null $modelNameSuffix modelNameSuffix generator option
|
||||
*
|
||||
* @return string capitalized model name
|
||||
*/
|
||||
public static function toModelName(
|
||||
$name,
|
||||
$modelNamePrefix = null,
|
||||
$modelNameSuffix = null
|
||||
) {
|
||||
if (is_string($name) === false || empty($name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// remove [
|
||||
$name = str_replace(']', '', $name);
|
||||
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
$name = preg_replace('/[^\w\\\\]+/', '_', $name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove underscores from start and end
|
||||
$name = trim($name, '_');
|
||||
|
||||
// remove dollar sign
|
||||
$name = str_replace('$', '', $name);
|
||||
|
||||
// model name cannot use reserved keyword
|
||||
if (self::isReservedWord($name)) {
|
||||
$name = 'model_' . $name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (preg_match('/^\d.*/', $name) === 1) {
|
||||
$name = 'model_' . $name; // e.g. 200Response => Model200Response (after camelize)
|
||||
}
|
||||
|
||||
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
|
||||
if (preg_match('/^\\\\.*/', $name) !== 1) {
|
||||
if (is_string($modelNamePrefix) && !empty($modelNamePrefix)) {
|
||||
$name = $modelNamePrefix . '_' . $name;
|
||||
}
|
||||
|
||||
if (is_string($modelNameSuffix) && !empty($modelNameSuffix)) {
|
||||
$name = $name . '_' . $modelNameSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return self::camelize($name);
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
namespace OpenAPIServer\Utils;
|
||||
|
||||
/**
|
||||
* StringUtilsTrait Class Doc Comment
|
||||
* This class duplicates functionality of StringUtils.java and AbstractPhpCodegen.java classes.
|
||||
*
|
||||
* @package OpenAPIServer\Utils
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
trait StringUtilsTrait
|
||||
{
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc)
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/StringUtils.java class.
|
||||
*
|
||||
* @param string $word string to be camelize
|
||||
* @param bool $lowercaseFirstLetter lower case for first letter if set to true
|
||||
*
|
||||
* @return string camelized string
|
||||
*/
|
||||
public static function camelize($word, $lowercaseFirstLetter = false)
|
||||
{
|
||||
// Replace all slashes with dots (package separator)
|
||||
$p = '/\/(.?)/';
|
||||
$word = preg_replace($p, '.$1', $word);
|
||||
|
||||
// case out dots
|
||||
$parts = explode('.', $word);
|
||||
$str = '';
|
||||
foreach ($parts as $z) {
|
||||
if (strlen($z) > 0) {
|
||||
$str .= strtoupper(substr($z, 0, 1)) . substr($z, 1);
|
||||
}
|
||||
}
|
||||
$word = $str;
|
||||
|
||||
// Uppercase the class name.
|
||||
$p = '/(\.?)(\w)([^\.]*)$/';
|
||||
$word = preg_replace_callback($p, function ($matches) {
|
||||
$rep = $matches[1] . strtoupper($matches[2]) . $matches[3];
|
||||
$rep = preg_replace('/\$/', '\\\$', $rep);
|
||||
return $rep;
|
||||
}, $word);
|
||||
|
||||
// Remove all underscores (underscore_case to camelCase)
|
||||
$p = '/(_)(.)/';
|
||||
while (preg_match($p, $word, $matches) === 1) {
|
||||
$original = $matches[2][0];
|
||||
$upperCase = strtoupper($original);
|
||||
if ($original === $upperCase) {
|
||||
$word = preg_replace($p, '$2', $word);
|
||||
} else {
|
||||
$word = preg_replace($p, $upperCase, $word);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all hyphens (hyphen-case to camelCase)
|
||||
$p = '/(-)(.)/';
|
||||
while (preg_match($p, $word, $matches) === 1) {
|
||||
$upperCase = strtoupper($matches[2][0]);
|
||||
$word = preg_replace($p, $upperCase, $word);
|
||||
}
|
||||
|
||||
if ($lowercaseFirstLetter === true && strlen($word) > 0) {
|
||||
$i = 0;
|
||||
$charAt = substr($word, $i, 1);
|
||||
while (
|
||||
$i + 1 < strlen($word)
|
||||
&& !(
|
||||
($charAt >= 'a' && $charAt <= 'z')
|
||||
|| ($charAt >= 'A' && $charAt <= 'Z')
|
||||
)
|
||||
) {
|
||||
$i++;
|
||||
$charAt = substr($word, $i, 1);
|
||||
}
|
||||
$i++;
|
||||
$word = strtolower(substr($word, 0, $i)) . substr($word, $i);
|
||||
}
|
||||
|
||||
// remove all underscore
|
||||
$word = str_replace('_', '', $word);
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether string is reserved php keyword.
|
||||
* This is recreated method of @link modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java class.
|
||||
*
|
||||
* @param string $word Checked string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isReservedWord($word)
|
||||
{
|
||||
if (is_string($word) === false) {
|
||||
return false;
|
||||
}
|
||||
// __halt_compiler is ommited because class names with underscores not allowed anyway
|
||||
return in_array(
|
||||
strtolower($word),
|
||||
['abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor']
|
||||
);
|
||||
}
|
||||
}
|
@ -15,12 +15,14 @@
|
||||
<directory>./test/Api</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Models">
|
||||
<file>./test/BaseModelTest.php</file>
|
||||
<directory>./test/Model</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./lib/Api</directory>
|
||||
<file>./lib/BaseModel.php</file>
|
||||
<directory suffix=".php">./lib/Model</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Please update the test case below to test the endpoint.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OpenAPIServer\Api\AnotherFakeApi;
|
||||
|
||||
/**
|
||||
* AnotherFakeApiTest Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*
|
||||
* @coversDefaultClass \OpenAPIServer\Api\AnotherFakeApi
|
||||
*/
|
||||
class AnotherFakeApiTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test cases
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for call123TestSpecialTags
|
||||
*
|
||||
* To test special tags.
|
||||
*
|
||||
* @covers ::call123TestSpecialTags
|
||||
*/
|
||||
public function testCall123TestSpecialTags()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "call123TestSpecialTags" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Please update the test case below to test the endpoint.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OpenAPIServer\Api\FakeApi;
|
||||
|
||||
/**
|
||||
* FakeApiTest Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*
|
||||
* @coversDefaultClass \OpenAPIServer\Api\FakeApi
|
||||
*/
|
||||
class FakeApiTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test cases
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for createXmlItem
|
||||
*
|
||||
* creates an XmlItem.
|
||||
*
|
||||
* @covers ::createXmlItem
|
||||
*/
|
||||
public function testCreateXmlItem()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "createXmlItem" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for fakeOuterBooleanSerialize
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::fakeOuterBooleanSerialize
|
||||
*/
|
||||
public function testFakeOuterBooleanSerialize()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "fakeOuterBooleanSerialize" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for fakeOuterCompositeSerialize
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::fakeOuterCompositeSerialize
|
||||
*/
|
||||
public function testFakeOuterCompositeSerialize()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "fakeOuterCompositeSerialize" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for fakeOuterNumberSerialize
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::fakeOuterNumberSerialize
|
||||
*/
|
||||
public function testFakeOuterNumberSerialize()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "fakeOuterNumberSerialize" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for fakeOuterStringSerialize
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::fakeOuterStringSerialize
|
||||
*/
|
||||
public function testFakeOuterStringSerialize()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "fakeOuterStringSerialize" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testBodyWithFileSchema
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::testBodyWithFileSchema
|
||||
*/
|
||||
public function testTestBodyWithFileSchema()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testBodyWithFileSchema" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testBodyWithQueryParams
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::testBodyWithQueryParams
|
||||
*/
|
||||
public function testTestBodyWithQueryParams()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testBodyWithQueryParams" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testClientModel
|
||||
*
|
||||
* To test \"client\" model.
|
||||
*
|
||||
* @covers ::testClientModel
|
||||
*/
|
||||
public function testTestClientModel()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testClientModel" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testEndpointParameters
|
||||
*
|
||||
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트.
|
||||
*
|
||||
* @covers ::testEndpointParameters
|
||||
*/
|
||||
public function testTestEndpointParameters()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testEndpointParameters" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testEnumParameters
|
||||
*
|
||||
* To test enum parameters.
|
||||
*
|
||||
* @covers ::testEnumParameters
|
||||
*/
|
||||
public function testTestEnumParameters()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testEnumParameters" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testGroupParameters
|
||||
*
|
||||
* Fake endpoint to test group parameters (optional).
|
||||
*
|
||||
* @covers ::testGroupParameters
|
||||
*/
|
||||
public function testTestGroupParameters()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testGroupParameters" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testInlineAdditionalProperties
|
||||
*
|
||||
* test inline additionalProperties.
|
||||
*
|
||||
* @covers ::testInlineAdditionalProperties
|
||||
*/
|
||||
public function testTestInlineAdditionalProperties()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testInlineAdditionalProperties" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testJsonFormData
|
||||
*
|
||||
* test json serialization of form data.
|
||||
*
|
||||
* @covers ::testJsonFormData
|
||||
*/
|
||||
public function testTestJsonFormData()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testJsonFormData" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testQueryParameterCollectionFormat
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @covers ::testQueryParameterCollectionFormat
|
||||
*/
|
||||
public function testTestQueryParameterCollectionFormat()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testQueryParameterCollectionFormat" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Please update the test case below to test the endpoint.
|
||||
*/
|
||||
namespace OpenAPIServer\Api;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OpenAPIServer\Api\FakeClassnameTags123Api;
|
||||
|
||||
/**
|
||||
* FakeClassnameTags123ApiTest Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Api
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*
|
||||
* @coversDefaultClass \OpenAPIServer\Api\FakeClassnameTags123Api
|
||||
*/
|
||||
class FakeClassnameTags123ApiTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test cases
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for testClassname
|
||||
*
|
||||
* To test class name in snake case.
|
||||
*
|
||||
* @covers ::testClassname
|
||||
*/
|
||||
public function testTestClassname()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "testClassname" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
@ -176,18 +176,4 @@ class PetApiTest extends TestCase
|
||||
'Test of "uploadFile" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for uploadFileWithRequiredFile
|
||||
*
|
||||
* uploads an image (required).
|
||||
*
|
||||
* @covers ::uploadFileWithRequiredFile
|
||||
*/
|
||||
public function testUploadFileWithRequiredFile()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "uploadFileWithRequiredFile" method has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user