Set 'parameters' annotation in NelmioApiDocBundle - symfony

I create an API RESTfull using Symfony2.1 with FOSRESTBundle and I am using NelmioApiDocBundle to generate automatic documentation.
I have a PUT request in which the user should send one parameter, but I don't need to create a Form for this purpose. All works perfectly but when I generate the documentation I don't know how to add this parameter to the documentation because I don't have a 'input' form.
I tried this but seems doesn't work:
/**
* #ApiDoc(
* description="description",
* statusCodes={
* 200="Success",
* 400="Bad request"},
* parameters={
* {"name"="parameter_name", "dataType"="integer"}
* }
* )
...
In the documentation of NelmioApiDocBundle I didn't see any solution for this...

use filters key instead of parameters
* filters={
* {"name"="parameter_name", "dataType"="integer"},
* },

Related

Swagger annotation for query parameters for file upload

I am trying to make an api documentation for my symfony based api and I would like to add info about the upload endpoint for my api. I am using nelmioapidocbundle. Can anyone please provide a link to the documentation where I can find it? or better if there is an example. Thank you.
/**
* #Route("/products/{id}/images", methods={"POST"})
*
* #SWG\Parameter(
* name="file",
* in="body",
* type="file",
* ---- Im not sure what to put here to make this work
* )
*
* #SWG\Response(
* response=201,
* description="File is uploaded."
* )
* )
*/
public function uploadImages(Request $request, FileUploadService $fileUploadService) {}
For anyone who might encounter this. this formData in value fixed the problem:
* #SWG\Parameter(
* name="file",
* in="formData", <----
* required=true,
* type="file",
* description="product image"

How to define an associative array in Nelmio API DOC vs 3?

I am using Symfomy 3.4 with Nelmio API DOC vs 3.
I have a GET API with a multiplier parameter of the format:
multiplier[14]=2&multiplier[15]=1. I want to be able to make the request from /api-doc panel with the keys of the array, not only the values. At this moment, I can add only values.
The way I am defining the relationship at this moment is:
* #SWG\Parameter(
* name="multiplier",
* in="query",
* type="array",
* description="multiply the received reward",
* #SWG\Items(
* type="integer",
* ),
* required=false
* )
I tried several things, like
* #SWG\Property(
* type="string"
* ),
but it seems not to work.
How can I make the key appear in the panel so I can complete it there, without using something external, such as Postman?

Symfony Assert Min Value

I have a video entity that only contains a video from YouTube. To do this, I have to add a constraint in the entity with an assert, I tried "Range" with minimum: https://youtube.com/watch?v= and by specifying the string group. It’s no working! Help me! Here is the code of the entity:
/**
* #ORM\Column(type="string", length=255, nullable=true)
* #Assert\Range(
* min = "https://youtube.com/watch?v=",
* groups = {"string"}"
* )
*/
private $video;
You should try to solve this task with a custom validation constraint. It allows your code to assert that a request parameter contains https://youtube.com/watch?v= or even to check that video url is a valid video (with request to a Youtube API with a help of Guzzle client or Youtube API library). More info see in the official Symfony docs. https://symfony.com/doc/current/validation/custom_constraint.html

defines manually routes using Symfony2

I've set up my entities, now I want to
use the doctrine:generate:crud, during this command it asks what route
prefix I would like. I would expect that this means that the routes
would automatically be generate, this is not happening. So I need to
know if it is supposed to generate the routes, or if I'm supposed to
create them all manually? If it is the case that I need to generate
them manually is there a route class, to define all the routes for the
CRUD operations?
When you generate a CRUD with Symfony, it will ask you to choose a configuration format.
By default, it's annotation. If you haven't changed it, then your routes are in the entity controller, as annotation.
In the example below, you can see the #Route anotation, which is how to define the URL in anotation.
/**
* Finds and displays a user entity.
*
* #Route("/user/{id}", name="user_show")
* #Method("GET")
*
* #param User $user
* #return \Symfony\Component\HttpFoundation\Response
*/
public function showAction(User $user) {
$deleteForm=$this->createDeleteForm($user);
return $this->render('security/show.html.twig', array(
'security'=>$user,
'delete_form'=>$deleteForm->createView(),
));
}
In the end, it's not that "It didn't happen", it's simply and most likely that you haven't read some doc, and didn't knew about it... ;)
Symfony doc: Routing

Custom metadata information in Symfony/Doctrine

Is it possible to create custom metadata information in the entities? Something that would use the already present functionality of using either Annotation, yml or xml to store metadata about the entity.
Example:
/**
* #var string
*
* #ORM\Column(name="text", type="text")
* #CUSTOM\Meta(key="value") // <-- Extra information
*/
protected $text;
For what I've been researching, it seems that I should use the functionality of ClassMetadataFactory. Is it possible, or would I have to make it from scratch?

Resources