Skip to content

Commit

Permalink
fixed template types being not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed May 21, 2024
1 parent d8d66b9 commit dcb7145
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Support/Generator/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Operation

public array $tags = [];

/** @var Parameter[] */
/** @var (Parameter|Reference)[] */
public array $parameters = [];

public ?RequestBodyObject $requestBodyObject = null;
Expand Down
17 changes: 14 additions & 3 deletions src/Support/Generator/RequestBodyObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@
class RequestBodyObject
{
/** @var array<string, Schema> */
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) {
Expand Down
5 changes: 5 additions & 0 deletions src/Support/Generator/TypeTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Generator/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ObjectType extends Type
/** @var string[] */
public array $required = [];

private ?Type $additionalProperties = null;
public ?Type $additionalProperties = null;

public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit dcb7145

Please sign in to comment.