Skip to content

Commit

Permalink
Feature: Small code refactoring related parameter with reference
Browse files Browse the repository at this point in the history
@s0lus can you take a look? Thanks
  • Loading branch information
ovr committed Jun 9, 2018
1 parent c3e74f0 commit 31bf425
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/Command/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,14 @@ function (\Swagger\Annotations\Parameter $parameter) use ($swagger) {
return flowTypeEscape($parameter->type, $parameter->enum);
}

if ($parameter->ref) {
$stripped = stripParameters($parameter->ref);
foreach ($swagger->parameters as $param) {
if ($stripped === $param->name) {
return handleFlowParameterType($param);
}
}
}

return handleFlowParameterType($parameter);
}
)
);

$twig->addFunction(
new \Twig_Function(
'flowParameterWithRef',
'extractParameterByRef',
function (\Swagger\Annotations\Parameter $parameter) use ($swagger) {
$stripped = stripParameters($parameter->ref);
foreach ($swagger->parameters as $param) {
Expand Down
4 changes: 2 additions & 2 deletions src/resource/js/params.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export type {{ operationId }}Params = {
{% for parameter in parameters %}
{% if parameter.in != "path" and parameter.in != "body" %}
{% if parameter.ref %}
{% set param = flowParameterWithRef(parameter) %}
{{ param.name|flowFieldEscape|raw }}{{ param.required ? ':' : '?:' }} {{ flowParameterType(parameter)|raw }},
{% set referencedParameter = extractParameterByRef(parameter) %}
{{ referencedParameter.name|flowFieldEscape|raw }}{{ referencedParameter.required ? ':' : '?:' }} {{ flowParameterType(referencedParameter)|raw }},
{% else %}
{{ parameter.name|flowFieldEscape|raw }}{{ parameter.required ? ':' : '?:' }} {{ flowParameterType(parameter)|raw }},
{% endif %}
Expand Down

0 comments on commit 31bf425

Please sign in to comment.