From dcb71454401deb669ad74cfcb09a5fa0a5e54110 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Tue, 21 May 2024 16:22:40 +0300 Subject: [PATCH] fixed template types being not recognized --- src/Support/Generator/Operation.php | 2 +- src/Support/Generator/RequestBodyObject.php | 17 ++++++++++++++--- src/Support/Generator/TypeTransformer.php | 5 +++++ src/Support/Generator/Types/ObjectType.php | 2 +- .../RulesExtractor/RulesToParameters.php | 4 ++-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Support/Generator/Operation.php b/src/Support/Generator/Operation.php index 5c3d6ada..0f93054a 100644 --- a/src/Support/Generator/Operation.php +++ b/src/Support/Generator/Operation.php @@ -23,7 +23,7 @@ class Operation public array $tags = []; - /** @var Parameter[] */ + /** @var (Parameter|Reference)[] */ public array $parameters = []; public ?RequestBodyObject $requestBodyObject = null; diff --git a/src/Support/Generator/RequestBodyObject.php b/src/Support/Generator/RequestBodyObject.php index f25a5dd3..db235729 100644 --- a/src/Support/Generator/RequestBodyObject.php +++ b/src/Support/Generator/RequestBodyObject.php @@ -5,23 +5,34 @@ class RequestBodyObject { /** @var array */ - private array $content; + public array $content; + + public string $description = ''; public static function make() { return new self(); } - public function setContent(string $type, Schema $schema) + public function setContent(string $type, Schema|Reference $schema) { $this->content[$type] = $schema; return $this; } + public function description(string $string) + { + $this->description = $string; + + return $this; + } + public function toArray() { - $result = []; + $result = array_filter([ + 'description' => $this->description, + ]); $content = []; foreach ($this->content as $mediaType => $schema) { diff --git a/src/Support/Generator/TypeTransformer.php b/src/Support/Generator/TypeTransformer.php index 0a075d06..ea79896f 100644 --- a/src/Support/Generator/TypeTransformer.php +++ b/src/Support/Generator/TypeTransformer.php @@ -18,6 +18,7 @@ use Dedoc\Scramble\Support\Type\ArrayItemType_; use Dedoc\Scramble\Support\Type\Literal\LiteralIntegerType; use Dedoc\Scramble\Support\Type\Literal\LiteralStringType; +use Dedoc\Scramble\Support\Type\TemplateType; use Dedoc\Scramble\Support\Type\Type; use Dedoc\Scramble\Support\Type\Union; use Illuminate\Support\Str; @@ -57,6 +58,10 @@ public function transform(Type $type) { $openApiType = new StringType(); + if ($type instanceof TemplateType && $type->is) { + $type = $type->is; + } + if ( $type instanceof \Dedoc\Scramble\Support\Type\KeyedArrayType && $type->isList diff --git a/src/Support/Generator/Types/ObjectType.php b/src/Support/Generator/Types/ObjectType.php index bac4f14c..9426f3df 100644 --- a/src/Support/Generator/Types/ObjectType.php +++ b/src/Support/Generator/Types/ObjectType.php @@ -10,7 +10,7 @@ class ObjectType extends Type /** @var string[] */ public array $required = []; - private ?Type $additionalProperties = null; + public ?Type $additionalProperties = null; public function __construct() { diff --git a/src/Support/OperationExtensions/RulesExtractor/RulesToParameters.php b/src/Support/OperationExtensions/RulesExtractor/RulesToParameters.php index 0a6a7efe..629c8bd3 100644 --- a/src/Support/OperationExtensions/RulesExtractor/RulesToParameters.php +++ b/src/Support/OperationExtensions/RulesExtractor/RulesToParameters.php @@ -40,8 +40,8 @@ public function handle() { return collect($this->rules) ->map(fn ($rules, $name) => (new RulesToParameter($name, $rules, $this->nodeDocs[$name] ?? null, $this->openApiTransformer))->generate()) - ->pipe(\Closure::fromCallable([$this, 'handleNested'])) - ->pipe(\Closure::fromCallable([$this, 'handleConfirmed'])) + ->pipe($this->handleNested(...)) + ->pipe($this->handleConfirmed(...)) ->values() ->all(); }