@kattebak/openapi-generator-ts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/cli/commands/generate.d.ts +23 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +116 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/list.d.ts +2 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +26 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +80 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/convert-template.d.ts +31 -0
- package/dist/cli/convert-template.d.ts.map +1 -0
- package/dist/cli/convert-template.js +204 -0
- package/dist/cli/convert-template.js.map +1 -0
- package/dist/cli/convert-template.test.d.ts +2 -0
- package/dist/cli/convert-template.test.d.ts.map +1 -0
- package/dist/cli/convert-template.test.js +74 -0
- package/dist/cli/convert-template.test.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +246 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config.d.ts +252 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +31 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/generator.d.ts +99 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +492 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/generators.test.d.ts +6 -0
- package/dist/generators/generators.test.d.ts.map +1 -0
- package/dist/generators/generators.test.js +247 -0
- package/dist/generators/generators.test.js.map +1 -0
- package/dist/generators/go.d.ts +10 -0
- package/dist/generators/go.d.ts.map +1 -0
- package/dist/generators/go.js +327 -0
- package/dist/generators/go.js.map +1 -0
- package/dist/generators/index.d.ts +29 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +58 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/php.d.ts +14 -0
- package/dist/generators/php.d.ts.map +1 -0
- package/dist/generators/php.js +241 -0
- package/dist/generators/php.js.map +1 -0
- package/dist/generators/python.d.ts +10 -0
- package/dist/generators/python.d.ts.map +1 -0
- package/dist/generators/python.js +273 -0
- package/dist/generators/python.js.map +1 -0
- package/dist/generators/typescript-fetch.d.ts +14 -0
- package/dist/generators/typescript-fetch.d.ts.map +1 -0
- package/dist/generators/typescript-fetch.js +217 -0
- package/dist/generators/typescript-fetch.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/models/codegen-model.d.ts +123 -0
- package/dist/models/codegen-model.d.ts.map +1 -0
- package/dist/models/codegen-model.js +64 -0
- package/dist/models/codegen-model.js.map +1 -0
- package/dist/models/codegen-model.test.d.ts +6 -0
- package/dist/models/codegen-model.test.d.ts.map +1 -0
- package/dist/models/codegen-model.test.js +143 -0
- package/dist/models/codegen-model.test.js.map +1 -0
- package/dist/models/codegen-operation.d.ts +95 -0
- package/dist/models/codegen-operation.d.ts.map +1 -0
- package/dist/models/codegen-operation.js +54 -0
- package/dist/models/codegen-operation.js.map +1 -0
- package/dist/models/codegen-parameter.d.ts +86 -0
- package/dist/models/codegen-parameter.d.ts.map +1 -0
- package/dist/models/codegen-parameter.js +47 -0
- package/dist/models/codegen-parameter.js.map +1 -0
- package/dist/models/codegen-property.d.ts +95 -0
- package/dist/models/codegen-property.d.ts.map +1 -0
- package/dist/models/codegen-property.js +47 -0
- package/dist/models/codegen-property.js.map +1 -0
- package/dist/models/codegen-response.d.ts +64 -0
- package/dist/models/codegen-response.d.ts.map +1 -0
- package/dist/models/codegen-response.js +42 -0
- package/dist/models/codegen-response.js.map +1 -0
- package/dist/models/codegen-security.d.ts +34 -0
- package/dist/models/codegen-security.d.ts.map +1 -0
- package/dist/models/codegen-security.js +18 -0
- package/dist/models/codegen-security.js.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/openapi-parser.d.ts +71 -0
- package/dist/parser/openapi-parser.d.ts.map +1 -0
- package/dist/parser/openapi-parser.js +195 -0
- package/dist/parser/openapi-parser.js.map +1 -0
- package/dist/parser/openapi-parser.test.d.ts +6 -0
- package/dist/parser/openapi-parser.test.d.ts.map +1 -0
- package/dist/parser/openapi-parser.test.js +238 -0
- package/dist/parser/openapi-parser.test.js.map +1 -0
- package/dist/parser/operation-transformer.d.ts +95 -0
- package/dist/parser/operation-transformer.d.ts.map +1 -0
- package/dist/parser/operation-transformer.js +634 -0
- package/dist/parser/operation-transformer.js.map +1 -0
- package/dist/parser/schema-transformer.d.ts +134 -0
- package/dist/parser/schema-transformer.d.ts.map +1 -0
- package/dist/parser/schema-transformer.js +557 -0
- package/dist/parser/schema-transformer.js.map +1 -0
- package/dist/template/engine-adapter.d.ts +55 -0
- package/dist/template/engine-adapter.d.ts.map +1 -0
- package/dist/template/engine-adapter.js +178 -0
- package/dist/template/engine-adapter.js.map +1 -0
- package/dist/template/engine-adapter.test.d.ts +6 -0
- package/dist/template/engine-adapter.test.d.ts.map +1 -0
- package/dist/template/engine-adapter.test.js +186 -0
- package/dist/template/engine-adapter.test.js.map +1 -0
- package/dist/template/index.d.ts +5 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +5 -0
- package/dist/template/index.js.map +1 -0
- package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
- package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/indent-lambdas.js +98 -0
- package/dist/template/lambdas/indent-lambdas.js.map +1 -0
- package/dist/template/lambdas/index.d.ts +44 -0
- package/dist/template/lambdas/index.d.ts.map +1 -0
- package/dist/template/lambdas/index.js +79 -0
- package/dist/template/lambdas/index.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.d.ts +78 -0
- package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.js +148 -0
- package/dist/template/lambdas/string-lambdas.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.js +158 -0
- package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
- package/dist/template/template-locator.d.ts +72 -0
- package/dist/template/template-locator.d.ts.map +1 -0
- package/dist/template/template-locator.js +173 -0
- package/dist/template/template-locator.js.map +1 -0
- package/dist/template/template-manager.d.ts +65 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +185 -0
- package/dist/template/template-manager.js.map +1 -0
- package/package.json +67 -0
- package/templates/go/.travis.yml +8 -0
- package/templates/go/README.mustache +236 -0
- package/templates/go/api.mustache +452 -0
- package/templates/go/api_doc.mustache +92 -0
- package/templates/go/api_test.mustache +59 -0
- package/templates/go/client.mustache +761 -0
- package/templates/go/configuration.mustache +332 -0
- package/templates/go/git_push.sh.mustache +57 -0
- package/templates/go/gitignore.mustache +24 -0
- package/templates/go/go.mod.mustache +16 -0
- package/templates/go/go.sum.mustache +19 -0
- package/templates/go/model.mustache +21 -0
- package/templates/go/model_anyof.mustache +93 -0
- package/templates/go/model_doc.mustache +97 -0
- package/templates/go/model_enum.mustache +101 -0
- package/templates/go/model_oneof.mustache +160 -0
- package/templates/go/model_simple.mustache +572 -0
- package/templates/go/nullable_model.mustache +35 -0
- package/templates/go/openapi.mustache +1 -0
- package/templates/go/partial_header.mustache +18 -0
- package/templates/go/response.mustache +38 -0
- package/templates/go/signing.mustache +453 -0
- package/templates/go/utils.mustache +352 -0
- package/templates/php/.php-cs-fixer.dist.php +29 -0
- package/templates/php/.travis.yml +8 -0
- package/templates/php/ApiException.mustache +111 -0
- package/templates/php/Configuration.mustache +606 -0
- package/templates/php/FormDataProcessor.mustache +238 -0
- package/templates/php/HeaderSelector.mustache +265 -0
- package/templates/php/ModelInterface.mustache +103 -0
- package/templates/php/ObjectSerializer.mustache +591 -0
- package/templates/php/README.mustache +151 -0
- package/templates/php/api.mustache +891 -0
- package/templates/php/api_doc.mustache +105 -0
- package/templates/php/api_test.mustache +80 -0
- package/templates/php/composer.mustache +44 -0
- package/templates/php/git_push.sh.mustache +57 -0
- package/templates/php/gitignore +15 -0
- package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
- package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
- package/templates/php/libraries/psr-18/README.mustache +161 -0
- package/templates/php/libraries/psr-18/api.mustache +833 -0
- package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
- package/templates/php/libraries/psr-18/composer.mustache +56 -0
- package/templates/php/model.mustache +47 -0
- package/templates/php/model_doc.mustache +10 -0
- package/templates/php/model_enum.mustache +33 -0
- package/templates/php/model_generic.mustache +565 -0
- package/templates/php/model_test.mustache +88 -0
- package/templates/php/partial_header.mustache +18 -0
- package/templates/php/php_doc_auth_partial.mustache +23 -0
- package/templates/php/phpunit.xml.mustache +18 -0
- package/templates/python/README.mustache +60 -0
- package/templates/python/README_onlypackage.mustache +50 -0
- package/templates/python/__init__.mustache +1 -0
- package/templates/python/__init__api.mustache +19 -0
- package/templates/python/__init__model.mustache +22 -0
- package/templates/python/__init__package.mustache +49 -0
- package/templates/python/api.mustache +244 -0
- package/templates/python/api_client.mustache +822 -0
- package/templates/python/api_doc.mustache +81 -0
- package/templates/python/api_doc_example.mustache +38 -0
- package/templates/python/api_response.mustache +21 -0
- package/templates/python/api_test.mustache +48 -0
- package/templates/python/asyncio/rest.mustache +209 -0
- package/templates/python/common_README.mustache +85 -0
- package/templates/python/configuration.mustache +806 -0
- package/templates/python/exceptions.mustache +210 -0
- package/templates/python/exports_api.mustache +3 -0
- package/templates/python/exports_model.mustache +3 -0
- package/templates/python/exports_package.mustache +20 -0
- package/templates/python/git_push.sh.mustache +57 -0
- package/templates/python/github-workflow.mustache +35 -0
- package/templates/python/gitignore.mustache +66 -0
- package/templates/python/gitlab-ci.mustache +31 -0
- package/templates/python/httpx/rest.mustache +190 -0
- package/templates/python/model.mustache +16 -0
- package/templates/python/model_anyof.mustache +182 -0
- package/templates/python/model_doc.mustache +40 -0
- package/templates/python/model_enum.mustache +36 -0
- package/templates/python/model_generic.mustache +403 -0
- package/templates/python/model_oneof.mustache +209 -0
- package/templates/python/model_test.mustache +60 -0
- package/templates/python/partial_api.mustache +52 -0
- package/templates/python/partial_api_args.mustache +18 -0
- package/templates/python/partial_header.mustache +19 -0
- package/templates/python/py.typed.mustache +1 -0
- package/templates/python/pyproject.mustache +172 -0
- package/templates/python/python_doc_auth_partial.mustache +108 -0
- package/templates/python/requirements.mustache +23 -0
- package/templates/python/rest.mustache +254 -0
- package/templates/python/setup.mustache +60 -0
- package/templates/python/setup_cfg.mustache +2 -0
- package/templates/python/signing.mustache +422 -0
- package/templates/python/test-requirements.mustache +6 -0
- package/templates/python/tornado/rest.mustache +148 -0
- package/templates/python/tox.mustache +9 -0
- package/templates/python/travis.mustache +17 -0
- package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
- package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
- package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
- package/templates/typescript-fetch/README.mustache +127 -0
- package/templates/typescript-fetch/allSagas.mustache +19 -0
- package/templates/typescript-fetch/api_doc.mustache +63 -0
- package/templates/typescript-fetch/api_example.mustache +44 -0
- package/templates/typescript-fetch/apis.index.mustache +16 -0
- package/templates/typescript-fetch/apis.mustache +483 -0
- package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
- package/templates/typescript-fetch/gitignore +4 -0
- package/templates/typescript-fetch/index.mustache +17 -0
- package/templates/typescript-fetch/licenseInfo.mustache +11 -0
- package/templates/typescript-fetch/modelEnum.mustache +28 -0
- package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
- package/templates/typescript-fetch/modelGeneric.mustache +261 -0
- package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
- package/templates/typescript-fetch/modelOneOf.mustache +255 -0
- package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
- package/templates/typescript-fetch/model_doc.mustache +41 -0
- package/templates/typescript-fetch/models.index.mustache +32 -0
- package/templates/typescript-fetch/models.mustache +24 -0
- package/templates/typescript-fetch/npmignore.mustache +1 -0
- package/templates/typescript-fetch/package.mustache +43 -0
- package/templates/typescript-fetch/recordGeneric.mustache +295 -0
- package/templates/typescript-fetch/records.mustache +17 -0
- package/templates/typescript-fetch/runtime.mustache +424 -0
- package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
- package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
- package/templates/typescript-fetch/sagas.mustache +245 -0
- package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
- package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
- package/templates/typescript-fetch/tsconfig.mustache +25 -0
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* ObjectSerializer
|
|
4
|
+
*
|
|
5
|
+
* PHP version 8.1
|
|
6
|
+
*
|
|
7
|
+
* @category Class
|
|
8
|
+
* @package {{invokerPackage}}
|
|
9
|
+
* @author OpenAPI Generator team
|
|
10
|
+
* @link https://openapi-generator.tech
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
{{>partial_header}}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
17
|
+
* https://openapi-generator.tech
|
|
18
|
+
* Do not edit the class manually.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
namespace {{invokerPackage}};
|
|
22
|
+
|
|
23
|
+
use GuzzleHttp\Psr7\Utils;
|
|
24
|
+
use {{modelPackage}}\ModelInterface;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* ObjectSerializer Class Doc Comment
|
|
28
|
+
*
|
|
29
|
+
* @category Class
|
|
30
|
+
* @package {{invokerPackage}}
|
|
31
|
+
* @author OpenAPI Generator team
|
|
32
|
+
* @link https://openapi-generator.tech
|
|
33
|
+
*/
|
|
34
|
+
class ObjectSerializer
|
|
35
|
+
{
|
|
36
|
+
/** @var string */
|
|
37
|
+
private static $dateTimeFormat = \DateTime::ATOM;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Change the date format
|
|
41
|
+
*
|
|
42
|
+
* @param string $format the new date format to use
|
|
43
|
+
*/
|
|
44
|
+
public static function setDateTimeFormat($format)
|
|
45
|
+
{
|
|
46
|
+
self::$dateTimeFormat = $format;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Serialize data
|
|
51
|
+
*
|
|
52
|
+
* @param mixed $data the data to serialize
|
|
53
|
+
* @param string|null $type the OpenAPIToolsType of the data
|
|
54
|
+
* @param string|null $format the format of the OpenAPITools type of the data
|
|
55
|
+
*
|
|
56
|
+
* @return scalar|object|array|null serialized form of $data
|
|
57
|
+
*/
|
|
58
|
+
public static function sanitizeForSerialization($data, $type = null, $format = null)
|
|
59
|
+
{
|
|
60
|
+
if (is_scalar($data) || null === $data) {
|
|
61
|
+
return $data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ($data instanceof \DateTime) {
|
|
65
|
+
return ($format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (is_array($data)) {
|
|
69
|
+
foreach ($data as $property => $value) {
|
|
70
|
+
$data[$property] = self::sanitizeForSerialization($value);
|
|
71
|
+
}
|
|
72
|
+
return $data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (is_object($data)) {
|
|
76
|
+
$values = [];
|
|
77
|
+
if ($data instanceof ModelInterface) {
|
|
78
|
+
$formats = $data::openAPIFormats();
|
|
79
|
+
foreach ($data::openAPITypes() as $property => $openAPIType) {
|
|
80
|
+
$getter = $data::getters()[$property];
|
|
81
|
+
$value = $data->$getter();
|
|
82
|
+
if ($value !== null && !in_array($openAPIType, [{{&primitives}}], true)) {
|
|
83
|
+
$callable = [$openAPIType, 'getAllowableEnumValues'];
|
|
84
|
+
if (is_callable($callable)) {
|
|
85
|
+
/** array $callable */
|
|
86
|
+
$allowedEnumTypes = $callable();
|
|
87
|
+
if (!in_array($value, $allowedEnumTypes, true)) {
|
|
88
|
+
$imploded = implode("', '", $allowedEnumTypes);
|
|
89
|
+
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (($data::isNullable($property) && $data->isNullableSetToNull($property)) || $value !== null) {
|
|
94
|
+
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
foreach($data as $property => $value) {
|
|
99
|
+
$values[$property] = self::sanitizeForSerialization($value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return (object)$values;
|
|
103
|
+
} else {
|
|
104
|
+
return (string)$data;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sanitize filename by removing path.
|
|
110
|
+
* e.g. ../../sun.gif becomes sun.gif
|
|
111
|
+
*
|
|
112
|
+
* @param string $filename filename to be sanitized
|
|
113
|
+
*
|
|
114
|
+
* @return string the sanitized filename
|
|
115
|
+
*/
|
|
116
|
+
public static function sanitizeFilename($filename)
|
|
117
|
+
{
|
|
118
|
+
if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) {
|
|
119
|
+
return $match[1];
|
|
120
|
+
} else {
|
|
121
|
+
return $filename;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Shorter timestamp microseconds to 6 digits length.
|
|
127
|
+
*
|
|
128
|
+
* @param string $timestamp Original timestamp
|
|
129
|
+
*
|
|
130
|
+
* @return string the shorten timestamp
|
|
131
|
+
*/
|
|
132
|
+
public static function sanitizeTimestamp($timestamp)
|
|
133
|
+
{
|
|
134
|
+
if (!is_string($timestamp)) return $timestamp;
|
|
135
|
+
|
|
136
|
+
return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Take value and turn it into a string suitable for inclusion in
|
|
141
|
+
* the path, by url-encoding.
|
|
142
|
+
*
|
|
143
|
+
* @param string $value a string which will be part of the path
|
|
144
|
+
*
|
|
145
|
+
* @return string the serialized object
|
|
146
|
+
*/
|
|
147
|
+
public static function toPathValue($value)
|
|
148
|
+
{
|
|
149
|
+
return rawurlencode(self::toString($value));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Checks if a value is empty, based on its OpenAPI type.
|
|
154
|
+
*
|
|
155
|
+
* @param mixed $value
|
|
156
|
+
* @param string $openApiType
|
|
157
|
+
*
|
|
158
|
+
* @return bool true if $value is empty
|
|
159
|
+
*/
|
|
160
|
+
private static function isEmptyValue($value, string $openApiType): bool
|
|
161
|
+
{
|
|
162
|
+
# If empty() returns false, it is not empty regardless of its type.
|
|
163
|
+
if (!empty($value)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Null is always empty, as we cannot send a real "null" value in a query parameter.
|
|
168
|
+
if ($value === null) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
switch ($openApiType) {
|
|
173
|
+
# For numeric values, false and '' are considered empty.
|
|
174
|
+
# This comparison is safe for floating point values, since the previous call to empty() will
|
|
175
|
+
# filter out values that don't match 0.
|
|
176
|
+
case 'int':
|
|
177
|
+
case 'integer':
|
|
178
|
+
return $value !== 0;
|
|
179
|
+
|
|
180
|
+
case 'number':
|
|
181
|
+
case 'float':
|
|
182
|
+
return $value !== 0 && $value !== 0.0;
|
|
183
|
+
|
|
184
|
+
# For boolean values, '' is considered empty
|
|
185
|
+
case 'bool':
|
|
186
|
+
case 'boolean':
|
|
187
|
+
return !in_array($value, [false, 0], true);
|
|
188
|
+
|
|
189
|
+
# For string values, '' is considered empty.
|
|
190
|
+
case 'string':
|
|
191
|
+
return $value === '';
|
|
192
|
+
|
|
193
|
+
# For all the other types, any value at this point can be considered empty.
|
|
194
|
+
default:
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Take query parameter properties and turn it into an array suitable for
|
|
201
|
+
* native http_build_query or GuzzleHttp\Psr7\Query::build.
|
|
202
|
+
*
|
|
203
|
+
* @param mixed $value Parameter value
|
|
204
|
+
* @param string $paramName Parameter name
|
|
205
|
+
* @param string $openApiType OpenAPIType eg. array or object
|
|
206
|
+
* @param string $style Parameter serialization style
|
|
207
|
+
* @param bool $explode Parameter explode option
|
|
208
|
+
* @param bool $required Whether query param is required or not
|
|
209
|
+
*
|
|
210
|
+
* @return array
|
|
211
|
+
*/
|
|
212
|
+
public static function toQueryValue(
|
|
213
|
+
$value,
|
|
214
|
+
string $paramName,
|
|
215
|
+
string $openApiType = 'string',
|
|
216
|
+
string $style = 'form',
|
|
217
|
+
bool $explode = true,
|
|
218
|
+
bool $required = true
|
|
219
|
+
): array {
|
|
220
|
+
|
|
221
|
+
# Check if we should omit this parameter from the query. This should only happen when:
|
|
222
|
+
# - Parameter is NOT required; AND
|
|
223
|
+
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
|
|
224
|
+
# example, 0 as "int" or "boolean" is NOT an empty value.
|
|
225
|
+
if (self::isEmptyValue($value, $openApiType)) {
|
|
226
|
+
if ($required) {
|
|
227
|
+
return ["{$paramName}" => ''];
|
|
228
|
+
} else {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# Handle DateTime objects in query
|
|
234
|
+
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
|
|
235
|
+
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
$query = [];
|
|
239
|
+
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;
|
|
240
|
+
|
|
241
|
+
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
|
|
242
|
+
// need to flatten array first
|
|
243
|
+
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
|
|
244
|
+
if (!is_array($arr)) return $arr;
|
|
245
|
+
|
|
246
|
+
foreach ($arr as $k => $v) {
|
|
247
|
+
$prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k;
|
|
248
|
+
|
|
249
|
+
if (is_array($v)) {
|
|
250
|
+
$flattenArray($v, $prop, $result);
|
|
251
|
+
} else {
|
|
252
|
+
if ($style !== 'deepObject' && !$explode) {
|
|
253
|
+
// push key itself
|
|
254
|
+
$result[] = $prop;
|
|
255
|
+
}
|
|
256
|
+
$result[$prop] = $v;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return $result;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
$value = $flattenArray($value, $paramName);
|
|
263
|
+
|
|
264
|
+
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.[1].0.md#style-values
|
|
265
|
+
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
|
|
266
|
+
return $value;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
|
|
270
|
+
return $value;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if ('boolean' === $openApiType && is_bool($value)) {
|
|
274
|
+
$value = self::convertBoolToQueryStringFormat($value);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// handle style in serializeCollection
|
|
278
|
+
$query[$paramName] = ($explode) ? $value : self::serializeCollection((array)$value, $style);
|
|
279
|
+
|
|
280
|
+
return $query;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Convert boolean value to format for query string.
|
|
285
|
+
*
|
|
286
|
+
* @param bool $value Boolean value
|
|
287
|
+
*
|
|
288
|
+
* @return int|string Boolean value in format
|
|
289
|
+
*/
|
|
290
|
+
public static function convertBoolToQueryStringFormat(bool $value)
|
|
291
|
+
{
|
|
292
|
+
if (Configuration::BOOLEAN_FORMAT_STRING == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
|
|
293
|
+
return $value ? 'true' : 'false';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return (int) $value;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Take value and turn it into a string suitable for inclusion in
|
|
301
|
+
* the header. If it's a string, pass through unchanged
|
|
302
|
+
* If it's a datetime object, format it in ISO8601
|
|
303
|
+
*
|
|
304
|
+
* @param string $value a string which will be part of the header
|
|
305
|
+
*
|
|
306
|
+
* @return string the header string
|
|
307
|
+
*/
|
|
308
|
+
public static function toHeaderValue($value)
|
|
309
|
+
{
|
|
310
|
+
$callable = [$value, 'toHeaderValue'];
|
|
311
|
+
if (is_callable($callable)) {
|
|
312
|
+
return $callable();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return self::toString($value);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Take value and turn it into a string suitable for inclusion in
|
|
320
|
+
* the parameter. If it's a string, pass through unchanged
|
|
321
|
+
* If it's a datetime object, format it in ISO8601
|
|
322
|
+
* If it's a boolean, convert it to "true" or "false".
|
|
323
|
+
*
|
|
324
|
+
* @param float|int|bool|\DateTime $value the value of the parameter
|
|
325
|
+
*
|
|
326
|
+
* @return string the header string
|
|
327
|
+
*/
|
|
328
|
+
public static function toString($value)
|
|
329
|
+
{
|
|
330
|
+
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
|
331
|
+
return $value->format(self::$dateTimeFormat);
|
|
332
|
+
} elseif (is_bool($value)) {
|
|
333
|
+
return $value ? 'true' : 'false';
|
|
334
|
+
} else {
|
|
335
|
+
return (string) $value;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Serialize an array to a string.
|
|
341
|
+
*
|
|
342
|
+
* @param array $collection collection to serialize to a string
|
|
343
|
+
* @param string $style the format use for serialization (csv,
|
|
344
|
+
* ssv, tsv, pipes, multi)
|
|
345
|
+
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
|
|
346
|
+
*
|
|
347
|
+
* @return string
|
|
348
|
+
*/
|
|
349
|
+
public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false)
|
|
350
|
+
{
|
|
351
|
+
if ($allowCollectionFormatMulti && ('multi' === $style)) {
|
|
352
|
+
// http_build_query() almost does the job for us. We just
|
|
353
|
+
// need to fix the result of multidimensional arrays.
|
|
354
|
+
return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&'));
|
|
355
|
+
}
|
|
356
|
+
switch ($style) {
|
|
357
|
+
case 'pipeDelimited':
|
|
358
|
+
case 'pipes':
|
|
359
|
+
return implode('|', $collection);
|
|
360
|
+
|
|
361
|
+
case 'tsv':
|
|
362
|
+
return implode("\t", $collection);
|
|
363
|
+
|
|
364
|
+
case 'spaceDelimited':
|
|
365
|
+
case 'ssv':
|
|
366
|
+
return implode(' ', $collection);
|
|
367
|
+
|
|
368
|
+
case 'simple':
|
|
369
|
+
case 'csv':
|
|
370
|
+
// Deliberate fall through. CSV is default format.
|
|
371
|
+
default:
|
|
372
|
+
return implode(',', $collection);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Deserialize a JSON string into an object
|
|
378
|
+
*
|
|
379
|
+
* @param mixed $data object or primitive to be deserialized
|
|
380
|
+
* @param string $class class name is passed as a string
|
|
381
|
+
* @param string[]|null $httpHeaders HTTP headers
|
|
382
|
+
*
|
|
383
|
+
* @return object|array|null a single or an array of $class instances
|
|
384
|
+
*/
|
|
385
|
+
public static function deserialize($data, $class, $httpHeaders = null)
|
|
386
|
+
{
|
|
387
|
+
if (null === $data) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (strcasecmp(substr($class, -2), '[]') === 0) {
|
|
392
|
+
$data = is_string($data) ? json_decode($data) : $data;
|
|
393
|
+
|
|
394
|
+
if (!is_array($data)) {
|
|
395
|
+
throw new \InvalidArgumentException("Invalid array '$class'");
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
$subClass = substr($class, 0, -2);
|
|
399
|
+
$values = [];
|
|
400
|
+
foreach ($data as $key => $value) {
|
|
401
|
+
$values[] = self::deserialize($value, $subClass, null);
|
|
402
|
+
}
|
|
403
|
+
return $values;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (preg_match('/^(array<|map\[)/', $class)) { // for associative array e.g. array<string,int>
|
|
407
|
+
$data = is_string($data) ? json_decode($data) : $data;
|
|
408
|
+
settype($data, 'array');
|
|
409
|
+
$inner = substr($class, 4, -1);
|
|
410
|
+
$deserialized = [];
|
|
411
|
+
if (strrpos($inner, ",") !== false) {
|
|
412
|
+
$subClass_array = explode(',', $inner, 2);
|
|
413
|
+
$subClass = $subClass_array[1];
|
|
414
|
+
foreach ($data as $key => $value) {
|
|
415
|
+
$deserialized[$key] = self::deserialize($value, $subClass, null);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return $deserialized;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if ($class === 'object') {
|
|
422
|
+
settype($data, 'array');
|
|
423
|
+
return $data;
|
|
424
|
+
} elseif ($class === 'mixed') {
|
|
425
|
+
settype($data, gettype($data));
|
|
426
|
+
return $data;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if ($class === '\DateTime') {
|
|
430
|
+
// Some APIs return an invalid, empty string as a
|
|
431
|
+
// date-time property. DateTime::__construct() will return
|
|
432
|
+
// the current time for empty input which is probably not
|
|
433
|
+
// what is meant. The invalid empty string is probably to
|
|
434
|
+
// be interpreted as a missing field/value. Let's handle
|
|
435
|
+
// this graceful.
|
|
436
|
+
if (!empty($data)) {
|
|
437
|
+
try {
|
|
438
|
+
return new \DateTime($data);
|
|
439
|
+
} catch (\Exception $exception) {
|
|
440
|
+
// Some APIs return a date-time with too high nanosecond
|
|
441
|
+
// precision for php's DateTime to handle.
|
|
442
|
+
// With provided regexp 6 digits of microseconds saved
|
|
443
|
+
return new \DateTime(self::sanitizeTimestamp($data));
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if ($class === '\SplFileObject') {
|
|
451
|
+
$data = Utils::streamFor($data);
|
|
452
|
+
|
|
453
|
+
/** @var \Psr\Http\Message\StreamInterface $data */
|
|
454
|
+
|
|
455
|
+
// determine file name
|
|
456
|
+
if (
|
|
457
|
+
is_array($httpHeaders)
|
|
458
|
+
&& array_key_exists('Content-Disposition', $httpHeaders)
|
|
459
|
+
&& preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)
|
|
460
|
+
) {
|
|
461
|
+
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);
|
|
462
|
+
} else {
|
|
463
|
+
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
$file = fopen($filename, 'w');
|
|
467
|
+
while ($chunk = $data->read(200)) {
|
|
468
|
+
fwrite($file, $chunk);
|
|
469
|
+
}
|
|
470
|
+
fclose($file);
|
|
471
|
+
|
|
472
|
+
return new \SplFileObject($filename, 'r');
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** @psalm-suppress ParadoxicalCondition */
|
|
476
|
+
if (in_array($class, [{{&primitives}}], true)) {
|
|
477
|
+
settype($data, $class);
|
|
478
|
+
return $data;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
if (method_exists($class, 'getAllowableEnumValues')) {
|
|
483
|
+
if (!in_array($data, $class::getAllowableEnumValues(), true)) {
|
|
484
|
+
$imploded = implode("', '", $class::getAllowableEnumValues());
|
|
485
|
+
throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'");
|
|
486
|
+
}
|
|
487
|
+
return $data;
|
|
488
|
+
} else {
|
|
489
|
+
$data = is_string($data) ? json_decode($data) : $data;
|
|
490
|
+
|
|
491
|
+
if (is_array($data)) {
|
|
492
|
+
$data = (object)$data;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// If a discriminator is defined and points to a valid subclass, use it.
|
|
496
|
+
$discriminator = $class::DISCRIMINATOR;
|
|
497
|
+
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
|
|
498
|
+
$subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator};
|
|
499
|
+
if (is_subclass_of($subclass, $class)) {
|
|
500
|
+
$class = $subclass;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** @var ModelInterface $instance */
|
|
505
|
+
$instance = new $class();
|
|
506
|
+
foreach ($instance::openAPITypes() as $property => $type) {
|
|
507
|
+
$propertySetter = $instance::setters()[$property];
|
|
508
|
+
|
|
509
|
+
if (!isset($propertySetter)) {
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (!isset($data->{$instance::attributeMap()[$property]})) {
|
|
514
|
+
if ($instance::isNullable($property)) {
|
|
515
|
+
$instance->$propertySetter(null);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (isset($data->{$instance::attributeMap()[$property]})) {
|
|
522
|
+
$propertyValue = $data->{$instance::attributeMap()[$property]};
|
|
523
|
+
$instance->$propertySetter(self::deserialize($propertyValue, $type, null));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return $instance;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Build a query string from an array of key value pairs.
|
|
532
|
+
*
|
|
533
|
+
* This function can use the return value of `parse()` to build a query
|
|
534
|
+
* string. This function does not modify the provided keys when an array is
|
|
535
|
+
* encountered (like `http_build_query()` would).
|
|
536
|
+
*
|
|
537
|
+
* The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112
|
|
538
|
+
* with a modification which is described in https://github.com/guzzle/psr7/pull/603
|
|
539
|
+
*
|
|
540
|
+
* @param array $params Query string parameters.
|
|
541
|
+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
|
|
542
|
+
* to encode using RFC3986, or PHP_QUERY_RFC1738
|
|
543
|
+
* to encode using RFC1738.
|
|
544
|
+
*/
|
|
545
|
+
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
|
|
546
|
+
{
|
|
547
|
+
if (!$params) {
|
|
548
|
+
return '';
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if ($encoding === false) {
|
|
552
|
+
$encoder = function (string $str): string {
|
|
553
|
+
return $str;
|
|
554
|
+
};
|
|
555
|
+
} elseif ($encoding === PHP_QUERY_RFC3986) {
|
|
556
|
+
$encoder = 'rawurlencode';
|
|
557
|
+
} elseif ($encoding === PHP_QUERY_RFC1738) {
|
|
558
|
+
$encoder = 'urlencode';
|
|
559
|
+
} else {
|
|
560
|
+
throw new \InvalidArgumentException('Invalid type');
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
$castBool = Configuration::BOOLEAN_FORMAT_INT == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()
|
|
564
|
+
? function ($v) { return (int) $v; }
|
|
565
|
+
: function ($v) { return $v ? 'true' : 'false'; };
|
|
566
|
+
|
|
567
|
+
$qs = '';
|
|
568
|
+
foreach ($params as $k => $v) {
|
|
569
|
+
$k = $encoder((string) $k);
|
|
570
|
+
if (!is_array($v)) {
|
|
571
|
+
$qs .= $k;
|
|
572
|
+
$v = is_bool($v) ? $castBool($v) : $v;
|
|
573
|
+
if ($v !== null) {
|
|
574
|
+
$qs .= '='.$encoder((string) $v);
|
|
575
|
+
}
|
|
576
|
+
$qs .= '&';
|
|
577
|
+
} else {
|
|
578
|
+
foreach ($v as $vv) {
|
|
579
|
+
$qs .= $k;
|
|
580
|
+
$vv = is_bool($vv) ? $castBool($vv) : $vv;
|
|
581
|
+
if ($vv !== null) {
|
|
582
|
+
$qs .= '='.$encoder((string) $vv);
|
|
583
|
+
}
|
|
584
|
+
$qs .= '&';
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return $qs ? substr($qs, 0, -1) : '';
|
|
590
|
+
}
|
|
591
|
+
}
|