@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,238 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* FormDataProcessor
|
|
4
|
+
* PHP version 7.4
|
|
5
|
+
*
|
|
6
|
+
* @category Class
|
|
7
|
+
* @package {{invokerPackage}}
|
|
8
|
+
* @author OpenAPI Generator team
|
|
9
|
+
* @link https://openapi-generator.tech
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
{{>partial_header}}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
16
|
+
* https://openapi-generator.tech
|
|
17
|
+
* Do not edit the class manually.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
namespace {{invokerPackage}};
|
|
21
|
+
|
|
22
|
+
use ArrayAccess;
|
|
23
|
+
use DateTime;
|
|
24
|
+
use GuzzleHttp\Psr7\Utils;
|
|
25
|
+
use Psr\Http\Message\StreamInterface;
|
|
26
|
+
use SplFileObject;
|
|
27
|
+
use {{modelPackage}}\ModelInterface;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* FormDataProcessor Class Doc Comment
|
|
31
|
+
*
|
|
32
|
+
* @category Class
|
|
33
|
+
* @package {{invokerPackage}}
|
|
34
|
+
* @author OpenAPI Generator team
|
|
35
|
+
* @link https://openapi-generator.tech
|
|
36
|
+
*/
|
|
37
|
+
class FormDataProcessor
|
|
38
|
+
{
|
|
39
|
+
/**
|
|
40
|
+
* Tags whether payload passed to ::prepare() contains one or more
|
|
41
|
+
* SplFileObject or stream values.
|
|
42
|
+
*/
|
|
43
|
+
public bool $has_file = false;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Take value and turn it into an array suitable for inclusion in
|
|
47
|
+
* the http body (form parameter). If it's a string, pass through unchanged
|
|
48
|
+
* If it's a datetime object, format it in ISO8601
|
|
49
|
+
*
|
|
50
|
+
* @param array<string|bool|array|DateTime|ArrayAccess|SplFileObject> $values the value of the form parameter
|
|
51
|
+
*
|
|
52
|
+
* @return array [key => value] of formdata
|
|
53
|
+
*/
|
|
54
|
+
public function prepare(array $values): array
|
|
55
|
+
{
|
|
56
|
+
$this->has_file = false;
|
|
57
|
+
$result = [];
|
|
58
|
+
|
|
59
|
+
foreach ($values as $k => $v) {
|
|
60
|
+
if ($v === null) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
$result[$k] = $this->makeFormSafe($v);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return $result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Flattens a multi-level array of data and generates a single-level array
|
|
72
|
+
* compatible with formdata - a single-level array where the keys use bracket
|
|
73
|
+
* notation to signify nested data.
|
|
74
|
+
*
|
|
75
|
+
* credit: https://github.com/FranBar1966/FlatPHP
|
|
76
|
+
*/
|
|
77
|
+
public static function flatten(array $source, string $start = ''): array
|
|
78
|
+
{
|
|
79
|
+
$opt = [
|
|
80
|
+
'prefix' => '[',
|
|
81
|
+
'suffix' => ']',
|
|
82
|
+
'suffix-end' => true,
|
|
83
|
+
'prefix-list' => '[',
|
|
84
|
+
'suffix-list' => ']',
|
|
85
|
+
'suffix-list-end' => true,
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
if ($start === '') {
|
|
89
|
+
$currentPrefix = '';
|
|
90
|
+
$currentSuffix = '';
|
|
91
|
+
$currentSuffixEnd = false;
|
|
92
|
+
} elseif (array_is_list($source)) {
|
|
93
|
+
$currentPrefix = $opt['prefix-list'];
|
|
94
|
+
$currentSuffix = $opt['suffix-list'];
|
|
95
|
+
$currentSuffixEnd = $opt['suffix-list-end'];
|
|
96
|
+
} else {
|
|
97
|
+
$currentPrefix = $opt['prefix'];
|
|
98
|
+
$currentSuffix = $opt['suffix'];
|
|
99
|
+
$currentSuffixEnd = $opt['suffix-end'];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
$currentName = $start;
|
|
103
|
+
$result = [];
|
|
104
|
+
|
|
105
|
+
foreach ($source as $key => $val) {
|
|
106
|
+
$currentName .= $currentPrefix.$key;
|
|
107
|
+
|
|
108
|
+
if (is_array($val) && !empty($val)) {
|
|
109
|
+
$currentName .= $currentSuffix;
|
|
110
|
+
$result += self::flatten($val, $currentName);
|
|
111
|
+
} else {
|
|
112
|
+
if ($currentSuffixEnd) {
|
|
113
|
+
$currentName .= $currentSuffix;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (is_resource($val)) {
|
|
117
|
+
$result[$currentName] = $val;
|
|
118
|
+
} else {
|
|
119
|
+
$result[$currentName] = ObjectSerializer::toString($val);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
$currentName = $start;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return $result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* formdata must be limited to scalars or arrays of scalar values,
|
|
131
|
+
* or a resource for a file upload. Here we iterate through all available
|
|
132
|
+
* data and identify how to handle each scenario
|
|
133
|
+
*/
|
|
134
|
+
protected function makeFormSafe($value)
|
|
135
|
+
{
|
|
136
|
+
if ($value instanceof SplFileObject) {
|
|
137
|
+
return $this->processFiles([$value])[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (is_resource($value)) {
|
|
141
|
+
$this->has_file = true;
|
|
142
|
+
|
|
143
|
+
return $value;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if ($value instanceof ModelInterface) {
|
|
147
|
+
return $this->processModel($value);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (is_array($value) || (is_object($value) && !$value instanceof \DateTimeInterface)) {
|
|
151
|
+
$data = [];
|
|
152
|
+
|
|
153
|
+
foreach ($value as $k => $v) {
|
|
154
|
+
$data[$k] = $this->makeFormSafe($v);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return $data;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return ObjectSerializer::toString($value);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* We are able to handle nested ModelInterface. We do not simply call
|
|
165
|
+
* json_decode(json_encode()) because any given model may have binary data
|
|
166
|
+
* or other data that cannot be serialized to a JSON string
|
|
167
|
+
*/
|
|
168
|
+
protected function processModel(ModelInterface $model): array
|
|
169
|
+
{
|
|
170
|
+
$result = [];
|
|
171
|
+
|
|
172
|
+
foreach ($model::openAPITypes() as $name => $type) {
|
|
173
|
+
$value = $model->offsetGet($name);
|
|
174
|
+
|
|
175
|
+
if ($value === null) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (strpos($type, '\SplFileObject') !== false) {
|
|
180
|
+
$file = is_array($value) ? $value : [$value];
|
|
181
|
+
$result[$name] = $this->processFiles($file);
|
|
182
|
+
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if ($value instanceof ModelInterface) {
|
|
187
|
+
$result[$name] = $this->processModel($value);
|
|
188
|
+
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (is_array($value) || is_object($value)) {
|
|
193
|
+
$result[$name] = $this->makeFormSafe($value);
|
|
194
|
+
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
$result[$name] = ObjectSerializer::toString($value);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return $result;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Handle file data
|
|
206
|
+
*/
|
|
207
|
+
protected function processFiles(array $files): array
|
|
208
|
+
{
|
|
209
|
+
$this->has_file = true;
|
|
210
|
+
|
|
211
|
+
$result = [];
|
|
212
|
+
|
|
213
|
+
foreach ($files as $i => $file) {
|
|
214
|
+
if (is_array($file)) {
|
|
215
|
+
$result[$i] = $this->processFiles($file);
|
|
216
|
+
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if ($file instanceof StreamInterface) {
|
|
221
|
+
$result[$i] = $file;
|
|
222
|
+
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if ($file instanceof SplFileObject) {
|
|
227
|
+
$result[$i] = $this->tryFopen($file);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return $result;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private function tryFopen(SplFileObject $file)
|
|
235
|
+
{
|
|
236
|
+
return Utils::tryFopen($file->getRealPath(), 'rb');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* HeaderSelector
|
|
4
|
+
* PHP version 8.1
|
|
5
|
+
*
|
|
6
|
+
* @category Class
|
|
7
|
+
* @package {{invokerPackage}}
|
|
8
|
+
* @author OpenAPI Generator team
|
|
9
|
+
* @link https://openapi-generator.tech
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
{{>partial_header}}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
16
|
+
* https://openapi-generator.tech
|
|
17
|
+
* Do not edit the class manually.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
namespace {{invokerPackage}};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HeaderSelector Class Doc Comment
|
|
24
|
+
*
|
|
25
|
+
* @category Class
|
|
26
|
+
* @package {{invokerPackage}}
|
|
27
|
+
* @author OpenAPI Generator team
|
|
28
|
+
* @link https://openapi-generator.tech
|
|
29
|
+
*/
|
|
30
|
+
class HeaderSelector
|
|
31
|
+
{
|
|
32
|
+
/**
|
|
33
|
+
* @param string[] $accept
|
|
34
|
+
* @param string $contentType
|
|
35
|
+
* @param bool $isMultipart
|
|
36
|
+
* @return string[]
|
|
37
|
+
*/
|
|
38
|
+
public function selectHeaders(array $accept, string $contentType, bool $isMultipart): array
|
|
39
|
+
{
|
|
40
|
+
$headers = [];
|
|
41
|
+
|
|
42
|
+
$accept = $this->selectAcceptHeader($accept);
|
|
43
|
+
if ($accept !== null) {
|
|
44
|
+
$headers['Accept'] = $accept;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!$isMultipart) {
|
|
48
|
+
if($contentType === '') {
|
|
49
|
+
$contentType = 'application/json';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
$headers['Content-Type'] = $contentType;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return $headers;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Return the header 'Accept' based on an array of Accept provided.
|
|
60
|
+
*
|
|
61
|
+
* @param string[] $accept Array of header
|
|
62
|
+
*
|
|
63
|
+
* @return null|string Accept (e.g. application/json)
|
|
64
|
+
*/
|
|
65
|
+
private function selectAcceptHeader(array $accept): ?string
|
|
66
|
+
{
|
|
67
|
+
# filter out empty entries
|
|
68
|
+
$accept = array_filter($accept);
|
|
69
|
+
|
|
70
|
+
if (count($accept) === 0) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# If there's only one Accept header, just use it
|
|
75
|
+
if (count($accept) === 1) {
|
|
76
|
+
return reset($accept);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# If none of the available Accept headers is of type "json", then just use all them
|
|
80
|
+
$headersWithJson = $this->selectJsonMimeList($accept);
|
|
81
|
+
if (count($headersWithJson) === 0) {
|
|
82
|
+
return implode(',', $accept);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# If we got here, then we need add quality values (weight), as described in IETF RFC 9110, Items 12.[4].2/12.[5].1,
|
|
86
|
+
# to give the highest priority to json-like headers - recalculating the existing ones, if needed
|
|
87
|
+
return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Detects whether a string contains a valid JSON mime type
|
|
92
|
+
*
|
|
93
|
+
* @param string $searchString
|
|
94
|
+
* @return bool
|
|
95
|
+
*/
|
|
96
|
+
public function isJsonMime(string $searchString): bool
|
|
97
|
+
{
|
|
98
|
+
return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Select all items from a list containing a JSON mime type
|
|
103
|
+
*
|
|
104
|
+
* @param array $mimeList
|
|
105
|
+
* @return array
|
|
106
|
+
*/
|
|
107
|
+
private function selectJsonMimeList(array $mimeList): array {
|
|
108
|
+
$jsonMimeList = [];
|
|
109
|
+
foreach ($mimeList as $mime) {
|
|
110
|
+
if($this->isJsonMime($mime)) {
|
|
111
|
+
$jsonMimeList[] = $mime;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return $jsonMimeList;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Create an Accept header string from the given "Accept" headers array, recalculating all weights
|
|
120
|
+
*
|
|
121
|
+
* @param string[] $accept Array of Accept Headers
|
|
122
|
+
* @param string[] $headersWithJson Array of Accept Headers of type "json"
|
|
123
|
+
*
|
|
124
|
+
* @return string "Accept" Header (e.g. "application/json, text/html; q=0.9")
|
|
125
|
+
*/
|
|
126
|
+
private function getAcceptHeaderWithAdjustedWeight(array $accept, array $headersWithJson): string
|
|
127
|
+
{
|
|
128
|
+
$processedHeaders = [
|
|
129
|
+
'withApplicationJson' => [],
|
|
130
|
+
'withJson' => [],
|
|
131
|
+
'withoutJson' => [],
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
foreach ($accept as $header) {
|
|
135
|
+
|
|
136
|
+
$headerData = $this->getHeaderAndWeight($header);
|
|
137
|
+
|
|
138
|
+
if (stripos($headerData['header'], 'application/json') === 0) {
|
|
139
|
+
$processedHeaders['withApplicationJson'][] = $headerData;
|
|
140
|
+
} elseif (in_array($header, $headersWithJson, true)) {
|
|
141
|
+
$processedHeaders['withJson'][] = $headerData;
|
|
142
|
+
} else {
|
|
143
|
+
$processedHeaders['withoutJson'][] = $headerData;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
$acceptHeaders = [];
|
|
148
|
+
$currentWeight = 1000;
|
|
149
|
+
|
|
150
|
+
$hasMoreThan28Headers = count($accept) > 28;
|
|
151
|
+
|
|
152
|
+
foreach($processedHeaders as $headers) {
|
|
153
|
+
if (count($headers) > 0) {
|
|
154
|
+
$acceptHeaders[] = $this->adjustWeight($headers, $currentWeight, $hasMoreThan28Headers);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
$acceptHeaders = array_merge(...$acceptHeaders);
|
|
159
|
+
|
|
160
|
+
return implode(',', $acceptHeaders);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Given an Accept header, returns an associative array splitting the header and its weight
|
|
165
|
+
*
|
|
166
|
+
* @param string $header "Accept" Header
|
|
167
|
+
*
|
|
168
|
+
* @return array with the header and its weight
|
|
169
|
+
*/
|
|
170
|
+
private function getHeaderAndWeight(string $header): array
|
|
171
|
+
{
|
|
172
|
+
# matches headers with weight, splitting the header and the weight in $outputArray
|
|
173
|
+
if (preg_match('/(.*);\s*q=(1(?:\.0+)?|0\.\d+)$/', $header, $outputArray) === 1) {
|
|
174
|
+
$headerData = [
|
|
175
|
+
'header' => $outputArray[1],
|
|
176
|
+
'weight' => (int)($outputArray[2] * 1000),
|
|
177
|
+
];
|
|
178
|
+
} else {
|
|
179
|
+
$headerData = [
|
|
180
|
+
'header' => trim($header),
|
|
181
|
+
'weight' => 1000,
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return $headerData;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param array[] $headers
|
|
190
|
+
* @param float $currentWeight
|
|
191
|
+
* @param bool $hasMoreThan28Headers
|
|
192
|
+
* @return string[] array of adjusted "Accept" headers
|
|
193
|
+
*/
|
|
194
|
+
private function adjustWeight(array $headers, float &$currentWeight, bool $hasMoreThan28Headers): array
|
|
195
|
+
{
|
|
196
|
+
usort($headers, function (array $a, array $b) {
|
|
197
|
+
return $b['weight'] - $a['weight'];
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
$acceptHeaders = [];
|
|
201
|
+
foreach ($headers as $index => $header) {
|
|
202
|
+
if($index > 0 && $headers[$index - 1]['weight'] > $header['weight'])
|
|
203
|
+
{
|
|
204
|
+
$currentWeight = $this->getNextWeight($currentWeight, $hasMoreThan28Headers);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
$weight = $currentWeight;
|
|
208
|
+
|
|
209
|
+
$acceptHeaders[] = $this->buildAcceptHeader($header['header'], $weight);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
$currentWeight = $this->getNextWeight($currentWeight, $hasMoreThan28Headers);
|
|
213
|
+
|
|
214
|
+
return $acceptHeaders;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param string $header
|
|
219
|
+
* @param int $weight
|
|
220
|
+
* @return string
|
|
221
|
+
*/
|
|
222
|
+
private function buildAcceptHeader(string $header, int $weight): string
|
|
223
|
+
{
|
|
224
|
+
if($weight === 1000) {
|
|
225
|
+
return $header;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return trim($header, '; ') . ';q=' . rtrim(sprintf('%0.3f', $weight / 1000), '0');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Calculate the next weight, based on the current one.
|
|
233
|
+
*
|
|
234
|
+
* If there are less than 28 "Accept" headers, the weights will be decreased by 1 on its highest significant digit, using the
|
|
235
|
+
* following formula:
|
|
236
|
+
*
|
|
237
|
+
* next weight = current weight - 10 ^ (floor(log(current weight - 1)))
|
|
238
|
+
*
|
|
239
|
+
* ( current weight minus ( 10 raised to the power of ( floor of (log to the base 10 of ( current weight minus 1 ) ) ) ) )
|
|
240
|
+
*
|
|
241
|
+
* Starting from 1000, this generates the following series:
|
|
242
|
+
*
|
|
243
|
+
* 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
|
|
244
|
+
*
|
|
245
|
+
* The resulting quality codes are closer to the average "normal" usage of them (like "q=0.9", "q=0.8" and so on), but it only works
|
|
246
|
+
* if there is a maximum of 28 "Accept" headers. If we have more than that (which is extremely unlikely), then we fall back to a 1-by-1
|
|
247
|
+
* decrement rule, which will result in quality codes like "q=0.999", "q=0.998" etc.
|
|
248
|
+
*
|
|
249
|
+
* @param int $currentWeight varying from 1 to 1000 (will be divided by 1000 to build the quality value)
|
|
250
|
+
* @param bool $hasMoreThan28Headers
|
|
251
|
+
* @return int
|
|
252
|
+
*/
|
|
253
|
+
public function getNextWeight(int $currentWeight, bool $hasMoreThan28Headers): int
|
|
254
|
+
{
|
|
255
|
+
if ($currentWeight <= 1) {
|
|
256
|
+
return 1;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if ($hasMoreThan28Headers) {
|
|
260
|
+
return $currentWeight - 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return $currentWeight - 10 ** floor( log10($currentWeight - 1) );
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* ModelInterface
|
|
4
|
+
*
|
|
5
|
+
* PHP version 8.1
|
|
6
|
+
*
|
|
7
|
+
* @category Class
|
|
8
|
+
* @package {{modelPackage}}
|
|
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 {{modelPackage}};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Interface abstracting model access.
|
|
25
|
+
*
|
|
26
|
+
* @package {{modelPackage}}
|
|
27
|
+
* @author OpenAPI Generator team
|
|
28
|
+
*/
|
|
29
|
+
interface ModelInterface
|
|
30
|
+
{
|
|
31
|
+
/**
|
|
32
|
+
* The original name of the model.
|
|
33
|
+
*
|
|
34
|
+
* @return string
|
|
35
|
+
*/
|
|
36
|
+
public function getModelName();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Array of property to type mappings. Used for (de)serialization
|
|
40
|
+
*
|
|
41
|
+
* @return array
|
|
42
|
+
*/
|
|
43
|
+
public static function openAPITypes();
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Array of property to format mappings. Used for (de)serialization
|
|
47
|
+
*
|
|
48
|
+
* @return array
|
|
49
|
+
*/
|
|
50
|
+
public static function openAPIFormats();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Array of attributes where the key is the local name, and the value is the original name
|
|
54
|
+
*
|
|
55
|
+
* @return array
|
|
56
|
+
*/
|
|
57
|
+
public static function attributeMap();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Array of attributes to setter functions (for deserialization of responses)
|
|
61
|
+
*
|
|
62
|
+
* @return array
|
|
63
|
+
*/
|
|
64
|
+
public static function setters();
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Array of attributes to getter functions (for serialization of requests)
|
|
68
|
+
*
|
|
69
|
+
* @return array
|
|
70
|
+
*/
|
|
71
|
+
public static function getters();
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Show all the invalid properties with reasons.
|
|
75
|
+
*
|
|
76
|
+
* @return array
|
|
77
|
+
*/
|
|
78
|
+
public function listInvalidProperties();
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Validate all the properties in the model
|
|
82
|
+
* return true if all passed
|
|
83
|
+
*
|
|
84
|
+
* @return bool
|
|
85
|
+
*/
|
|
86
|
+
public function valid();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Checks if a property is nullable
|
|
90
|
+
*
|
|
91
|
+
* @param string $property
|
|
92
|
+
* @return bool
|
|
93
|
+
*/
|
|
94
|
+
public static function isNullable(string $property): bool;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a nullable property is set to null.
|
|
98
|
+
*
|
|
99
|
+
* @param string $property
|
|
100
|
+
* @return bool
|
|
101
|
+
*/
|
|
102
|
+
public function isNullableSetToNull(string $property): bool;
|
|
103
|
+
}
|