api-platform.com

POST request on many-to-many association

余生长醉 提交于 2021-02-16 15:27:10
问题 I have two entities with a many-to-many association: class User extends BaseUser and class Calendar { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="name", type="text") */ private $name; /** * @var string * * @ORM\Column(name="view", type="text") * @Assert\Choice(choices = {"work week", "week", "month", "year"}, message = "Choose a valid view.") */ private $view; /** *

POST request on many-to-many association

只愿长相守 提交于 2021-02-16 15:27:07
问题 I have two entities with a many-to-many association: class User extends BaseUser and class Calendar { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="name", type="text") */ private $name; /** * @var string * * @ORM\Column(name="view", type="text") * @Assert\Choice(choices = {"work week", "week", "month", "year"}, message = "Choose a valid view.") */ private $view; /** *

How to add Login to swagger UI with API PLATFORM (symfony 4)?

风格不统一 提交于 2021-02-11 13:48:00
问题 I installed & configured LexikJWTAuthenticationBundle, it works fine but I've got a small problem. I have include the Authorization button for put the JWT token, the problem is the only way I can have my token is to use this commands: curl -X POST -H "Content-Type: application/json" http://localhost:8000/api/login_check -d '{"username":"johndoe","password":"test"}' It send my the token and I put it in the API, OK. First problem: When I try this request with POSTMAN I get an error : Unable to

API Platform returns type error instead of validation error when passing null to a string field

送分小仙女□ 提交于 2021-02-10 19:55:21
问题 I'm using API Platform v2.2.5, and in the process of writing tests for my resources I've discovered that, when null is provided for a field of type string , an error response is being returned during the denormalization process, which includes a non client-friendly message and a stack trace. This is different to if an empty string is provided or the field is omitted completely, which returns a structured validation response. How can I instead return a validation error response as when an

How to write custom endpoints with parameters not related to any specific entity

旧时模样 提交于 2021-02-03 21:32:42
问题 I'm trying to write custom GET endpoints, which must have one or more custom parameters, but not built on top of specific entity. Something like: /assets/{device_id}/{scene_id}/{maybe_other_param} which I imagine to be just own controller class, in which I do something, calculate values from input, read some data manually and return array of entities. What I only get is an Asset entity, but it requires {device} and {scene} to be properties of this entity... I don't want this to work as

How to write custom endpoints with parameters not related to any specific entity

前提是你 提交于 2021-02-03 21:26:21
问题 I'm trying to write custom GET endpoints, which must have one or more custom parameters, but not built on top of specific entity. Something like: /assets/{device_id}/{scene_id}/{maybe_other_param} which I imagine to be just own controller class, in which I do something, calculate values from input, read some data manually and return array of entities. What I only get is an Asset entity, but it requires {device} and {scene} to be properties of this entity... I don't want this to work as

How to configure different prefixes for different bundles in api-platform

放肆的年华 提交于 2021-01-29 15:49:22
问题 Console command debug:router show absolutely ALL resources, from all installed Bundles (entity marked with @ApiResource()) How to configure different prefixes for different bundles? Or selectively disable resources. App ignored any path in resource : config/routes/api_platform.yaml api_platform: resource: . type: api_platform prefix: /api With default config config/packages/api_platform.yaml api_platform: mapping: paths: ['%kernel.project_dir%/src/Entity'] 回答1: https://github.com/api-platform

How to create custom update operation that can be rejected depending on the entity current status?

你离开我真会死。 提交于 2021-01-29 10:57:18
问题 I'm creating a custom PUT operation. Not using the built-in operations because the affected property is not included in the default normalization for this entity, and also because this operation has a few side-effects that go beyond this entity/model. Additionally, the update operation should only succeed if the current state of the entity on the DB matches certain expectations. E.g. for the entity class Lead { /** * @ORM\Column(type="integer", nullable=true) * @Groups({"lead", "leadReject" }

Security voter on relational entity field when not using custom subresource path

此生再无相见时 提交于 2021-01-28 11:16:52
问题 I have started doing some more advanced security things in our application, where companies can create their own user roles with customizable CRUD for every module, which means you can create a custom role "Users read only" where you set "read" to "2" and create, update, delete to 0 for the user module. And the same for the teams module. 0 means that he have no access at all. 1 means can access all data under company, 2 means can access only things related to him (if he is owner of an another

PUT operation creates new embedded document instead of updating it on Api Platform

随声附和 提交于 2021-01-28 06:37:23
问题 I am stuck on an issue I cannot solve for few days now. As said in the title, Api Platform PUT operation based on annotations doesn't work as expected with regards to partial update on embedded document with MongoDB ODM. Indeed, despite all the different configurations I tried, I didn't succeed in updating an embedded document already set in a parent document. I tried to change annotations in relevant documents, for example by changing normalization and denormalization groups, by trying