-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
WIP: HTTP Response Code and Include File #71
Conversation
- 'responseCodes' allows to define the HTTP response codes and the situations when they are returned. (Think of Docblocks and Exceptions). - 'include' allows to include a Markdown file with a long description. - Minor tweaks: Made the Filters actually display as Markdown as well. - When 'default' is included in filters, use this instead of the description for the sandbox.
@@ -12,6 +12,7 @@ | |||
namespace Nelmio\ApiDocBundle\Annotation; | |||
|
|||
use Symfony\Component\Routing\Route; | |||
use dflydev\markdown\MarkdownParser; |
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.
I will add the dependency to the composer.json
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 already in the composer.json
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.
however, the annotation should not be responsible of the parsing. The rendering should
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.
Oh yeah. just noticed that.
btw, this included file has nothing to do in the ApiDoc annotation: you are defining it as a global setting, whereas the annotation is about one route |
I don't understand your last comment. The setting is simply a basepath. The annotation is still about one route. |
hmm, indeed. But this looks weird. Couldn't you make the path relative to the location of the controller (which can be retrieved from the reflection objects) ? Thsi would avoid having to configure a base path, making it possible for shared bundles to use it if they want too. |
I'll look into that. Good idea. |
Thanks @stof for tip on how to use ReflectionClass to get the filename. Updated README, and reverted changes to the configuration.
$fileContents = file_get_contents($data['fileToInclude']); | ||
$data['fileToInclude'] = $mdParser->transform($fileContents); | ||
|
||
} |
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.
why not simply using the |markdown
filter to do the rendering part, passing the content of the file here ?
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.
Done
Also check whether included file is defined and non-empty
@@ -28,6 +28,29 @@ | |||
{% if data.documentation is defined and data.documentation is not empty %} | |||
<h4>Documentation</h4> | |||
<div>{{ data.documentation|extra_markdown }}</div> | |||
{% if data.fileToInclude is defined and data.fileToInclude is not empty %} | |||
<div>{{ data.fileToInclude|markdown }}</div> |
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 filter defined in the bundle is extra_markdown
, not markdown
(sorry for giving a wrong name)
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.
Done.
Added two small unit tests
Thanks @stof for all the feedback. |
@@ -305,6 +305,12 @@ protected function extractData(ApiDoc $annotation, Route $route, \ReflectionMeth | |||
$annotation->setMethod($route->getRequirement('_method') ?: 'ANY'); | |||
$annotation->setUri($route->getPattern()); | |||
|
|||
// Include File | |||
if ("" != ($fileToInclude = $annotation->getFileToInclude())) { |
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.
if (!($fileToInclude = $annotation->getFileToInclude())) {
or
if (false === ($fileToInclude = $annotation->getFileToInclude())) {
or
if (empty($fileToInclude = $annotation->getFileToInclude())) {
look cleaner to me
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.
Done.
I really like the response codes idea! |
I don't get the point of the response codes. First, it would be named "status codes" but also, why do you want to add these information in the annotation? You can write complete documentation in the doc block. I like to document my status codes too, but I often need to provide the response body with a given status code. |
Also, I thought a lot about your second feature, and having documentation in another file leads to outdated documentation as you can change the code without changing the documentation (because you missed the included file). However, it would fix a common issue: the huge doc blocks in the controllers. |
Right, it's one of those things where both kind of suck. :-/ |
I think these two things should be separate PRs. I like
|
Regarding
|
@baldurrensch You're right about the For what it's worth, here is how Swagger documents errors, which would be a subset of responses: https://github.com/wordnik/swagger-core/wiki/errors As it stands in this PR, it would be easy for me to check specifically for 400-500 range errors to support Swagger using the response data documented here. The response body content its self is already covered with with the @asm89 mentioned in IRC splitting the |
@evillemez The response body is -- in almost all cases -- different from the success scenario, I would think. I definitely like the idea of splitting up the By the way, swagger calls the |
Any news on this PR? |
@phidah Unfortunately I never got a clear answer whether my PR was desired or not, or whether I should split it up in multiple parts, so I put it to sleep. :-( |
That seems to be a general problem with the bundles from Nelmio :( On Tuesday den 6. November 2012 at 22.18, Baldur Rensch wrote:
|
@phidah sorry but we're a small team and I already spend a lot of time on other stuff like composer/packagist, so we do what we can here. @baldurrensch Anyway I just reviewed this quickly and as it was said above I agree it should be split in two PRs. I'm pretty much ok with the response codes bit and would be happy to merge that. My only comment there would be that statusCodes might be better than responseCodes, after all that's what the spec calls them. Regarding the file includes, I'm still not sure if that's a good idea. It definitely goes against the point of this bundle that is to keep everything in your code to avoid stuff getting too out of date. Then again one might argue it's ok to give the freedom to shoot yourself in the foot to users. Just not sure what the use case is? |
@Seldaek: Perfect, I will split it up in the next few days, as soon as I find some time. I see the point of enforcing the documentation to be in the source code file, but that can blow those up in some cases when you need/want a lot of documentation. |
For the includes, one approach that might be better is to do a |
Can we close that PR? If you want to continue the discussion about |
Yes. I'll close it. Thanks. |
Hey all,
this is a PR. It's currently WIP, so, Tests are not added, and not all templates are up to date. I wanted to get some feedback first (and whether there is any interest for that). Basically it adds two new parameters to the ApiDoc annotation. I updated the README to show how to use them.
I noticed that "response" was just merged in, however I believe that my response codes is different. Any feedback is appreciated.