Skip to content

Conversation

@eceltov
Copy link
Collaborator

@eceltov eceltov commented Oct 17, 2024

Added a new command generate-swagger that prints a swagger document representing the current API to the console.

$path = __DIR__ . '/../V1Module/presenters/_autogenerated_annotations_temp.php';
$openapi = \OpenApi\Generator::scan([$path]);

header('Content-Type: application/x-yaml');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of setting a header here?


protected function execute(InputInterface $input, OutputInterface $output)
{
$path = __DIR__ . '/../V1Module/presenters/_autogenerated_annotations_temp.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated files are usually in temp. If there is any exception, it needs to be duly explained in a comment.

// $entry["tags"] = array_unique($entry["tags"]);
// }
// }
class GenerateSwagger extends Command
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class doc comment is missing.

use ReflectionException;
use ReflectionClass;

class SwaggerAnnotator extends Command
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class doc comment is missing.

$tokens = explode(" ", $annotation);
$type = $tokens[1];
// assumed that all names start with $
$name = substr($tokens[2], 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use destructive assignments like [$_, $type, $name] = $tokens. (but this comment has low priority)

// remove the '"' at the end
$value = substr($tokens[1], 0, -1);
$dict[$name] = $value;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting increasingly complex. Wouldn't it be more readable to extract the name-value pair using regex?

// sample: @checked_param format:group group
$tokens = explode(" ", $annotation);
$format = $tokens[1];
$name = $tokens[2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, opportunity for destructive assignment.

return true;
}

return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit like an overkill (the whole function can be one && bool expr). If this might extend in the future, then it is ok, I guess, otherwise, compacting should be considered.

@krulis-martin krulis-martin merged commit b4ac7d7 into master Dec 12, 2024
12 checks passed
@krulis-martin krulis-martin deleted the swagger branch December 12, 2024 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants