diff --git a/src/Generator/Client/Dto/Operation.php b/src/Generator/Client/Dto/Operation.php index 3ff9cee..d597d4a 100644 --- a/src/Generator/Client/Dto/Operation.php +++ b/src/Generator/Client/Dto/Operation.php @@ -42,6 +42,7 @@ public function __construct( public array $queryStructNames, public ?string $bodyName, public ?string $bodyContentType, + public ?string $bodyContentShape, public array $imports, ) { diff --git a/src/Generator/Client/Dto/Response.php b/src/Generator/Client/Dto/Response.php index f421d7a..d8ada11 100644 --- a/src/Generator/Client/Dto/Response.php +++ b/src/Generator/Client/Dto/Response.php @@ -35,6 +35,7 @@ public function __construct( public ?string $className = null, public ?Type $innerSchema = null, public ?string $contentType = null, + public ?string $contentShape = null, ) { } diff --git a/src/Generator/Client/Language/php-operation.php.twig b/src/Generator/Client/Language/php-operation.php.twig index d9676b0..033bd12 100644 --- a/src/Generator/Client/Language/php-operation.php.twig +++ b/src/Generator/Client/Language/php-operation.php.twig @@ -24,6 +24,8 @@ 'headers' => [ {% if operation.bodyContentType %} 'Content-Type' => '{{ operation.bodyContentType }}', +{% elseif operation.bodyName %} + 'Content-Type' => 'application/json' {% endif %} ], 'query' => $this->parser->query([ @@ -36,14 +38,12 @@ {% endfor %} ]), {% if operation.bodyName %} -{% if operation.bodyContentType == 'application/octet-stream' or operation.bodyContentType == 'text/plain' %} +{% if operation.bodyContentShape == 'application/octet-stream' or operation.bodyContentShape == 'application/xml' or operation.bodyContentShape == 'text/plain' %} 'body' => ${{ operation.bodyName }} -{% elseif operation.bodyContentType == 'application/x-www-form-urlencoded' %} +{% elseif operation.bodyContentShape == 'application/x-www-form-urlencoded' %} 'form_params' => ${{ operation.bodyName }} -{% elseif operation.bodyContentType == 'multipart/form-data' %} +{% elseif operation.bodyContentShape == 'multipart/form-data' %} 'multipart' => ${{ operation.bodyName }} -{% elseif operation.bodyContentType == 'application/xml' %} - 'body' => ${{ operation.bodyName }}->saveXML() {% else %} 'json' => ${{ operation.bodyName }} {% endif %} @@ -80,21 +80,18 @@ {% endfor %} {% macro response(payload, in_throw) %} -{% if payload.contentType == 'application/octet-stream' %} +{% if payload.contentShape == 'application/octet-stream' %} {% if in_throw %} {% endif %}$data = $body; -{% elseif payload.contentType == 'application/x-www-form-urlencoded' %} +{% elseif payload.contentShape == 'application/x-www-form-urlencoded' %} {% if in_throw %} {% endif %}$data = []; {% if in_throw %} {% endif %}parse_str((string) $body, $data); -{% elseif payload.contentType == 'application/json' %} +{% elseif payload.contentShape == 'application/json' %} {% if in_throw %} {% endif %}$data = \json_decode((string) $body); -{% elseif payload.contentType == 'multipart/form-data' %} +{% elseif payload.contentShape == 'multipart/form-data' %} {% if in_throw %} {% endif %}// @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed {% if in_throw %} {% endif %}$data = []; -{% elseif payload.contentType == 'text/plain' %} +{% elseif payload.contentShape == 'text/plain' or payload.contentShape == 'application/xml' %} {% if in_throw %} {% endif %}$data = (string) $body; -{% elseif payload.contentType == 'application/xml' %} - {% if in_throw %} {% endif %}$data = new \DOMDocument(); - {% if in_throw %} {% endif %}$data->loadXML((string) $body); {% else %} {% if payload.innerSchema.isMap %} {% if in_throw %} {% endif %}$data = $this->parser->parse((string) $body, {{ payload.innerSchema.type }}::class, isMap: true); diff --git a/src/Generator/Client/Language/typescript-operation.ts.twig b/src/Generator/Client/Language/typescript-operation.ts.twig index 606cf7d..81ea649 100644 --- a/src/Generator/Client/Language/typescript-operation.ts.twig +++ b/src/Generator/Client/Language/typescript-operation.ts.twig @@ -23,6 +23,8 @@ headers: { {% if operation.bodyContentType %} 'Content-Type': '{{ operation.bodyContentType }}', +{% elseif operation.bodyName %} + 'Content-Type': 'application/json', {% endif %} }, params: this.parser.query({ @@ -34,14 +36,12 @@ '{{ realName }}', {% endfor %} ]), -{% if operation.return.contentType == 'application/octet-stream' %} +{% if operation.return.contentShape == 'application/octet-stream' %} responseType: 'arraybuffer', -{% elseif operation.return.contentType == 'application/json' %} +{% elseif operation.return.contentShape == 'application/json' %} responseType: 'json', -{% elseif operation.return.contentType == 'text/plain' %} +{% elseif operation.return.contentShape == 'text/plain' or operation.return.contentShape == 'application/xml' %} responseType: 'text', -{% elseif operation.return.contentType == 'application/xml' %} - responseType: 'document', {% endif %} {% if operation.bodyName %} data: {{ operation.bodyName }} diff --git a/src/Generator/Client/LanguageBuilder.php b/src/Generator/Client/LanguageBuilder.php index ef818ba..9f6ffec 100644 --- a/src/Generator/Client/LanguageBuilder.php +++ b/src/Generator/Client/LanguageBuilder.php @@ -150,7 +150,7 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $imports = []; $path = $pathNames = []; $query = $queryNames = $queryStructNames = []; - $body = $bodyName = $bodyContentType = null; + $body = $bodyName = $bodyContentType = $bodyContentShape = null; foreach ($operation->getArguments()->getAll() as $name => $argument) { $realName = $argument->getName(); if (empty($realName)) { @@ -172,7 +172,8 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $bodyName = $normalized; if ($argument->getSchema() instanceof ContentType) { - $bodyContentType = $argument->getSchema()->value; + $bodyContentType = $argument->getSchema()->toString(); + $bodyContentShape = $argument->getSchema()->getShape(); } } @@ -185,6 +186,7 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $body = null; $bodyName = null; $bodyContentType = null; + $bodyContentShape = null; } $arguments = array_merge($path, $body !== null ? [$bodyName => $body] : [], $query); @@ -195,7 +197,14 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $returnType = $this->newType($returnSchema, false, $definitions, Type\GeneratorInterface::CONTEXT_CLIENT | Type\GeneratorInterface::CONTEXT_RESPONSE); $innerSchema = $returnSchema instanceof TypeInterface ? $this->getInnerSchema($returnSchema, $definitions) : null; - $return = new Dto\Response($operation->getReturn()->getCode(), $returnType, null, $innerSchema, $returnSchema instanceof ContentType ? $returnSchema->value : null); + $return = new Dto\Response( + $operation->getReturn()->getCode(), + $returnType, + null, + $innerSchema, + $returnSchema instanceof ContentType ? $returnSchema->toString() : null, + $returnSchema instanceof ContentType ? $returnSchema->getShape() : null, + ); if ($returnSchema instanceof TypeInterface) { $this->resolveImport($returnSchema, $imports); @@ -217,7 +226,14 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $exceptionClassName = $this->naming->buildExceptionClassNameByType($throwSchema); $exceptions[$exceptionClassName] = new Dto\Exception($exceptionClassName, $exceptionType, 'The server returned an error', $exceptionImports); - $throws[$throw->getCode()] = new Dto\Response($throw->getCode(), $exceptionType, $exceptionClassName, $innerSchema, $throwSchema instanceof ContentType ? $throwSchema->value : null); + $throws[$throw->getCode()] = new Dto\Response( + $throw->getCode(), + $exceptionType, + $exceptionClassName, + $innerSchema, + $throwSchema instanceof ContentType ? $throwSchema->toString() : null, + $throwSchema instanceof ContentType ? $throwSchema->getShape() : null, + ); $imports[$this->normalizer->file($exceptionClassName)] = $exceptionClassName; } @@ -235,6 +251,7 @@ private function getOperations(array $operations, DefinitionsInterface $definiti $queryStructNames, $bodyName, $bodyContentType, + $bodyContentShape, $imports ); } diff --git a/src/Generator/Client/Util/Naming.php b/src/Generator/Client/Util/Naming.php index b80a4df..52426b8 100644 --- a/src/Generator/Client/Util/Naming.php +++ b/src/Generator/Client/Util/Naming.php @@ -58,7 +58,7 @@ public function buildMethodNameByTag(string $tagName): string public function buildExceptionClassNameByType(TypeInterface|ContentType $type): string { if ($type instanceof ContentType) { - return match ($type) { + return match ($type->getShape()) { ContentType::BINARY => 'BinaryException', ContentType::FORM => 'FormException', ContentType::JSON => 'JsonException', diff --git a/src/Parser/Attribute.php b/src/Parser/Attribute.php index b21ac18..41a677a 100644 --- a/src/Parser/Attribute.php +++ b/src/Parser/Attribute.php @@ -360,18 +360,16 @@ private function getSchemaFromTypeHint(?\ReflectionType $type): string|ContentTy if ($type instanceof \ReflectionNamedType) { if ($type->getName() === 'mixed') { return Passthru::class; - } elseif ($type->getName() === \DOMDocument::class) { - return ContentType::XML; } elseif ($type->getName() === StreamInterface::class) { - return ContentType::BINARY; + return new ContentType(ContentType::BINARY); } elseif ($type->getName() === 'string') { - return ContentType::TEXT; + return new ContentType(ContentType::TEXT); } elseif ($type->getName() === 'PSX\\Data\\Body\\Json') { - return ContentType::JSON; + return new ContentType(ContentType::JSON); } elseif ($type->getName() === 'PSX\\Data\\Body\\Multipart') { - return ContentType::MULTIPART; + return new ContentType(ContentType::MULTIPART); } elseif ($type->getName() === 'PSX\\Data\\Body\\Form') { - return ContentType::FORM; + return new ContentType(ContentType::FORM); } elseif (class_exists($type->getName())) { return $type->getName(); } diff --git a/src/Parser/TypeAPI.php b/src/Parser/TypeAPI.php index 670f882..fe020a3 100644 --- a/src/Parser/TypeAPI.php +++ b/src/Parser/TypeAPI.php @@ -216,7 +216,7 @@ private function parseArgument(\stdClass $data): Operation\Argument } $contentType = $data->contentType ?? null; - if (is_string($contentType)) { + if (is_string($contentType) && !empty($contentType)) { $type = ContentType::from($contentType); } else { $schema = $data->schema ?? null; diff --git a/tests/Generator/Client/resource/php/Client.php b/tests/Generator/Client/resource/php/Client.php index 201d2ac..ff3ad54 100644 --- a/tests/Generator/Client/resource/php/Client.php +++ b/tests/Generator/Client/resource/php/Client.php @@ -88,6 +88,7 @@ public function create(string $name, string $type, EntryCreate $payload): EntryM $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ @@ -144,6 +145,7 @@ public function update(string $name, string $type, \PSX\Record\Record $payload): $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ @@ -237,6 +239,7 @@ public function patch(string $name, string $type, array $payload): array $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_collection/BarTag.php b/tests/Generator/Client/resource/php_collection/BarTag.php index 0bb0ded..98044df 100644 --- a/tests/Generator/Client/resource/php_collection/BarTag.php +++ b/tests/Generator/Client/resource/php_collection/BarTag.php @@ -66,6 +66,7 @@ public function put(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_collection/FooBarTag.php b/tests/Generator/Client/resource/php_collection/FooBarTag.php index 9b59b39..ea20345 100644 --- a/tests/Generator/Client/resource/php_collection/FooBarTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBarTag.php @@ -65,6 +65,7 @@ public function create(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_collection/FooBazTag.php b/tests/Generator/Client/resource/php_collection/FooBazTag.php index 783b398..7e86da8 100644 --- a/tests/Generator/Client/resource/php_collection/FooBazTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBazTag.php @@ -66,6 +66,7 @@ public function create(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_content_type/Client.php b/tests/Generator/Client/resource/php_content_type/Client.php index 2128802..a1e0ef9 100644 --- a/tests/Generator/Client/resource/php_content_type/Client.php +++ b/tests/Generator/Client/resource/php_content_type/Client.php @@ -252,12 +252,12 @@ public function text(string $body): string } /** - * @param \DOMDocument $body - * @return \DOMDocument + * @param string $body + * @return string * @throws XmlException * @throws ClientException */ - public function xml(\DOMDocument $body): \DOMDocument + public function xml(string $body): string { $url = $this->parser->url('/xml', [ ]); @@ -269,15 +269,14 @@ public function xml(\DOMDocument $body): \DOMDocument 'query' => $this->parser->query([ ], [ ]), - 'body' => $body->saveXML() + 'body' => $body ]; try { $response = $this->httpClient->request('POST', $url, $options); $body = $response->getBody(); - $data = new \DOMDocument(); - $data->loadXML((string) $body); + $data = (string) $body; return $data; } catch (ClientException $e) { @@ -287,8 +286,7 @@ public function xml(\DOMDocument $body): \DOMDocument $statusCode = $e->getResponse()->getStatusCode(); if ($statusCode === 500) { - $data = new \DOMDocument(); - $data->loadXML((string) $body); + $data = (string) $body; throw new XmlException($data); } diff --git a/tests/Generator/Client/resource/php_content_type/XmlException.php b/tests/Generator/Client/resource/php_content_type/XmlException.php index 195076d..b823f85 100644 --- a/tests/Generator/Client/resource/php_content_type/XmlException.php +++ b/tests/Generator/Client/resource/php_content_type/XmlException.php @@ -10,9 +10,9 @@ class XmlException extends KnownStatusCodeException { - private \DOMDocument $payload; + private string $payload; - public function __construct(\DOMDocument $payload) + public function __construct(string $payload) { parent::__construct('The server returned an error'); @@ -20,9 +20,9 @@ public function __construct(\DOMDocument $payload) } /** - * @return \DOMDocument + * @return string */ - public function getPayload(): \DOMDocument + public function getPayload(): string { return $this->payload; } diff --git a/tests/Generator/Client/resource/php_test/ProductTag.php b/tests/Generator/Client/resource/php_test/ProductTag.php index 51edae8..0356e7c 100644 --- a/tests/Generator/Client/resource/php_test/ProductTag.php +++ b/tests/Generator/Client/resource/php_test/ProductTag.php @@ -72,6 +72,7 @@ public function create(TestRequest $payload): TestResponse $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ @@ -114,6 +115,7 @@ public function update(int $id, TestRequest $payload): TestResponse $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ @@ -156,6 +158,7 @@ public function patch(int $id, TestRequest $payload): TestResponse $options = [ 'headers' => [ + 'Content-Type' => 'application/json' ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/typescript/Client.ts b/tests/Generator/Client/resource/typescript/Client.ts index 4178423..89fe743 100644 --- a/tests/Generator/Client/resource/typescript/Client.ts +++ b/tests/Generator/Client/resource/typescript/Client.ts @@ -80,6 +80,7 @@ export class Client extends ClientAbstract { url: url, method: 'POST', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ @@ -127,6 +128,7 @@ export class Client extends ClientAbstract { url: url, method: 'PUT', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ @@ -209,6 +211,7 @@ export class Client extends ClientAbstract { url: url, method: 'PATCH', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_collection/BarTag.ts b/tests/Generator/Client/resource/typescript_collection/BarTag.ts index c74c137..57bfda9 100644 --- a/tests/Generator/Client/resource/typescript_collection/BarTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/BarTag.ts @@ -61,6 +61,7 @@ export class BarTag extends TagAbstract { url: url, method: 'POST', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts b/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts index 7515f6a..c2f895f 100644 --- a/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/FooBarTag.ts @@ -62,6 +62,7 @@ export class FooBarTag extends TagAbstract { url: url, method: 'POST', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts b/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts index 5fa0678..5398d23 100644 --- a/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts +++ b/tests/Generator/Client/resource/typescript_collection/FooBazTag.ts @@ -61,6 +61,7 @@ export class FooBazTag extends TagAbstract { url: url, method: 'POST', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_content_type/Client.ts b/tests/Generator/Client/resource/typescript_content_type/Client.ts index 0303723..aebd6e8 100644 --- a/tests/Generator/Client/resource/typescript_content_type/Client.ts +++ b/tests/Generator/Client/resource/typescript_content_type/Client.ts @@ -225,11 +225,11 @@ export class Client extends ClientAbstract { } /** - * @returns {Promise} + * @returns {Promise} * @throws {XmlException} * @throws {ClientException} */ - public async xml(body: XMLDocument): Promise { + public async xml(body: string): Promise { const url = this.parser.url('/xml', { }); @@ -242,12 +242,12 @@ export class Client extends ClientAbstract { params: this.parser.query({ }, [ ]), - responseType: 'document', + responseType: 'text', data: body }; try { - const response = await this.httpClient.request(params); + const response = await this.httpClient.request(params); return response.data; } catch (error) { if (error instanceof ClientException) { diff --git a/tests/Generator/Client/resource/typescript_content_type/XmlException.ts b/tests/Generator/Client/resource/typescript_content_type/XmlException.ts index 8076033..747b495 100644 --- a/tests/Generator/Client/resource/typescript_content_type/XmlException.ts +++ b/tests/Generator/Client/resource/typescript_content_type/XmlException.ts @@ -8,11 +8,11 @@ import {KnownStatusCodeException} from "sdkgen-client" export class XmlException extends KnownStatusCodeException { - public constructor(private payload: XMLDocument) { + public constructor(private payload: string) { super('The server returned an error'); } - public getPayload(): XMLDocument { + public getPayload(): string { return this.payload; } diff --git a/tests/Generator/Client/resource/typescript_test/ProductTag.ts b/tests/Generator/Client/resource/typescript_test/ProductTag.ts index 882554e..1af2797 100644 --- a/tests/Generator/Client/resource/typescript_test/ProductTag.ts +++ b/tests/Generator/Client/resource/typescript_test/ProductTag.ts @@ -64,6 +64,7 @@ export class ProductTag extends TagAbstract { url: url, method: 'POST', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ @@ -102,6 +103,7 @@ export class ProductTag extends TagAbstract { url: url, method: 'PUT', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ @@ -140,6 +142,7 @@ export class ProductTag extends TagAbstract { url: url, method: 'PATCH', headers: { + 'Content-Type': 'application/json', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/GeneratorTestCase.php b/tests/Generator/GeneratorTestCase.php index c4496f5..81833e6 100644 --- a/tests/Generator/GeneratorTestCase.php +++ b/tests/Generator/GeneratorTestCase.php @@ -201,29 +201,29 @@ protected function getSpecificationContentType(): SpecificationInterface { $builder = $this->apiManager->getBuilder(); - $operation = $builder->addOperation('binary', 'POST', '/binary', 200, ContentType::BINARY); - $operation->addArgument('body', 'body', ContentType::BINARY); - $operation->addThrow(999, ContentType::BINARY); + $operation = $builder->addOperation('binary', 'POST', '/binary', 200, new ContentType(ContentType::BINARY)); + $operation->addArgument('body', 'body', new ContentType(ContentType::BINARY)); + $operation->addThrow(999, new ContentType(ContentType::BINARY)); - $operation = $builder->addOperation('form', 'POST', '/form', 200, ContentType::FORM); - $operation->addArgument('body', 'body', ContentType::FORM); - $operation->addThrow(599, ContentType::FORM); + $operation = $builder->addOperation('form', 'POST', '/form', 200, new ContentType(ContentType::FORM)); + $operation->addArgument('body', 'body', new ContentType(ContentType::FORM)); + $operation->addThrow(599, new ContentType(ContentType::FORM)); - $operation = $builder->addOperation('json', 'POST', '/json', 200, ContentType::JSON); - $operation->addArgument('body', 'body', ContentType::JSON); - $operation->addThrow(499, ContentType::JSON); + $operation = $builder->addOperation('json', 'POST', '/json', 200, new ContentType(ContentType::JSON)); + $operation->addArgument('body', 'body', new ContentType(ContentType::JSON)); + $operation->addThrow(499, new ContentType(ContentType::JSON)); - $operation = $builder->addOperation('multipart', 'POST', '/multipart', 200, ContentType::MULTIPART); - $operation->addArgument('body', 'body', ContentType::MULTIPART); - $operation->addThrow(500, ContentType::MULTIPART); + $operation = $builder->addOperation('multipart', 'POST', '/multipart', 200, new ContentType(ContentType::MULTIPART)); + $operation->addArgument('body', 'body', new ContentType(ContentType::MULTIPART)); + $operation->addThrow(500, new ContentType(ContentType::MULTIPART)); - $operation = $builder->addOperation('text', 'POST', '/text', 200, ContentType::TEXT); - $operation->addArgument('body', 'body', ContentType::TEXT); - $operation->addThrow(500, ContentType::TEXT); + $operation = $builder->addOperation('text', 'POST', '/text', 200, new ContentType(ContentType::TEXT)); + $operation->addArgument('body', 'body', new ContentType(ContentType::TEXT)); + $operation->addThrow(500, new ContentType(ContentType::TEXT)); - $operation = $builder->addOperation('xml', 'POST', '/xml', 200, ContentType::XML); - $operation->addArgument('body', 'body', ContentType::XML); - $operation->addThrow(500, ContentType::XML); + $operation = $builder->addOperation('xml', 'POST', '/xml', 200, new ContentType(ContentType::XML)); + $operation->addArgument('body', 'body', new ContentType(ContentType::XML)); + $operation->addThrow(500, new ContentType(ContentType::XML)); return $builder->getSpecification(); } diff --git a/tests/Generator/Server/resource/php_content_type/src/Controller/App.php b/tests/Generator/Server/resource/php_content_type/src/Controller/App.php index 2b1103a..f46380a 100644 --- a/tests/Generator/Server/resource/php_content_type/src/Controller/App.php +++ b/tests/Generator/Server/resource/php_content_type/src/Controller/App.php @@ -64,7 +64,7 @@ public function text(#[Body] string $body): string #[Post] #[Path('/xml')] #[StatusCode(200)] - public function xml(#[Body] \DOMDocument $body): \DOMDocument + public function xml(#[Body] string $body): string { // @TODO implement method } diff --git a/tests/Generator/Server/resource/typescript_content_type/src/controller/app.controller.ts b/tests/Generator/Server/resource/typescript_content_type/src/controller/app.controller.ts index 944c6f7..f9f8644 100644 --- a/tests/Generator/Server/resource/typescript_content_type/src/controller/app.controller.ts +++ b/tests/Generator/Server/resource/typescript_content_type/src/controller/app.controller.ts @@ -44,7 +44,7 @@ export class AppController { @Post('/xml') @HttpCode(200) - xml(@Body() body: XMLDocument): XMLDocument { + xml(@Body() body: string): string { // @TODO implement method return {}; } diff --git a/tests/Parser/Attribute/ContentTypeController.php b/tests/Parser/Attribute/ContentTypeController.php index bb8c4cd..bb92251 100644 --- a/tests/Parser/Attribute/ContentTypeController.php +++ b/tests/Parser/Attribute/ContentTypeController.php @@ -78,12 +78,4 @@ protected function json(#[Body] Json $body): Json { return $body; } - - #[Post] - #[Path('/xml')] - #[OperationId('xml')] - protected function xml(#[Body] \DOMDocument $body): \DOMDocument - { - return new \DOMDocument(); - } } diff --git a/tests/Parser/AttributeTest.php b/tests/Parser/AttributeTest.php index a5a82d6..5a028ff 100644 --- a/tests/Parser/AttributeTest.php +++ b/tests/Parser/AttributeTest.php @@ -121,10 +121,5 @@ public function testParseContentType() $this->assertInstanceOf(OperationInterface::class, $operation); $this->assertEquals(ContentType::JSON, $operation->getArguments()->get('body')->getSchema()); $this->assertEquals(ContentType::JSON, $operation->getReturn()->getSchema()); - - $operation = $specification->getOperations()->get('xml'); - $this->assertInstanceOf(OperationInterface::class, $operation); - $this->assertEquals(ContentType::XML, $operation->getArguments()->get('body')->getSchema()); - $this->assertEquals(ContentType::XML, $operation->getReturn()->getSchema()); } }