From 56e5f45c8e23a21d591e904f86eb54778b88520f Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sun, 18 Aug 2024 20:46:56 +0200 Subject: [PATCH] update server gen --- src/Generator/Server/PHP.php | 146 +++++++++++------- src/Generator/Server/ServerAbstract.php | 82 +++++++++- src/Generator/Server/TypeScript.php | 98 +++++++----- .../resource/php/src/Controller/App.php | 96 ++++++++---- .../Server/resource/php/src/Model/Entry.php | 8 + .../php/src/Model/EntryCollection.php | 9 ++ .../resource/php/src/Model/EntryCreate.php | 8 + .../resource/php/src/Model/EntryDelete.php | 8 + .../resource/php/src/Model/EntryMessage.php | 9 ++ .../resource/php/src/Model/EntryPatch.php | 8 + .../resource/php/src/Model/EntryUpdate.php | 8 + .../php_complex/src/Controller/Bar.php | 45 ++++-- .../php_complex/src/Controller/Foo/Bar.php | 45 ++++-- .../php_complex/src/Controller/Foo/Baz.php | 45 ++++-- .../resource/php_complex/src/Model/Entry.php | 8 + .../php_complex/src/Model/EntryCollection.php | 9 ++ .../php_complex/src/Model/EntryCreate.php | 8 + .../php_complex/src/Model/EntryMessage.php | 9 ++ .../src/controller/app.controller.ts | 24 ++- .../resource/typescript/src/dto/Entry.ts | 5 + .../typescript/src/dto/EntryCollection.ts | 5 + .../typescript/src/dto/EntryCreate.ts | 5 + .../typescript/src/dto/EntryDelete.ts | 5 + .../typescript/src/dto/EntryMessage.ts | 5 + .../resource/typescript/src/dto/EntryPatch.ts | 5 + .../typescript/src/dto/EntryUpdate.ts | 5 + .../src/controller/bar.controller.ts | 12 +- .../src/controller/foo/bar.controller.ts | 12 +- .../src/controller/foo/baz.controller.ts | 12 +- .../typescript_complex/src/dto/Entry.ts | 5 + .../src/dto/EntryCollection.ts | 5 + .../typescript_complex/src/dto/EntryCreate.ts | 5 + .../src/dto/EntryMessage.ts | 5 + 33 files changed, 583 insertions(+), 181 deletions(-) diff --git a/src/Generator/Server/PHP.php b/src/Generator/Server/PHP.php index 89b0e42c..0870588e 100644 --- a/src/Generator/Server/PHP.php +++ b/src/Generator/Server/PHP.php @@ -21,8 +21,7 @@ namespace PSX\Api\Generator\Server; use PSX\Api\Generator\Server\Dto\File; -use PSX\Api\Operation\ArgumentInterface; -use PSX\Api\SpecificationInterface; +use PSX\Api\OperationInterface; use PSX\Schema\Generator; use PSX\Schema\GeneratorInterface as SchemaGeneratorInterface; @@ -37,7 +36,10 @@ class PHP extends ServerAbstract { protected function newGenerator(): SchemaGeneratorInterface { - return new Generator\Php(); + $config = new Generator\Config(); + $config->put(Generator\Config::NAMESPACE, 'App\\Model'); + + return new Generator\Php($config); } protected function getControllerPath(): string @@ -50,82 +52,112 @@ protected function getModelPath(): string return 'src/Model'; } - protected function buildControllerFileName(string $name): string + protected function getFileExtension(): string { - return $this->normalizer->file($name); + return 'php'; } - protected function buildFolderName(string $name): string + protected function getFileContent(string $code, string $identifier): string + { + $comment = '/**' . "\n"; + $comment.= ' * ' . $identifier . ' automatically generated by SDKgen please do not edit this file manually' . "\n"; + $comment.= ' * @see https://sdkgen.app' . "\n"; + $comment.= ' */' . "\n"; + + return 'normalizer->file($name); } - protected function getFileExtension(): string + protected function buildFolderName(string $name): string { - return 'php'; + return $this->normalizer->file($name); } - protected function generateControllerFile(File $file, SpecificationInterface $specification): string + protected function generateHeader(File $file, array $imports): string { - $controllerClass = $this->buildControllerClass($file); + $controllerClass = $this->normalizer->class($file->getName()); - $controller = 'getOperations() as $operationName => $operation) { - $method = ucfirst(strtolower($operation->getMethod())); - - $args = []; - foreach ($operation->getArguments()->getAll() as $argumentName => $argument) { - $rawName = $argumentName; - $variableName = $this->normalizer->argument($argumentName); - $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); - - if ($argument->getIn() === ArgumentInterface::IN_PATH) { - if ($rawName === $variableName) { - $args[] = '#[Param] ' . $type->type . ' $' . $variableName; - } else { - $args[] = '#[Param(\'' . $rawName . '\')] ' . $type->type . ' $' . $variableName; - } - } elseif ($argument->getIn() === ArgumentInterface::IN_QUERY) { - if ($rawName === $variableName) { - $args[] = '#[Query] ' . $type->type . ' $' . $variableName; - } else { - $args[] = '#[Query(\'' . $rawName . '\')] ' . $type->type . ' $' . $variableName; - } - } elseif ($argument->getIn() === ArgumentInterface::IN_HEADER) { - if ($rawName === $variableName) { - $args[] = '#[Header] ' . $type->type . ' $' . $variableName; - } else { - $args[] = '#[Header(\'' . $rawName . '\')] ' . $type->type . ' $' . $variableName; - } - } elseif ($argument->getIn() === ArgumentInterface::IN_BODY) { - $args[] = '#[Body] ' . $type->type . ' $' . $variableName; - } - } - - $type = $this->newType($operation->getReturn()->getSchema(), $specification->getDefinitions()); - - $controller.= ' #[' . $method . ']' . "\n"; - $controller.= ' #[Path(\'' . $operation->getPath() . '\')]' . "\n"; - $controller.= ' #[StatusCode(' . $operation->getReturn()->getCode() . ')]' . "\n"; - $controller.= ' public function ' . $operationName . '(' . implode(', ', $args) . '): ' . $type->type . ' {' . "\n"; - $controller.= ' // @TODO implement method' . "\n"; - $controller.= ' }' . "\n"; - $controller.= "\n"; - } + return $controller; + } - $controller.= '}' . "\n"; + protected function generateFooter(File $file): string + { + $controller = '}' . "\n"; return $controller; } - private function buildControllerClass(File $file): string + protected function generateArgumentPath(string $rawName, string $variableName, string $type): string + { + if ($rawName === $variableName) { + return '#[Param] ' . $type . ' $' . $variableName; + } else { + return '#[Param(\'' . $rawName . '\')] ' . $type . ' $' . $variableName; + } + } + + protected function generateArgumentQuery(string $rawName, string $variableName, string $type): string + { + if ($rawName === $variableName) { + return '#[Query] ' . $type . ' $' . $variableName; + } else { + return '#[Query(\'' . $rawName . '\')] ' . $type . ' $' . $variableName; + } + } + + protected function generateArgumentHeader(string $rawName, string $variableName, string $type): string + { + if ($rawName === $variableName) { + return '#[Header] ' . $type . ' $' . $variableName; + } else { + return '#[Header(\'' . $rawName . '\')] ' . $type . ' $' . $variableName; + } + } + + protected function generateArgumentBody(string $variableName, string $type): string + { + return '#[Body] ' . $type . ' $' . $variableName; + } + + protected function generateMethod(string $operationName, OperationInterface $operation, array $arguments, string $returnType): string { - return $this->normalizer->class($file->getName()); + $methodName = ucfirst(strtolower($operation->getMethod())); + + $method = ' #[' . $methodName . ']' . "\n"; + $method.= ' #[Path(\'' . $operation->getPath() . '\')]' . "\n"; + $method.= ' #[StatusCode(' . $operation->getReturn()->getCode() . ')]' . "\n"; + $method.= ' public function ' . $operationName . '(' . implode(', ', $arguments) . '): ' . $returnType . "\n"; + $method.= ' {' . "\n"; + $method.= ' // @TODO implement method' . "\n"; + $method.= ' }' . "\n"; + $method.= "\n"; + + return $method; } } diff --git a/src/Generator/Server/ServerAbstract.php b/src/Generator/Server/ServerAbstract.php index a6459277..554af7e2 100644 --- a/src/Generator/Server/ServerAbstract.php +++ b/src/Generator/Server/ServerAbstract.php @@ -26,6 +26,7 @@ use PSX\Api\Generator\Server\Dto\File; use PSX\Api\Generator\Server\Dto\Folder; use PSX\Api\GeneratorInterface; +use PSX\Api\Operation\ArgumentInterface; use PSX\Api\OperationInterface; use PSX\Api\SpecificationInterface; use PSX\Schema\DefinitionsInterface; @@ -39,9 +40,12 @@ use PSX\Schema\GeneratorInterface as SchemaGeneratorInterface; use PSX\Schema\Schema; use PSX\Schema\Type\AnyType; +use PSX\Schema\Type\ArrayType; +use PSX\Schema\Type\IntersectionType; use PSX\Schema\Type\MapType; use PSX\Schema\Type\ReferenceType; use PSX\Schema\Type\StructType; +use PSX\Schema\Type\UnionType; use PSX\Schema\TypeFactory; use PSX\Schema\TypeInterface; use Twig\Environment; @@ -132,10 +136,21 @@ private function generateRecursive(Folder $folder, Chunks $chunks, Specification abstract protected function getControllerPath(): string; abstract protected function getModelPath(): string; - abstract protected function buildControllerFileName(string $name): string; - abstract protected function generateControllerFile(File $file, SpecificationInterface $specification): string; abstract protected function getFileExtension(): string; + abstract protected function generateHeader(File $file, array $imports): string; + abstract protected function generateFooter(File $file): string; + abstract protected function generateArgumentPath(string $rawName, string $variableName, string $type): string; + abstract protected function generateArgumentQuery(string $rawName, string $variableName, string $type): string; + abstract protected function generateArgumentHeader(string $rawName, string $variableName, string $type): string; + abstract protected function generateArgumentBody(string $variableName, string $type): string; + abstract protected function generateMethod(string $operationName, OperationInterface $operation, array $arguments, string $returnType): string; + + protected function buildControllerFileName(string $name): string + { + return $name; + } + protected function buildFolderName(string $name): string { return $name; @@ -191,6 +206,69 @@ protected function generateSchema(DefinitionsInterface $definitions, Generator\C } } + private function generateControllerFile(File $file, SpecificationInterface $specification): string + { + $controller = ''; + $imports = []; + + foreach ($file->getOperations() as $operationName => $operation) { + $args = []; + foreach ($operation->getArguments()->getAll() as $argumentName => $argument) { + $rawName = $argumentName; + $variableName = $this->normalizer->argument($argumentName); + $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); + + if ($argument->getIn() === ArgumentInterface::IN_PATH) { + $args[] = $this->generateArgumentPath($rawName, $variableName, $type->type); + } elseif ($argument->getIn() === ArgumentInterface::IN_QUERY) { + $args[] = $this->generateArgumentQuery($rawName, $variableName, $type->type); + } elseif ($argument->getIn() === ArgumentInterface::IN_HEADER) { + $args[] = $this->generateArgumentHeader($rawName, $variableName, $type->type); + } elseif ($argument->getIn() === ArgumentInterface::IN_BODY) { + $args[] = $this->generateArgumentBody($variableName, $type->type); + } + + $this->resolveImport($argument->getSchema(), $imports); + } + + $type = $this->newType($operation->getReturn()->getSchema(), $specification->getDefinitions()); + + $this->resolveImport($operation->getReturn()->getSchema(), $imports); + + $controller.= $this->generateMethod($operationName, $operation, $args, $type->type); + } + + $result = $this->generateHeader($file, $imports); + $result.= $controller; + $result.= $this->generateFooter($file); + + return $this->getFileContent($result, $file->getName()); + } + + private function resolveImport(TypeInterface $type, array &$imports): void + { + if ($type instanceof ReferenceType) { + $imports[$this->normalizer->file($type->getRef())] = $this->normalizer->class($type->getRef()); + if ($type->getTemplate()) { + foreach ($type->getTemplate() as $typeRef) { + $imports[$this->normalizer->file($typeRef)] = $this->normalizer->class($typeRef); + } + } + } elseif ($type instanceof MapType && $type->getAdditionalProperties() instanceof TypeInterface) { + $this->resolveImport($type->getAdditionalProperties(), $imports); + } elseif ($type instanceof ArrayType && $type->getItems() instanceof TypeInterface) { + $this->resolveImport($type->getItems(), $imports); + } elseif ($type instanceof UnionType && $type->getOneOf()) { + foreach ($type->getOneOf() as $item) { + $this->resolveImport($item, $imports); + } + } elseif ($type instanceof IntersectionType) { + foreach ($type->getAllOf() as $item) { + $this->resolveImport($item, $imports); + } + } + } + protected function getFileName(string $identifier): string { $identifier = $this->generator->getNormalizer()->file($identifier); diff --git a/src/Generator/Server/TypeScript.php b/src/Generator/Server/TypeScript.php index 7af129a1..c7c3efdb 100644 --- a/src/Generator/Server/TypeScript.php +++ b/src/Generator/Server/TypeScript.php @@ -21,8 +21,7 @@ namespace PSX\Api\Generator\Server; use PSX\Api\Generator\Server\Dto\File; -use PSX\Api\Operation\ArgumentInterface; -use PSX\Api\SpecificationInterface; +use PSX\Api\OperationInterface; use PSX\Schema\Generator; use PSX\Schema\GeneratorInterface as SchemaGeneratorInterface; @@ -50,62 +49,81 @@ protected function getModelPath(): string return 'src/dto'; } - protected function buildControllerFileName(string $name): string + protected function getFileExtension(): string { - return $name . '.controller'; + return 'ts'; } - protected function getFileExtension(): string + protected function getFileContent(string $code, string $identifier): string { - return 'ts'; + $comment = '/**' . "\n"; + $comment.= ' * ' . $identifier . ' automatically generated by SDKgen please do not edit this file manually' . "\n"; + $comment.= ' * {@link https://sdkgen.app}' . "\n"; + $comment.= ' */' . "\n"; + + return $comment . "\n" . $code; } - protected function generateControllerFile(File $file, SpecificationInterface $specification): string + protected function buildControllerFileName(string $name): string { - $controllerClass = $this->buildControllerClass($file); + return $name . '.controller'; + } + + protected function generateHeader(File $file, array $imports): string + { + $controllerClass = ucfirst($file->getName()) . 'Controller'; $controller = 'import { Controller, Get, Post, Put, Patch, Delete, HttpCode, Param, Query, Headers, Body } from \'@nestjs/common\'' . "\n"; + + foreach ($imports as $className) { + $controller.= 'import {' . $className . '} from "../dto/' . $className . '";' . "\n"; + } + $controller.= "\n"; $controller.= '@Controller()' . "\n"; $controller.= 'export class ' . $controllerClass . ' {' . "\n"; - foreach ($file->getOperations() as $operationName => $operation) { - $method = ucfirst(strtolower($operation->getMethod())); - - $args = []; - foreach ($operation->getArguments()->getAll() as $argumentName => $argument) { - if ($argument->getIn() === ArgumentInterface::IN_PATH) { - $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); - $args[] = '@Param(\'' . $argumentName . '\') ' . $this->normalizer->argument($argumentName) . ': ' . $type->type; - } elseif ($argument->getIn() === ArgumentInterface::IN_QUERY) { - $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); - $args[] = '@Query(\'' . $argumentName . '\') ' . $this->normalizer->argument($argumentName) . '?: ' . $type->type; - } elseif ($argument->getIn() === ArgumentInterface::IN_HEADER) { - $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); - $args[] = '@Headers(\'' . $argumentName . '\') ' . $this->normalizer->argument($argumentName) . '?: ' . $type->type; - } elseif ($argument->getIn() === ArgumentInterface::IN_BODY) { - $type = $this->newType($argument->getSchema(), $specification->getDefinitions()); - $args[] = '@Body() ' . $this->normalizer->argument($argumentName) . ': ' . $type->type; - } - } - - $type = $this->newType($operation->getReturn()->getSchema(), $specification->getDefinitions()); - - $controller.= ' @' . $method . '()' . "\n"; - $controller.= ' @HttpCode(' . $operation->getReturn()->getCode() . ')' . "\n"; - $controller.= ' ' . $operationName . '(' . implode(', ', $args) . '): ' . $type->type . ' {' . "\n"; - $controller.= ' // @TODO implement method' . "\n"; - $controller.= ' }' . "\n"; - $controller.= "\n"; - } + return $controller; + } - $controller.= '}' . "\n"; + protected function generateFooter(File $file): string + { + $controller = '}' . "\n"; return $controller; } - private function buildControllerClass(File $file): string + protected function generateArgumentPath(string $rawName, string $variableName, string $type): string + { + return '@Param(\'' . $rawName . '\') ' . $variableName . ': ' . $type; + } + + protected function generateArgumentQuery(string $rawName, string $variableName, string $type): string + { + return '@Query(\'' . $rawName . '\') ' . $variableName . ': ' . $type; + } + + protected function generateArgumentHeader(string $rawName, string $variableName, string $type): string { - return ucfirst($file->getName()) . 'Controller'; + return '@Headers(\'' . $rawName . '\') ' . $variableName . ': ' . $type; + } + + protected function generateArgumentBody(string $variableName, string $type): string + { + return '@Body() ' . $variableName . ': ' . $type; + } + + protected function generateMethod(string $operationName, OperationInterface $operation, array $arguments, string $returnType): string + { + $methodName = ucfirst(strtolower($operation->getMethod())); + + $method = ' @' . $methodName . '(\'' . $operation->getPath() . '\')' . "\n"; + $method.= ' @HttpCode(' . $operation->getReturn()->getCode() . ')' . "\n"; + $method.= ' ' . $operationName . '(' . implode(', ', $arguments) . '): ' . $returnType . ' {' . "\n"; + $method.= ' // @TODO implement method' . "\n"; + $method.= ' }' . "\n"; + $method.= "\n"; + + return $method; } } diff --git a/tests/Generator/Server/resource/php/src/Controller/App.php b/tests/Generator/Server/resource/php/src/Controller/App.php index 6a0735ac..4e923b7d 100644 --- a/tests/Generator/Server/resource/php/src/Controller/App.php +++ b/tests/Generator/Server/resource/php/src/Controller/App.php @@ -1,42 +1,70 @@ ')] - #[StatusCode(200)] - public function get(#[Param] string $year): EntryCollection { - // @TODO implement method - } + #[Get] + #[Path('/bar/$year<[0-9]+>')] + #[StatusCode(200)] + public function get(#[Param] string $year): EntryCollection + { + // @TODO implement method + } - #[Post] - #[Path('/bar/$year<[0-9]+>')] - #[StatusCode(201)] - public function create(#[Body] EntryCreate $payload): EntryMessage { - // @TODO implement method - } + #[Post] + #[Path('/bar/$year<[0-9]+>')] + #[StatusCode(201)] + public function create(#[Body] EntryCreate $payload): EntryMessage + { + // @TODO implement method + } } diff --git a/tests/Generator/Server/resource/php_complex/src/Model/Entry.php b/tests/Generator/Server/resource/php_complex/src/Model/Entry.php index 457eeb59..e9ee19ff 100644 --- a/tests/Generator/Server/resource/php_complex/src/Model/Entry.php +++ b/tests/Generator/Server/resource/php_complex/src/Model/Entry.php @@ -1,3 +1,11 @@ +): Record { // @TODO implement method } - @Delete() + @Delete('/foo/:name/:type') @HttpCode(204) delete(@Param('name') name: string, @Param('type') type: string, @Body() payload: EntryDelete): EntryMessage { // @TODO implement method } - @Patch() + @Patch('/foo/:name/:type') @HttpCode(200) patch(@Param('name') name: string, @Param('type') type: string, @Body() payload: Array): Array { // @TODO implement method diff --git a/tests/Generator/Server/resource/typescript/src/dto/Entry.ts b/tests/Generator/Server/resource/typescript/src/dto/Entry.ts index 65de8319..b50aaa0c 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/Entry.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/Entry.ts @@ -1,3 +1,8 @@ +/** + * Entry automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface Entry { id?: number userId?: number diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryCollection.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryCollection.ts index a7aa0d0d..1f8e50b2 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryCollection.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryCollection.ts @@ -1,3 +1,8 @@ +/** + * EntryCollection automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + import {Entry} from "./Entry"; export interface EntryCollection { entry?: Array diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryCreate.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryCreate.ts index ebbc1aba..ec66486d 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryCreate.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryCreate.ts @@ -1,3 +1,8 @@ +/** + * EntryCreate automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryCreate { id?: number userId?: number diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryDelete.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryDelete.ts index 83da1b20..102bbf92 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryDelete.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryDelete.ts @@ -1,3 +1,8 @@ +/** + * EntryDelete automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryDelete { id: number userId?: number diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryMessage.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryMessage.ts index b7a4b1da..3c733c2b 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryMessage.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryMessage.ts @@ -1,3 +1,8 @@ +/** + * EntryMessage automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryMessage { success?: boolean message?: string diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryPatch.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryPatch.ts index 1d1a676d..d901ed0b 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryPatch.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryPatch.ts @@ -1,3 +1,8 @@ +/** + * EntryPatch automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryPatch { id: number userId?: number diff --git a/tests/Generator/Server/resource/typescript/src/dto/EntryUpdate.ts b/tests/Generator/Server/resource/typescript/src/dto/EntryUpdate.ts index 0a94f447..984816ce 100644 --- a/tests/Generator/Server/resource/typescript/src/dto/EntryUpdate.ts +++ b/tests/Generator/Server/resource/typescript/src/dto/EntryUpdate.ts @@ -1,3 +1,8 @@ +/** + * EntryUpdate automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryUpdate { id: number userId?: number diff --git a/tests/Generator/Server/resource/typescript_complex/src/controller/bar.controller.ts b/tests/Generator/Server/resource/typescript_complex/src/controller/bar.controller.ts index 91c977fc..aa7107ea 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/controller/bar.controller.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/controller/bar.controller.ts @@ -1,14 +1,22 @@ +/** + * bar automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + import { Controller, Get, Post, Put, Patch, Delete, HttpCode, Param, Query, Headers, Body } from '@nestjs/common' +import {EntryCollection} from "../dto/EntryCollection"; +import {EntryCreate} from "../dto/EntryCreate"; +import {EntryMessage} from "../dto/EntryMessage"; @Controller() export class BarController { - @Get() + @Get('/bar/:foo') @HttpCode(200) find(@Param('foo') foo: string): EntryCollection { // @TODO implement method } - @Post() + @Post('/bar/:foo') @HttpCode(201) put(@Body() payload: EntryCreate): EntryMessage { // @TODO implement method diff --git a/tests/Generator/Server/resource/typescript_complex/src/controller/foo/bar.controller.ts b/tests/Generator/Server/resource/typescript_complex/src/controller/foo/bar.controller.ts index 7738f1e3..4905e4e5 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/controller/foo/bar.controller.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/controller/foo/bar.controller.ts @@ -1,14 +1,22 @@ +/** + * bar automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + import { Controller, Get, Post, Put, Patch, Delete, HttpCode, Param, Query, Headers, Body } from '@nestjs/common' +import {EntryCollection} from "../dto/EntryCollection"; +import {EntryCreate} from "../dto/EntryCreate"; +import {EntryMessage} from "../dto/EntryMessage"; @Controller() export class BarController { - @Get() + @Get('/foo') @HttpCode(200) get(): EntryCollection { // @TODO implement method } - @Post() + @Post('/foo') @HttpCode(201) create(@Body() payload: EntryCreate): EntryMessage { // @TODO implement method diff --git a/tests/Generator/Server/resource/typescript_complex/src/controller/foo/baz.controller.ts b/tests/Generator/Server/resource/typescript_complex/src/controller/foo/baz.controller.ts index 2f1d2b9c..9e64ec00 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/controller/foo/baz.controller.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/controller/foo/baz.controller.ts @@ -1,14 +1,22 @@ +/** + * baz automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + import { Controller, Get, Post, Put, Patch, Delete, HttpCode, Param, Query, Headers, Body } from '@nestjs/common' +import {EntryCollection} from "../dto/EntryCollection"; +import {EntryCreate} from "../dto/EntryCreate"; +import {EntryMessage} from "../dto/EntryMessage"; @Controller() export class BazController { - @Get() + @Get('/bar/$year<[0-9]+>') @HttpCode(200) get(@Param('year') year: string): EntryCollection { // @TODO implement method } - @Post() + @Post('/bar/$year<[0-9]+>') @HttpCode(201) create(@Body() payload: EntryCreate): EntryMessage { // @TODO implement method diff --git a/tests/Generator/Server/resource/typescript_complex/src/dto/Entry.ts b/tests/Generator/Server/resource/typescript_complex/src/dto/Entry.ts index 65de8319..b50aaa0c 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/dto/Entry.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/dto/Entry.ts @@ -1,3 +1,8 @@ +/** + * Entry automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface Entry { id?: number userId?: number diff --git a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCollection.ts b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCollection.ts index a7aa0d0d..1f8e50b2 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCollection.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCollection.ts @@ -1,3 +1,8 @@ +/** + * EntryCollection automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + import {Entry} from "./Entry"; export interface EntryCollection { entry?: Array diff --git a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCreate.ts b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCreate.ts index ebbc1aba..ec66486d 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCreate.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryCreate.ts @@ -1,3 +1,8 @@ +/** + * EntryCreate automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryCreate { id?: number userId?: number diff --git a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryMessage.ts b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryMessage.ts index b7a4b1da..3c733c2b 100644 --- a/tests/Generator/Server/resource/typescript_complex/src/dto/EntryMessage.ts +++ b/tests/Generator/Server/resource/typescript_complex/src/dto/EntryMessage.ts @@ -1,3 +1,8 @@ +/** + * EntryMessage automatically generated by SDKgen please do not edit this file manually + * {@link https://sdkgen.app} + */ + export interface EntryMessage { success?: boolean message?: string