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

API Platform support: add an --api-resource flag for the make:entity command #178

Merged
merged 5 commits into from
May 17, 2018

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented May 10, 2018

This PR adds a new --api-resource flag to the make:entity command. It allows to automatically a REST endpoint with CRUD operations for the given resource class using API Platform:

screencast

I need some guidance about how to add test for this (actually, a few tests are red locally on my Mac even on master).

Fixes #175.

@weaverryan
Copy link
Member

Ignoring your question about testing for a moment, I don't like the --api-resource flag from a user's perspective. I think it only makes sense to add a new interactive question to make:entity automatically IF ApiPlatform is installed.

@weaverryan
Copy link
Member

Or, the option AND automatically asking if the flag isn’t passed and API Platform is installed

@dunglas
Copy link
Member Author

dunglas commented May 11, 2018

@weaverryan done

capture d ecran 2018-05-11 a 08 00 55

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment. And, we should add a test for this. In FunctionalTest, I would duplicate the entity_new test case that's inside getCommandEntityTests(). There, we can add api as a dependency (so it gets installed) and then interactively answer the new question. To be extra sure, by adding the ->assert(function (string $output, string $directory) { to the test case, you could check the new file for the annotation.

$value = $io->askQuestion($question);

$input->setOption('api-resource', $value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only ask this question when the entity does NOT exist yet. Unfortunately, that means we'll need to duplicate a bit of logic from generate() up here:

$entityClassDetails = $generator->createClassNameDetails(
    $input->getArgument('name'),
    'Entity\\'
);
$classExists = class_exists($entityClassDetails->getFullName());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d003a48 (with some more Voodoo...)

@dunglas
Copy link
Member Author

dunglas commented May 14, 2018

Tests added.

I also transformed Generator in a service: it's better from a design POV (this class should be a service anyway), and it prevents to add a new magic interface to be able to retrieve the Generator instance in the interact method.

IMO we should also remove the Generator argument from the MakerInterface::generate() method and recommend using the service instead (it's allowed by our BC policy, and won't break existing external implementation as long a we still pass this argument even if not defined in the interface). But I'll handle that in another PR, because all other makers need to be updated, and it's not related at all with the purpose of this PR.

@weaverryan
Copy link
Member

Thank you @dunglas!

@weaverryan weaverryan merged commit 1c8cf9a into symfony:master May 17, 2018
weaverryan added a commit that referenced this pull request May 17, 2018
… make:entity command (dunglas)

This PR was squashed before being merged into the 1.0-dev branch (closes #178).

Discussion
----------

API Platform support: add an --api-resource flag for the make:entity command

This PR adds a new `--api-resource` flag to the `make:entity` command. It allows to automatically a REST endpoint with CRUD operations for the given resource class using API Platform:

![screencast](https://user-images.githubusercontent.com/57224/39909149-c6c386e6-54f1-11e8-83a2-bfcd10f5ed39.gif)

I need some guidance about how to add test for this (actually, a few tests are red locally on my Mac even on master).

Fixes #175.

Commits
-------

1c8cf9a Make the Generator class a service
3d2918a Add a functional test
e6ad344 Check if the class exists
ae7c296 Add an interactive question
37b3b9c API Platform support: add an --api-resource flag for the make:entity command
@dunglas dunglas deleted the api-resource branch May 28, 2018 20:37
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.

2 participants