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"
Related
I have route like this:
* #Route(
* "/search/{ro}/{mind}/{his}",
* name="search",
* requirements={"ro"="[a-zA-Z]{2,}", "mind"="()|new|old", "his"="()|yes|ok|no"}
* )
if I want this url: /search/yes I need to enter this address: /search///yes to show page.
how can remove // from original url?
welcome to stackoverflow,
you know you can have multiple routes for one action?
Just be aware of the order of the routes - the more parameters the higher - or a lesser route will catch first.
* #Route(
* "/search/{ro}/{mind}/{his}",
* name="search",
* requirements={"ro"="[a-zA-Z]{2,}", "mind"="()|new|old", "his"="yes|ok|no"}
* )
* #Route(
* "/search/{his}",
* name="search_short",
* requirements={"his"="yes|ok|no"}
* )
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?
I have entity with uniq field, inviteCode. And when I create new entity I want set automatic some random code, but this code must be different from exist in db, what do you thing, what practices about that you know ?
/**
* #ORM\Table(name="users")
* #ORM\Entity
* #ORM\HasLifecycleCallbacks
* #AssertBridge\UniqueEntity(
* groups={"registration"},
* fields="inviteCode",
* errorPath="not valid",
* message="This inviteCode is already in use."
* )
*/
class User extends AbstractUser implements UserInterface
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=500, unique=true)
* #Annotation\SerializedName("_invite_code")
*/
private $inviteCode;
I found something like that
private function calculateReference($number)
{
$multipliers = array(7,3,1);
$length = strlen($number);
$numberArr = str_split($number);
$sum = 0;
for ($i = $length - 1; $i >= 0; --$i)
{
$sum += $numberArr[$i] * $multipliers[($length - 1 - $i) % 3];
}
return $number.(10 - $sum % 10) % 10;
}
first get max id from table then call function calculateReference with id and then setInviteCode.
But I believe doctrine have something exist for this issue or maybe somebody have good example for this
Someone provided a great answer here https://stackoverflow.com/a/13917309/4173130.
But like he said at the end, you don't need doctrine for such a simple feature. Generating the code in the constructor is an efficient, simple and clear solution.
You can use a UUID library like ramsey/uuid. Then you would be able to generate any random code with Uuid::uuid4();.
Another solution is to use random_bytes() with base64_encode : base64_encode(random_bytes(32)).
Please don't try to create a new function to generate random values. Most of time it is not secure, see https://www.owasp.org/index.php/Insecure_Randomness.
Why not using a uuid? It is included in php as a core function and i believe it suits your needs.
Check in the official documentation here
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"},
* },
I need to add functionality to attach a file to a comment. The upload of the image would automatically when the user drops the file into the form (in the same way that you attach a file with gmail). My question is how do I do to find the file that was previously sent to the server when the comment is submitted and to delete the comment if the document is never submitted.
Do any of you have already done something similar?
Here's the association I have between my classes Comment and Document.
class Comment extends BaseComment
{
/** ... */
/**
* #ORM\ManyToMany(targetEntity="Document", cascade={"persist","remove"})
* #ORM\JoinTable(name="fls_comment_and_documents",
* joinColumns={#ORM\JoinColumn(name="comment_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="document_id", referencedColumnName="id", unique=true)}
* )
*
* #var ArrayCollection $documents
*/
protected $documents;
/** ... */
}
Thanks in advance !