Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swagger] Added support for customizing the Definition key #1607

Merged
merged 1 commit into from
Dec 26, 2017

Conversation

lyrixx
Copy link
Contributor

@lyrixx lyrixx commented Dec 26, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1583
License MIT
Doc PR api-platform/docs#368

Hello.

I want to customize the Definition key as state in #1583.

I found this way:

/**
 * @ApiResource(
 *      collectionOperations={
 *          "post"={
 *              "method"="POST",
 *              "denormalization_context"={"groups"={"v2_user_read"}, "swagger_definition_name": "HERE_WE_GO"},
 *          },
 *      },
 * )
 */
class User
{

And in order to reduce the code duplication,
when there are many (de)normalization_context,
we can use this shortcut:

/**
 * @ApiResource(
 *      collectionOperations={
 *          "post"={
 *              "method"="POST",
 *              "denormalization_context"=User::API_CREATION_WRITE,
 *          },
 *      },
 * )
 */
class User
{
    const API_CREATION_WRITE = [
        'groups' => ['v2_user_creation_write'],
        'swagger_definition_name' => 'CreationWrite',
    ];
}

If this RFC is accepted I will do the following:

  • Make tests
  • Removed the definition_name in the serializer execution
  • Make a Documenation PR

dunglas
dunglas approved these changes Dec 26, 2017
@dunglas dunglas merged commit e0dfbcd into api-platform:master Dec 26, 2017
@dunglas
Copy link
Member

dunglas commented Dec 26, 2017

Thanks @lyrixx!

@lyrixx lyrixx deleted the model-name branch December 26, 2017 17:05
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
[Swagger] Added support for customizing the Definition key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants