diff --git a/CHANGELOG.md b/CHANGELOG.md index 238a008..10af238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [11.1.3] - 2025.12.08 +### Fixed +- Fixed content type construction parameter generation - issue #128, fixed + - with multiple content type values + - with content type value received from parameters + ## [11.1.2] - 2025.10.28 ### Fixed - Enum with invalid PHP constant value diff --git a/example/PetStoreClient/doc/petstore3.json b/example/PetStoreClient/doc/petstore3.json index cc9889d..de2abd4 100644 --- a/example/PetStoreClient/doc/petstore3.json +++ b/example/PetStoreClient/doc/petstore3.json @@ -116,6 +116,20 @@ "summary": "Add a new pet to the store", "description": "Add a new pet to the store", "operationId": "addPet", + "parameters": [ + { + "in" : "header", + "name": "Content-Type", + "required": true, + "schema": { + "type": "string", + "enum": [ + "application/json", + "application/xml" + ] + } + } + ], "requestBody": { "description": "Create a new pet in the store", "content": { diff --git a/example/PetStoreClient/src/Request/AddPetRequest.php b/example/PetStoreClient/src/Request/AddPetRequest.php index 4da10df..2755f47 100644 --- a/example/PetStoreClient/src/Request/AddPetRequest.php +++ b/example/PetStoreClient/src/Request/AddPetRequest.php @@ -11,17 +11,22 @@ namespace OpenApi\PetStoreClient\Request; use OpenApi\PetStoreClient\Schema\Pet; +use OpenApi\PetStoreClient\Schema\SerializableInterface; class AddPetRequest implements RequestInterface { - private Pet $pet; + public const CONTENT_TYPE_APPLICATION_JSON = 'application/json'; + + public const CONTENT_TYPE_APPLICATION_XML = 'application/xml'; private string $contentType; - public function __construct(Pet $pet, string $contentType) + private Pet $pet; + + public function __construct(string $contentType, Pet $pet) { - $this->pet = $pet; $this->contentType = $contentType; + $this->pet = $pet; } public function getContentType(): string @@ -56,7 +61,11 @@ public function getCookies(): array public function getHeaders(): array { - return ['Content-Type' => $this->contentType]; + return array_merge(['Content-Type' => $this->contentType], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['Content-Type' => $this->contentType], static function ($value) { + return null !== $value; + }))); } /** diff --git a/example/petstore3.json b/example/petstore3.json index cc9889d..de2abd4 100644 --- a/example/petstore3.json +++ b/example/petstore3.json @@ -116,6 +116,20 @@ "summary": "Add a new pet to the store", "description": "Add a new pet to the store", "operationId": "addPet", + "parameters": [ + { + "in" : "header", + "name": "Content-Type", + "required": true, + "schema": { + "type": "string", + "enum": [ + "application/json", + "application/xml" + ] + } + } + ], "requestBody": { "description": "Create a new pet in the store", "content": { diff --git a/src/Generator/RequestGenerator.php b/src/Generator/RequestGenerator.php index 8775af9..596102e 100644 --- a/src/Generator/RequestGenerator.php +++ b/src/Generator/RequestGenerator.php @@ -28,9 +28,13 @@ class RequestGenerator extends MutatorAccessorClassGeneratorAbstract public const SUBDIRECTORY = 'Request/'; + private const CONTENT_TYPE_PARAMETER_NAME = 'contentType'; + /** @var SecurityStrategyInterface[] */ private array $securityStrategies; + private bool $isContentTypeEnum = false; + public function __construct( string $baseNamespace, CodeBuilder $builder, @@ -45,6 +49,7 @@ public function __construct( public function generate(Specification $specification, PhpFileCollection $fileRegistry): void { foreach ($specification->getOperations() as $operation) { + $this->isContentTypeEnum = false; $this->generateRequest($fileRegistry, $operation, $specification); } } @@ -92,6 +97,7 @@ protected function generateEnums(Request $request): array protected function generateProperties(Request $request, Operation $operation, Specification $specification): array { $statements = []; + $fieldNames = []; foreach ($request->fields as $field) { if ($field->isComposite()) { @@ -117,13 +123,21 @@ protected function generateProperties(Request $request, Operation $operation, Sp } $statements[] = $this->generateProperty($field); + $fieldNames[] = $field->getPhpVariableName(); } - $default = null; - if (count($request->bodyContentTypes) < 2) { + $default = null; + $bodyContentTypesCount = count($request->bodyContentTypes); + if ($bodyContentTypesCount < 2) { $default = $this->builder->val($request->bodyContentTypes[0] ?? ''); } - $statements[] = $this->builder->localProperty('contentType', 'string', 'string', false, $default); + + if ( + ($bodyContentTypesCount < 2 || !$this->phpVersion->isConstructorPropertyPromotionSupported()) + && !in_array(self::CONTENT_TYPE_PARAMETER_NAME, $fieldNames, true) + ) { + $statements[] = $this->builder->localProperty(self::CONTENT_TYPE_PARAMETER_NAME, 'string', 'string', false, $default); + } foreach ($this->securityStrategies as $securityStrategy) { array_push($statements, ...$securityStrategy->getProperties($operation, $specification)); @@ -137,6 +151,7 @@ protected function generateConstructor( Operation $operation, Specification $specification ): ?ClassMethod { + $paramNames = []; $params = []; $paramInits = []; $validations = []; @@ -163,7 +178,16 @@ protected function generateConstructor( } } - $params[] = $param; + $params[] = $param; + $paramNames[] = $field->getPhpVariableName(); + + if ( + $field->isEnum() + && $this->phpVersion->isEnumSupported() + && $field->getPhpVariableName() === self::CONTENT_TYPE_PARAMETER_NAME + ) { + $this->isContentTypeEnum = true; + } $paramInits[] = $this->builder->assign( $this->builder->localPropertyFetch($field->getPhpVariableName()), @@ -177,14 +201,12 @@ protected function generateConstructor( array_push($paramInits, ...$securityStrategy->getConstructorParamInits($operation, $specification)); } - if (count($request->bodyContentTypes) > 1) { - $contentTypeVariableName = 'contentType'; - - $params[] = $this->builder->param($contentTypeVariableName)->setType('string'); + if (count($request->bodyContentTypes) > 1 && !in_array(self::CONTENT_TYPE_PARAMETER_NAME, $paramNames, true)) { + $params[] = $this->builder->param(self::CONTENT_TYPE_PARAMETER_NAME)->setType('string'); $paramInits[] = $this->builder->assign( - $this->builder->localPropertyFetch($contentTypeVariableName), - $this->builder->var($contentTypeVariableName) + $this->builder->localPropertyFetch(self::CONTENT_TYPE_PARAMETER_NAME), + $this->builder->var(self::CONTENT_TYPE_PARAMETER_NAME) ); } @@ -242,8 +264,14 @@ private function generateSetters(Request $request): array private function generateGetContentType(): ClassMethod { - $return = $this->builder->return($this->builder->localPropertyFetch('contentType')); - $returnType = 'string'; + $localProperty = $this->builder->localPropertyFetch(self::CONTENT_TYPE_PARAMETER_NAME); + $returnType = 'string'; + + if ($this->isContentTypeEnum) { + $localProperty = $this->builder->propertyFetch($localProperty, 'value'); + } + + $return = $this->builder->return($localProperty); return $this ->builder @@ -452,8 +480,15 @@ private function generateGetHeadersMethod( $stmts = $this->getSecurityHeadersStmts($operation, $specification); $headers = $this->getSecurityHeaders($operation, $specification); if (!empty($request->bodyContentTypes)) { - $headers['Content-Type'] = $this->builder->localPropertyFetch('contentType'); + $contentType = $this->builder->localPropertyFetch('contentType'); + + if ($this->isContentTypeEnum) { + $contentType = $this->builder->propertyFetch($contentType, 'value'); + } + + $headers['Content-Type'] = $contentType; } + $returnVal = $this->builder->array($headers); $fieldsArr = []; $returnType = 'array'; diff --git a/test/suite/functional/Generator/Request/GetResourceByTypeRequest83.php b/test/suite/functional/Generator/Request/GetResourceByTypeRequest83.php new file mode 100644 index 0000000..daa0162 --- /dev/null +++ b/test/suite/functional/Generator/Request/GetResourceByTypeRequest83.php @@ -0,0 +1,62 @@ +contentType; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function getRoute(): string + { + return strtr('v1/{resource-type}/resource', ['{resource-type}' => $this->resourceType->value]); + } + + public function getQueryParameters(): array + { + return []; + } + + public function getRawQueryParameters(): array + { + return []; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return []; + } + + public function getBody() + { + return null; + } +} diff --git a/test/suite/functional/Generator/Request/GetResourcesRequest83.php b/test/suite/functional/Generator/Request/GetResourcesRequest83.php new file mode 100644 index 0000000..df1fd66 --- /dev/null +++ b/test/suite/functional/Generator/Request/GetResourcesRequest83.php @@ -0,0 +1,106 @@ +contentType; + } + + public function setFilterById(int $filterById): self + { + $this->filterById = $filterById; + + return $this; + } + + public function setFilterByName(string $filterByName): self + { + $this->filterByName = $filterByName; + + return $this; + } + + /** + * @param int[] $filterByIds + */ + public function setFilterByIds(array $filterByIds): self + { + $this->filterByIds = $filterByIds; + + return $this; + } + + public function setFilter(ResourceFilter $filter): self + { + $this->filter = $filter; + + return $this; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function getRoute(): string + { + return 'v1/resources'; + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['filterById' => $this->filterById, 'filterByName' => $this->filterByName, 'filterByIds' => $this->filterByIds, 'filter' => $this->filter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['filterById' => $this->filterById, 'filterByName' => $this->filterByName, 'filterByIds' => $this->filterByIds, 'filter' => $this->filter]; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return ['Authorization' => sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->credentials->getUsername(), $this->credentials->getPassword())))]; + } + + public function getBody() + { + return null; + } +} diff --git a/test/suite/functional/Generator/Request/GetSubResourcesRequest83.php b/test/suite/functional/Generator/Request/GetSubResourcesRequest83.php new file mode 100644 index 0000000..3508151 --- /dev/null +++ b/test/suite/functional/Generator/Request/GetSubResourcesRequest83.php @@ -0,0 +1,76 @@ +contentType; + } + + public function setFilter(SubResourceFilter $filter): self + { + $this->filter = $filter; + + return $this; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function getRoute(): string + { + return 'v1/resources/sub-resources'; + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['filter' => $this->filter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['filter' => $this->filter]; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return ['Authorization' => sprintf('Bearer %s', $this->bearerToken)]; + } + + public function getBody() + { + return null; + } +} diff --git a/test/suite/functional/Generator/Request/PatchAnotherSubResourceRequest83.php b/test/suite/functional/Generator/Request/PatchAnotherSubResourceRequest83.php new file mode 100644 index 0000000..cf16a51 --- /dev/null +++ b/test/suite/functional/Generator/Request/PatchAnotherSubResourceRequest83.php @@ -0,0 +1,65 @@ +contentType; + } + + public function getMethod(): string + { + return 'PATCH'; + } + + public function getRoute(): string + { + return 'v1/resources/sub/resource/{resourceId}'; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getRawQueryParameters(): array + { + return []; + } + + public function getCookies(): array + { + return ['api_key' => $this->apiKey]; + } + + public function getHeaders(): array + { + return ['Content-Type' => $this->contentType]; + } + + /** + * @return PatchAnotherSubResourceRequestBody + */ + public function getBody() + { + return $this->patchAnotherSubResourceRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PatchResourceRequest83.php b/test/suite/functional/Generator/Request/PatchResourceRequest83.php new file mode 100644 index 0000000..1836dc0 --- /dev/null +++ b/test/suite/functional/Generator/Request/PatchResourceRequest83.php @@ -0,0 +1,71 @@ +contentType; + } + + public function getMethod(): string + { + return 'PATCH'; + } + + public function getRoute(): string + { + return 'v1/resources/{resourceId}'; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getRawQueryParameters(): array + { + return []; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return array_merge(['X-API-KEY' => $this->apiKey, 'Content-Type' => $this->contentType], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['Accept' => $this->accept], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PatchResourceRequestBody + */ + public function getBody() + { + return $this->patchResourceRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PatchSubResourceRequest83.php b/test/suite/functional/Generator/Request/PatchSubResourceRequest83.php new file mode 100644 index 0000000..f4d0bf5 --- /dev/null +++ b/test/suite/functional/Generator/Request/PatchSubResourceRequest83.php @@ -0,0 +1,65 @@ +contentType; + } + + public function getMethod(): string + { + return 'PATCH'; + } + + public function getRoute(): string + { + return 'v1/resources/sub-resource/{resourceId}'; + } + + public function getQueryParameters(): array + { + return ['apikey' => $this->apiKey]; + } + + public function getRawQueryParameters(): array + { + return ['apikey' => $this->apiKey]; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return ['Content-Type' => $this->contentType]; + } + + /** + * @return PatchSubResourceRequestBody + */ + public function getBody() + { + return $this->patchSubResourceRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PatchYetAnotherSubResourceRequest83.php b/test/suite/functional/Generator/Request/PatchYetAnotherSubResourceRequest83.php new file mode 100644 index 0000000..c6b58b7 --- /dev/null +++ b/test/suite/functional/Generator/Request/PatchYetAnotherSubResourceRequest83.php @@ -0,0 +1,80 @@ +contentType; + } + + public function setFilter(SubResourceFilter $filter): self + { + $this->filter = $filter; + + return $this; + } + + public function getMethod(): string + { + return 'PATCH'; + } + + public function getRoute(): string + { + return 'v1/resources/sub/sub-resource/{resourceId}'; + } + + public function getQueryParameters(): array + { + return array_merge(array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['filter' => $this->filter], static function ($value) { + return null !== $value; + })), ['apikey' => $this->apiKey]); + } + + public function getRawQueryParameters(): array + { + return ['filter' => $this->filter, 'apikey' => $this->apiKey]; + } + + public function getCookies(): array + { + return []; + } + + public function getHeaders(): array + { + return ['Content-Type' => $this->contentType]; + } + + /** + * @return PatchYetAnotherSubResourceRequestBody + */ + public function getBody() + { + return $this->patchYetAnotherSubResourceRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PostResourceByIdRequest74.php b/test/suite/functional/Generator/Request/PostResourceByIdRequest74.php new file mode 100644 index 0000000..03b6977 --- /dev/null +++ b/test/suite/functional/Generator/Request/PostResourceByIdRequest74.php @@ -0,0 +1,228 @@ +resourceId = $resourceId; + $this->contentType = $contentType; + $this->xRequestId = $xRequestId; + $this->mandatoryIntegerParameter = $mandatoryIntegerParameter; + $this->mandatoryStringParameter = $mandatoryStringParameter; + $this->mandatoryEnumParameter = $mandatoryEnumParameter; + $this->mandatoryDateParameter = $mandatoryDateParameter; + $this->mandatoryFloatParameter = $mandatoryFloatParameter; + $this->mandatoryBooleanParameter = $mandatoryBooleanParameter; + $this->mandatoryArrayParameter = $mandatoryArrayParameter; + $this->mandatoryObjectParameter = $mandatoryObjectParameter; + $this->postResourceByIdRequestBody = $postResourceByIdRequestBody; + $this->xwsseUsername = $xwsseUsername; + $this->xwsseSecret = $xwsseSecret; + } + + public function getContentType(): string + { + return $this->contentType; + } + + public function setIntegerParameter(int $integerParameter): self + { + $this->integerParameter = $integerParameter; + + return $this; + } + + public function setStringParameter(string $stringParameter): self + { + $this->stringParameter = $stringParameter; + + return $this; + } + + public function setEnumParameter(string $enumParameter): self + { + $this->enumParameter = $enumParameter; + + return $this; + } + + public function setDateParameter(DateTimeInterface $dateParameter): self + { + $this->dateParameter = $dateParameter; + + return $this; + } + + public function setFloatParameter(float $floatParameter): self + { + $this->floatParameter = $floatParameter; + + return $this; + } + + public function setBooleanParameter(bool $booleanParameter): self + { + $this->booleanParameter = $booleanParameter; + + return $this; + } + + /** + * @param int[] $arrayParameter + */ + public function setArrayParameter(array $arrayParameter): self + { + $this->arrayParameter = $arrayParameter; + + return $this; + } + + public function setObjectParameter(EmbeddedObject $objectParameter): self + { + $this->objectParameter = $objectParameter; + + return $this; + } + + public function setCsrfToken(string $csrfToken): self + { + $this->csrfToken = $csrfToken; + + return $this; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function getRoute(): string + { + return strtr('v1/resources/{resourceId}', ['{resourceId}' => $this->resourceId]); + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter]; + } + + public function getCookies(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['csrf_token' => $this->csrfToken], static function ($value) { + return null !== $value; + })); + } + + public function getHeaders(): array + { + $nonce = bin2hex(random_bytes(16)); + $timestamp = gmdate('c'); + $xwsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->xwsseUsername, base64_encode(sha1($nonce . $timestamp . $this->xwsseSecret)), $nonce, $timestamp); + + return array_merge(['X-WSSE' => $xwsse, 'Content-Type' => $this->contentType], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['contentType' => $this->contentType, 'X-Request-ID' => $this->xRequestId], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PostResourceByIdRequestBody + */ + public function getBody() + { + return $this->postResourceByIdRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PostResourceByIdRequest80.php b/test/suite/functional/Generator/Request/PostResourceByIdRequest80.php new file mode 100644 index 0000000..7aa1c33 --- /dev/null +++ b/test/suite/functional/Generator/Request/PostResourceByIdRequest80.php @@ -0,0 +1,186 @@ +contentType; + } + + public function setIntegerParameter(int $integerParameter): self + { + $this->integerParameter = $integerParameter; + + return $this; + } + + public function setStringParameter(string $stringParameter): self + { + $this->stringParameter = $stringParameter; + + return $this; + } + + public function setEnumParameter(string $enumParameter): self + { + $this->enumParameter = $enumParameter; + + return $this; + } + + public function setDateParameter(DateTimeInterface $dateParameter): self + { + $this->dateParameter = $dateParameter; + + return $this; + } + + public function setFloatParameter(float $floatParameter): self + { + $this->floatParameter = $floatParameter; + + return $this; + } + + public function setBooleanParameter(bool $booleanParameter): self + { + $this->booleanParameter = $booleanParameter; + + return $this; + } + + /** + * @param int[] $arrayParameter + */ + public function setArrayParameter(array $arrayParameter): self + { + $this->arrayParameter = $arrayParameter; + + return $this; + } + + public function setObjectParameter(EmbeddedObject $objectParameter): self + { + $this->objectParameter = $objectParameter; + + return $this; + } + + public function setCsrfToken(string $csrfToken): self + { + $this->csrfToken = $csrfToken; + + return $this; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function getRoute(): string + { + return strtr('v1/resources/{resourceId}', ['{resourceId}' => $this->resourceId]); + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter]; + } + + public function getCookies(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['csrf_token' => $this->csrfToken], static function ($value) { + return null !== $value; + })); + } + + public function getHeaders(): array + { + $nonce = bin2hex(random_bytes(16)); + $timestamp = gmdate('c'); + $xwsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->xwsseUsername, base64_encode(sha1($nonce . $timestamp . $this->xwsseSecret)), $nonce, $timestamp); + + return array_merge(['X-WSSE' => $xwsse, 'Content-Type' => $this->contentType], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['contentType' => $this->contentType, 'X-Request-ID' => $this->xRequestId], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PostResourceByIdRequestBody + */ + public function getBody() + { + return $this->postResourceByIdRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PostResourceByIdRequest81.php b/test/suite/functional/Generator/Request/PostResourceByIdRequest81.php new file mode 100644 index 0000000..b5725a8 --- /dev/null +++ b/test/suite/functional/Generator/Request/PostResourceByIdRequest81.php @@ -0,0 +1,173 @@ +contentType->value; + } + + public function setIntegerParameter(int $integerParameter): self + { + $this->integerParameter = $integerParameter; + + return $this; + } + + public function setStringParameter(string $stringParameter): self + { + $this->stringParameter = $stringParameter; + + return $this; + } + + public function setEnumParameter(EnumParameterEnum $enumParameter): self + { + $this->enumParameter = $enumParameter; + + return $this; + } + + public function setDateParameter(DateTimeInterface $dateParameter): self + { + $this->dateParameter = $dateParameter; + + return $this; + } + + public function setFloatParameter(float $floatParameter): self + { + $this->floatParameter = $floatParameter; + + return $this; + } + + public function setBooleanParameter(bool $booleanParameter): self + { + $this->booleanParameter = $booleanParameter; + + return $this; + } + + /** + * @param int[] $arrayParameter + */ + public function setArrayParameter(array $arrayParameter): self + { + $this->arrayParameter = $arrayParameter; + + return $this; + } + + public function setObjectParameter(EmbeddedObject $objectParameter): self + { + $this->objectParameter = $objectParameter; + + return $this; + } + + public function setCsrfToken(string $csrfToken): self + { + $this->csrfToken = $csrfToken; + + return $this; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function getRoute(): string + { + return strtr('v1/resources/{resourceId}', ['{resourceId}' => $this->resourceId]); + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter]; + } + + public function getCookies(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['csrf_token' => $this->csrfToken], static function ($value) { + return null !== $value; + })); + } + + public function getHeaders(): array + { + $nonce = bin2hex(random_bytes(16)); + $timestamp = gmdate('c'); + $xwsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->xwsseUsername, base64_encode(sha1($nonce . $timestamp . $this->xwsseSecret)), $nonce, $timestamp); + + return array_merge(['X-WSSE' => $xwsse, 'Content-Type' => $this->contentType->value], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['contentType' => $this->contentType, 'X-Request-ID' => $this->xRequestId], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PostResourceByIdRequestBody + */ + public function getBody() + { + return $this->postResourceByIdRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PostResourceByIdRequest83.php b/test/suite/functional/Generator/Request/PostResourceByIdRequest83.php new file mode 100644 index 0000000..b5725a8 --- /dev/null +++ b/test/suite/functional/Generator/Request/PostResourceByIdRequest83.php @@ -0,0 +1,173 @@ +contentType->value; + } + + public function setIntegerParameter(int $integerParameter): self + { + $this->integerParameter = $integerParameter; + + return $this; + } + + public function setStringParameter(string $stringParameter): self + { + $this->stringParameter = $stringParameter; + + return $this; + } + + public function setEnumParameter(EnumParameterEnum $enumParameter): self + { + $this->enumParameter = $enumParameter; + + return $this; + } + + public function setDateParameter(DateTimeInterface $dateParameter): self + { + $this->dateParameter = $dateParameter; + + return $this; + } + + public function setFloatParameter(float $floatParameter): self + { + $this->floatParameter = $floatParameter; + + return $this; + } + + public function setBooleanParameter(bool $booleanParameter): self + { + $this->booleanParameter = $booleanParameter; + + return $this; + } + + /** + * @param int[] $arrayParameter + */ + public function setArrayParameter(array $arrayParameter): self + { + $this->arrayParameter = $arrayParameter; + + return $this; + } + + public function setObjectParameter(EmbeddedObject $objectParameter): self + { + $this->objectParameter = $objectParameter; + + return $this; + } + + public function setCsrfToken(string $csrfToken): self + { + $this->csrfToken = $csrfToken; + + return $this; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function getRoute(): string + { + return strtr('v1/resources/{resourceId}', ['{resourceId}' => $this->resourceId]); + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter]; + } + + public function getCookies(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['csrf_token' => $this->csrfToken], static function ($value) { + return null !== $value; + })); + } + + public function getHeaders(): array + { + $nonce = bin2hex(random_bytes(16)); + $timestamp = gmdate('c'); + $xwsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->xwsseUsername, base64_encode(sha1($nonce . $timestamp . $this->xwsseSecret)), $nonce, $timestamp); + + return array_merge(['X-WSSE' => $xwsse, 'Content-Type' => $this->contentType->value], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['contentType' => $this->contentType, 'X-Request-ID' => $this->xRequestId], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PostResourceByIdRequestBody + */ + public function getBody() + { + return $this->postResourceByIdRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/PutResourceByIdRequest83.php b/test/suite/functional/Generator/Request/PutResourceByIdRequest83.php new file mode 100644 index 0000000..b38faf8 --- /dev/null +++ b/test/suite/functional/Generator/Request/PutResourceByIdRequest83.php @@ -0,0 +1,174 @@ +contentType; + } + + public function setIntegerParameter(int $integerParameter): self + { + $this->integerParameter = $integerParameter; + + return $this; + } + + public function setStringParameter(string $stringParameter): self + { + $this->stringParameter = $stringParameter; + + return $this; + } + + public function setEnumParameter(EnumParameterEnum $enumParameter): self + { + $this->enumParameter = $enumParameter; + + return $this; + } + + public function setDateParameter(DateTimeInterface $dateParameter): self + { + $this->dateParameter = $dateParameter; + + return $this; + } + + public function setFloatParameter(float $floatParameter): self + { + $this->floatParameter = $floatParameter; + + return $this; + } + + public function setBooleanParameter(bool $booleanParameter): self + { + $this->booleanParameter = $booleanParameter; + + return $this; + } + + /** + * @param int[] $arrayParameter + */ + public function setArrayParameter(array $arrayParameter): self + { + $this->arrayParameter = $arrayParameter; + + return $this; + } + + public function setObjectParameter(EmbeddedObject $objectParameter): self + { + $this->objectParameter = $objectParameter; + + return $this; + } + + public function setCsrfToken(string $csrfToken): self + { + $this->csrfToken = $csrfToken; + + return $this; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function getRoute(): string + { + return strtr('v1/resources/{resourceId}', ['{resourceId}' => $this->resourceId]); + } + + public function getQueryParameters(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter], static function ($value) { + return null !== $value; + })); + } + + public function getRawQueryParameters(): array + { + return ['integerParameter' => $this->integerParameter, 'stringParameter' => $this->stringParameter, 'enumParameter' => $this->enumParameter?->value, 'dateParameter' => $this->dateParameter, 'floatParameter' => $this->floatParameter, 'booleanParameter' => $this->booleanParameter, 'arrayParameter' => $this->arrayParameter, 'objectParameter' => $this->objectParameter, 'mandatoryIntegerParameter' => $this->mandatoryIntegerParameter, 'mandatoryStringParameter' => $this->mandatoryStringParameter, 'mandatoryEnumParameter' => $this->mandatoryEnumParameter->value, 'mandatoryDateParameter' => $this->mandatoryDateParameter, 'mandatoryFloatParameter' => $this->mandatoryFloatParameter, 'mandatoryBooleanParameter' => $this->mandatoryBooleanParameter, 'mandatoryArrayParameter' => $this->mandatoryArrayParameter, 'mandatoryObjectParameter' => $this->mandatoryObjectParameter]; + } + + public function getCookies(): array + { + return array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['csrf_token' => $this->csrfToken], static function ($value) { + return null !== $value; + })); + } + + public function getHeaders(): array + { + $nonce = bin2hex(random_bytes(16)); + $timestamp = gmdate('c'); + $xwsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $this->xwsseUsername, base64_encode(sha1($nonce . $timestamp . $this->xwsseSecret)), $nonce, $timestamp); + + return array_merge(['X-WSSE' => $xwsse, 'Content-Type' => $this->contentType], array_map(static function ($value) { + return $value instanceof SerializableInterface ? $value->toArray() : $value; + }, array_filter(['X-Request-ID' => $this->xRequestId], static function ($value) { + return null !== $value; + }))); + } + + /** + * @return PutResourceByIdRequestBody + */ + public function getBody() + { + return $this->putResourceByIdRequestBody; + } +} diff --git a/test/suite/functional/Generator/Request/postResourceById.yaml b/test/suite/functional/Generator/Request/postResourceById.yaml new file mode 100644 index 0000000..888b891 --- /dev/null +++ b/test/suite/functional/Generator/Request/postResourceById.yaml @@ -0,0 +1,163 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Example API +paths: + '/v1/resources/{resourceId}': + post: + description: Post new resource with id + operationId: postResourceById + security: + - X-WSSE: [] + parameters: + - $ref: '#/components/parameters/ResourceId' + - name: contentType + in: header + required: true + schema: + type: string + enum: + - 'application/json' + - 'application/xml' + - name: integerParameter + in: query + schema: + type: integer + - name: stringParameter + in: query + schema: + type: string + - name: enumParameter + in: query + schema: + type: string + enum: + - 'one value' + - 'another value' + - 'third value' + - name: dateParameter + in: query + schema: + type: string + format: 'date-time' + - name: floatParameter + in: query + schema: + type: number + format: float + - name: booleanParameter + in: query + schema: + type: boolean + - name: arrayParameter + in: query + schema: + type: array + items: + type: integer + - name: objectParameter + in: query + schema: + $ref: '#/components/schemas/EmbeddedObject' + - name: mandatoryIntegerParameter + in: query + required: true + schema: + type: integer + - name: mandatoryStringParameter + in: query + required: true + schema: + type: string + - name: mandatoryEnumParameter + in: query + required: true + schema: + type: string + enum: + - 'one value' + - 'another value' + - 'third value' + - name: mandatoryDateParameter + in: query + required: true + schema: + type: string + format: 'date-time' + - name: mandatoryFloatParameter + in: query + required: true + schema: + type: number + format: float + - name: mandatoryBooleanParameter + in: query + required: true + schema: + type: boolean + - name: mandatoryArrayParameter + in: query + required: true + schema: + type: array + items: + type: integer + - name: mandatoryObjectParameter + in: query + required: true + schema: + $ref: '#/components/schemas/EmbeddedObject' + - in: header + name: X-Request-ID + schema: + type: string + format: uuid + required: true + - in: cookie + name: csrf_token + schema: + type: string + requestBody: + description: New resource. + content: + application/json: + schema: + type: object + properties: + value: + type: integer + required: + - value + application/xml: + schema: + type: object + properties: + value: + type: integer + required: + - value + responses: + '201': + description: Successful operation. +components: + securitySchemes: + X-WSSE: + type: apiKey + in: header + name: X-WSSE + schemas: + EmbeddedObject: + type: object + properties: + string: + type: string + parameters: + ResourceId: + in: path + description: Id of a resource. + required: true + name: resourceId + schema: + type: integer + format: int64 + minimum: 0 diff --git a/test/suite/functional/Generator/RequestGeneratorTest.php b/test/suite/functional/Generator/RequestGeneratorTest.php index 700eea4..b164896 100644 --- a/test/suite/functional/Generator/RequestGeneratorTest.php +++ b/test/suite/functional/Generator/RequestGeneratorTest.php @@ -22,29 +22,29 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', ConfigurationBuilder::fake()->build(), ], - 'Request with body with php 7.4 + api key in query' => [ + 'Request with body with php 8.0 + api key in header' => [ '/Request/patchResource.yaml', - '/Request/PatchSubResourceRequest74.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', - ConfigurationBuilder::fake()->build(), + '/Request/PatchResourceRequest80.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), ], - 'Request with body with php 7.4 + query params + api key in query' => [ + 'Request with body with php 8.1 + api key in header' => [ '/Request/patchResource.yaml', - '/Request/PatchYetAnotherSubResourceRequest74.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', - ConfigurationBuilder::fake()->build(), + '/Request/PatchResourceRequest81.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], - 'Request with body with php 7.4 + api key in cookie' => [ + 'Request with body with php 8.3 + api key in header' => [ '/Request/patchResource.yaml', - '/Request/PatchAnotherSubResourceRequest74.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', - ConfigurationBuilder::fake()->build(), + '/Request/PatchResourceRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), ], - 'Request with body with php 8.0 + api key in header' => [ + 'Request with body with php 7.4 + api key in query' => [ '/Request/patchResource.yaml', - '/Request/PatchResourceRequest80.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', - ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), + '/Request/PatchSubResourceRequest74.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', + ConfigurationBuilder::fake()->build(), ], 'Request with body with php 8.0 + api key in query' => [ '/Request/patchResource.yaml', @@ -52,29 +52,29 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), ], - 'Request with body with php 8.0 + query params + api key in query' => [ + 'Request with body with php 8.1 + api key in query' => [ '/Request/patchResource.yaml', - '/Request/PatchYetAnotherSubResourceRequest80.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', - ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), + '/Request/PatchSubResourceRequest81.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], - 'Request with body with php 8.0 + api key in cookie' => [ + 'Request with body with php 8.3 + api key in query' => [ '/Request/patchResource.yaml', - '/Request/PatchAnotherSubResourceRequest80.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', - ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), + '/Request/PatchSubResourceRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), ], - 'Request with body with php 8.1 + api key in header' => [ + 'Request with body with php 7.4 + query params + api key in query' => [ '/Request/patchResource.yaml', - '/Request/PatchResourceRequest81.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchResourceRequest', - ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), + '/Request/PatchYetAnotherSubResourceRequest74.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', + ConfigurationBuilder::fake()->build(), ], - 'Request with body with php 8.1 + api key in query' => [ + 'Request with body with php 8.0 + query params + api key in query' => [ '/Request/patchResource.yaml', - '/Request/PatchSubResourceRequest81.php', - self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchSubResourceRequest', - ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), + '/Request/PatchYetAnotherSubResourceRequest80.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), ], 'Request with body with php 8.1 + query params + api key in query' => [ '/Request/patchResource.yaml', @@ -82,12 +82,36 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request with body with php 8.3 + query params + api key in query' => [ + '/Request/patchResource.yaml', + '/Request/PatchYetAnotherSubResourceRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchYetAnotherSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], + 'Request with body with php 7.4 + api key in cookie' => [ + '/Request/patchResource.yaml', + '/Request/PatchAnotherSubResourceRequest74.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', + ConfigurationBuilder::fake()->build(), + ], + 'Request with body with php 8.0 + api key in cookie' => [ + '/Request/patchResource.yaml', + '/Request/PatchAnotherSubResourceRequest80.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), + ], 'Request with body with php 8.1 + api key in cookie' => [ '/Request/patchResource.yaml', '/Request/PatchAnotherSubResourceRequest81.php', self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request with body with php 8.3 + api key in cookie' => [ + '/Request/patchResource.yaml', + '/Request/PatchAnotherSubResourceRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PatchAnotherSubResourceRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], 'Request with mandatory parameters and body with php 7.4' => [ '/Request/putResourceById.yaml', '/Request/PutResourceByIdRequest74.php', @@ -106,6 +130,12 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PutResourceByIdRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request with mandatory parameters and body with php 8.3' => [ + '/Request/putResourceById.yaml', + '/Request/PutResourceByIdRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PutResourceByIdRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], 'Request without mandatory parameters and body with php 7.4' => [ '/Request/getResources.yaml', '/Request/GetResourcesRequest74.php', @@ -124,6 +154,12 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetResourcesRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request without mandatory parameters and body with php 8.3' => [ + '/Request/getResources.yaml', + '/Request/GetResourcesRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetResourcesRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], 'Request with same parameter name but different parameters with php 7.4' => [ '/Request/getResources.yaml', '/Request/GetSubResourcesRequest74.php', @@ -142,6 +178,12 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetSubResourcesRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request with same parameter name but different parameters with php 8.3' => [ + '/Request/getResources.yaml', + '/Request/GetSubResourcesRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetSubResourcesRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], 'Request with enum path parameter and php 7.4' => [ '/Request/getResourceByType.yaml', '/Request/GetResourceByTypeRequest74.php', @@ -160,6 +202,36 @@ public function exampleProvider(): array self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetResourceByTypeRequest', ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), ], + 'Request with enum path parameter and php 8.3' => [ + '/Request/getResourceByType.yaml', + '/Request/GetResourceByTypeRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\GetResourceByTypeRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], + 'Request with content type enum header parameters and body with php 7.4' => [ + '/Request/postResourceById.yaml', + '/Request/PostResourceByIdRequest74.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PostResourceByIdRequest', + ConfigurationBuilder::fake()->build(), + ], + 'Request with content type enum header parameters and body with php 8.0' => [ + '/Request/postResourceById.yaml', + '/Request/PostResourceByIdRequest80.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PostResourceByIdRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(), + ], + 'Request with content type enum header parameters and body with php 8.1' => [ + '/Request/postResourceById.yaml', + '/Request/PostResourceByIdRequest81.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PostResourceByIdRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP81)->build(), + ], + 'Request with content type enum header parameters and body with php 8.3' => [ + '/Request/postResourceById.yaml', + '/Request/PostResourceByIdRequest83.php', + self::BASE_NAMESPACE . RequestGenerator::NAMESPACE_SUBPATH . '\\PostResourceByIdRequest', + ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP83)->build(), + ], ]; }