When generating output documentation the status code shown in the return block is always 200. However in my case I am returning a 201, as we can see in the statusCodes annotation. Is there a way to override the value shown for the output? Or maybe just hide it when the statusCodes annotation is provided?
Here are my annotations:
/**
* @ApiDoc(
* resource=true,
* section="Job",
* description="Create a new job",
* input="AppBundle\Form\ApiJobType",
* output={
* "class"="AppBundle\Entity\Job",
* "groups"={"api_create"},
* "parsers"={
* "Nelmio\ApiDocBundle\Parser\JmsMetadataParser"
* }
* },
* statusCodes = {
* Codes::HTTP_CREATED = "Returned when successful",
* Codes::HTTP_BAD_REQUEST = "Returned when the form has errors"
* }
* )
*
* @param Request $request
* @return Response
*/
And the result:
Hi Emily,
Outpout require a HTTP Code 200 (see Nelmio\ApiDocBundle\Annotation\ApiDoc.php line 287). I don't know why :-/
Instead, you can use another great parameter : responseMap!
* @ApiDoc(
* //...
* statusCodes = {
* 201 = "Returned when successful",
* 400 = "Returned when the form has errors"
* },
* responseMap = {
* 201 = {
* "class" = Job::class,
* "groups"={"api_create"}
* },
* 400 = {
* "class" = ApiJobType::class,
* "form_errors" = true,
* "name" = ""
* },
* }
* )
See #791
Thanks Maxpou! I'll use the responseMap instead for now. But I still think the http code shouldn't be hardcoded for the ouput
@emiliemarchand I think too !
But I still think the http code shouldn't be hardcoded for the ouput
:+1:
As this has been merged IMO it should be closed.
Where can I find documentation about Response Map options please ? I would to documentate response -> error after validation of an entity
Response looks like :
[{
"property_path":"...",
"message":"..."
}]
Controller :
$errors = $this->get('validator')->validate($athleteWeight);
if (count($errors)) {
return $this->view($errors, Response::HTTP_BAD_REQUEST);
}
Annotation :
responseMap = {
400 = {
"class" = "",
"form_errors"=true,
"name" = ""
},
},
Code above show in http://local.../api/doc something like :
400 - Returned when the request was not valid
status_code integer * The status code
message string * The error message
errors errors * Errors
I hope my question is understandable
version 3 is a complete rewrite. please check if this is still a problem with version 3 and a recent symfony version.
Most helpful comment
Thanks Maxpou! I'll use the responseMap instead for now. But I still think the http code shouldn't be hardcoded for the ouput