Skip to content

Commit

Permalink
moved default value from parameter (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Jun 29, 2024
1 parent b5ea08a commit 6a0ee09
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
12 changes: 0 additions & 12 deletions src/Support/Generator/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Parameter
/** @var array|scalar|null|MissingExample */
public $example;

/** @var array|scalar|null|MissingExample */
public $default;

public bool $deprecated = false;

public bool $allowEmptyValue = false;
Expand All @@ -37,7 +34,6 @@ public function __construct(string $name, string $in)
$this->in = $in;

$this->example = new MissingExample;
$this->default = new MissingExample;

if ($this->in === 'path') {
$this->required = true;
Expand Down Expand Up @@ -67,7 +63,6 @@ public function toArray(): array
return array_merge(
$result,
$this->example instanceof MissingExample ? [] : ['example' => $this->example],
$this->default instanceof MissingExample ? [] : ['default' => $this->default],
);
}

Expand All @@ -92,13 +87,6 @@ public function setSchema(?Schema $schema): self
return $this;
}

public function default($default)
{
$this->default = $default;

return $this;
}

public function description(string $description)
{
$this->description = $description;
Expand Down
1 change: 0 additions & 1 deletion src/Support/Generator/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static function createFromParameters(array $parameters)

$paramType->setDescription($parameter->description);
$paramType->example($parameter->example);
$paramType->default($parameter->default);

$type->addProperty($parameter->name, $paramType);
})
Expand Down
7 changes: 4 additions & 3 deletions src/Support/IndexBuilders/RequestParametersBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public function afterAnalyzedNode(Scope $scope, Node $node)
$parameter
->description($this->makeDescriptionFromComments($commentHolderNode))
->setSchema(Schema::fromType(
app(TypeTransformer::class)->transform($parameterType)
))
->default($parameterDefault ?? new MissingExample);
app(TypeTransformer::class)
->transform($parameterType)
->default($parameterDefault ?? new MissingExample)
));

$this->bag->set($parameterName, $parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function applyDocsInfo(Parameter $parameter)
}

if ($default = ExamplesExtractor::make($this->docNode, '@default')->extract(preferString: $parameter->schema->type instanceof StringType)) {
$parameter->default($default[0]);
$parameter->schema->type->default($default[0]);
}

if ($this->docNode->getTagsByName('@query')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ enum RequestBodyExtensionTest__Status_Params_Extraction: string
'in' => 'query',
'schema' => [
'type' => 'string',
'default' => 'foo',
],
'default' => 'foo',
]]);
});
class RequestBodyExtensionTest__extracts_parameters_from_retrieving_methods_with_query
Expand Down Expand Up @@ -254,8 +254,10 @@ public function index(Illuminate\Http\Request $request)
->toBe([[
'name' => 'foo',
'in' => 'query',
'schema' => ['type' => 'integer'],
'default' => 10,
'schema' => [
'type' => 'integer',
'default' => 10,
],
]]);
});
class RequestBodyExtensionTest__allows_explicitly_specifying_parameter_placement_in_query_manually_in_doc
Expand Down

0 comments on commit 6a0ee09

Please sign in to comment.