1

I have a custom Operation CreatePerson which is dispatched via messenger.

/**
 * @ApiResource(
 *     messenger=true,
 *     output=false,
 *     shortName="person",
 *     collectionOperations={
 *         "post"
 *     },
 *     itemOperations={}
 * )
 *
 * @psalm-immutable
 */
final class CreatePerson

This works as expected with POST /api/people (people instead of person because ApiPlatform uses Inflection to pluralize the shortname on collectionOperations.

The API-Docs look like that:

enter image description here

I'd like to add a list of persons, too. So I created an other Api-Resource:

/**
 * @ApiResource(
 *     collectionOperations={
 *         "get"
 *     },
 *     itemOperations={}
 * )
 *
 * @psalm-immutable
 */
final class Person

The shortname of my customOperation ist person. This is also the group in the docs I want my list operation in.

Everything works as expected. Person and CreatePerson are two ApiResources. But now my docs look like that:

enter image description here

I want to group them both together in the API-Docs (because they belong together).

The reason why I use an extra CreatePerson-DTO here is because I use Api-Platform completely without doctrine. The DTO gets dispatched through messenger and creates a Person via Event-Sourcing. The Person-class is a readonly projection.

4
  • I don't understand. The command is CreatePerson. But the error message points to App\Entity\Person. Not possible to answer with this amount of detail. It is entirely possible to add custom operations this way (dto + messenger), so something else is amiss in your setup. Commented Jan 12, 2020 at 11:03
  • Thanks for the answer, I tried to clarify my question. Commented Jan 12, 2020 at 12:13
  • Yeah, but the clarification does not really clear things up for me. The previous revision had a configuration that seemed OK, but an error message that was not consistent with that configuration. I could answer this revision, but in the end I would just be repeating the configuration you had in the previous revision. Sorry. Commented Jan 12, 2020 at 12:19
  • The previous revision was me trying to hack around the problem. I found out why the group does not work as expected. I had to change the shortName="person" to shortName="Person" and that's it. Commented Jan 12, 2020 at 12:21

1 Answer 1

-1

The solution for me was using openapi_context.

/**
 * @ApiResource(
 *     messenger=true,
 *     output=false,
 *     collectionOperations={
 *          "post"={
 *              "method"="POST",
 *              "path"="/people",
 *              "openapi_context"={
 *                  "tags"={
 *                      "Person"
 *                  },
 *             },
 *         },
 *     },
 *     itemOperations={},
 * )
 *
 * @psalm-immutable
 */
final class CreatePerson

And Person:

/**
 * @ApiResource(
 *     collectionOperations={
 *          "get"
 *     },
 *     itemOperations={},
 * )
 * @ORM\Entity(repositoryClass="App\Repository\PersonRepository")
 *
 * @psalm-immutable
 */
final class Person

(seen here: https://github.com/api-platform/docs/issues/143)

With the following result in the docs:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.