-
Notifications
You must be signed in to change notification settings - Fork 3
Swagger #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger #469
Conversation
…nvert it to a Swagger specification; newly supports path and query parameters
… now delete the temp file
…nvert it to a Swagger specification; newly supports path and query parameters
… now delete the temp file
app/commands/GenerateSwagger.php
Outdated
| $path = __DIR__ . '/../V1Module/presenters/_autogenerated_annotations_temp.php'; | ||
| $openapi = \OpenApi\Generator::scan([$path]); | ||
|
|
||
| header('Content-Type: application/x-yaml'); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Added a new command
generate-swaggerthat prints a swagger document representing the current API to the console.