Skip to content

Add a recipe to install API Platform #21

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

Closed
wants to merge 5 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Apr 10, 2017

But I've no idea of how to test it 😅

serializer:
enabled: true
property_info:
enabled: true
Copy link
Member

Choose a reason for hiding this comment

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

That should not be needed. If API platform requires serializer and property_info, they will/should be enabled automatically.

@fabpot
Copy link
Member

fabpot commented Apr 12, 2017

@dunglas You can now easily test PRs :)

Each PR has its own Flex server. So to test this PR for instance, define FLEX_ENDPOINT like this:

FLEX_ENDPOINT=https://pr21.flex.symfony.com/ composer req some/package

@stof
Copy link
Member

stof commented Apr 12, 2017

@fabpot could it be reported on the github repo using the github deployment API so that contributors know when the updated deployment is available and don't have to guess the URL ? It would make it easier (not critical currently as the core team can remember the convention, but much easier once the repo becomes public)

@fabpot
Copy link
Member

fabpot commented Apr 12, 2017

@stof Right now, Symfony Flex creates a commit status as you can see here with the link begin available on "Details". Is that what you're looking for?

@stof
Copy link
Member

stof commented Apr 12, 2017

Well, as green status are collapsed by default, people might not notice that it includes info about a deployment.
Github also has a deployment API, which is dedicated to that, and makes the deployment more visible (the target of the link might be the same than for the commit status).
See this screenshot of how it looks like when using heroku review apps:
github_deployment

The commit status is good to make the PR unmergeable when recipes are invalid. (btw, could the validator be part of the repo like in https://github.com/FriendsOfPHP/security-advisories to allow running it locally or is it too much work ?). The deployment API on the other hand would make it easy to access the temporary deployment.

@fabpot
Copy link
Member

fabpot commented Apr 12, 2017

@stof Done :)

For the validator, it's part of the server, written in Go, so not easy to add to the repository.

@fabpot
Copy link
Member

fabpot commented Apr 12, 2017

@dunglas Have you tested your recipe? Does it work well? I've tried and everything installs correctly at least :)

@dunglas
Copy link
Member Author

dunglas commented Apr 12, 2017

The flex part works great. But I'll need to make some minor changes to do to the API Platform Bundle's configuration to allow it to work without the full stack framework installed.

For now I've to do composer req validator twig doctrine/annotations symfony/property-access to be able to use it. Most of those packages are not required by API Platform's components themselves, I should be adjust the bundle to work with a minimal setup like the one provided by Flex.

The only annoying thing related to Flex is that templates provided by bundles are not discovered automatically:

Unable to find template "ApiPlatformBundle:SwaggerUi:index.html.twig" (looked into: /Users/dunglas/workspace/flex-api/templates).

@dunglas
Copy link
Member Author

dunglas commented Apr 12, 2017

Btw, what is the preferred way to encourage the user to install some extra packages? For instance API Platform works with a minimal setup but the user will miss most interesting features like the Doctrine ORM integration and the UI.

Should I add a post install message like "Type composer require orm twig to enable the user interface and the integration with the Doctrine ORM."?

@stof
Copy link
Member

stof commented Apr 13, 2017

@dunglas you would need to use the @ApiPlatform/SwaggerUI/index.html.twig notation. Otherwise, you also need symfony/templating as a dependency (TwigBundle without the Templating component only supports the native Twig syntax, not the Symfony specific one)

@stof
Copy link
Member

stof commented Apr 13, 2017

For the validator, it's part of the server, written in Go, so not easy to add to the repository.

Then fine. Having the CI can be enough if the report is clear enough (and feedback is fast on push)

@fabpot
Copy link
Member

fabpot commented Apr 14, 2017

@dunglas You should really get rid of the a:b:c template notation and switch to the native Twig notation @ApiPlatform/x.

For optional, but interesting packages, I think adding a post-install-output is the way to go (with some colors to emphasize what needs to be done).

@dunglas
Copy link
Member Author

dunglas commented Apr 15, 2017

Minor issues (including the template notation) fixed in API Platform and pack created.

@fabpot do you have an idea of why it fails? https://pr21.flex.symfony.com/ NVM...

@dunglas
Copy link
Member Author

dunglas commented Apr 15, 2017

Works like a charm!

To test it:

composer create-project symfony/skeleton:dev-temp flex-api
cd flex-api
FLEX_ENDPOINT=https://pr21.flex.symfony.com/ composer require api

Then, create an API for the "Hello" resource class:

<?php

// src/Entity/Hello.php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Say Hello.
 *
 * @ORM\Entity
 * @ApiResource
 */
class Hello
{
    /**
     * @var int The id
     *
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    public $id;

    /**
     * @var string A name
     *
     * @ORM\Column
     * @Assert\NotBlank
     */
    public $name;
}

And finally create the related schema:

bin/console doctrine:schema:create

Go to http://127.0.0.1:8000/ to play with the new API.

@fabpot
Copy link
Member

fabpot commented Apr 15, 2017

That's wonderful! I like it a lot. No configuration, nothing more than pure business logic.

@@ -0,0 +1,3 @@
{
"aliases": ["api", "api-platform"]
}
Copy link
Member

Choose a reason for hiding this comment

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

Only change I would do is that I would not use master as min-supported version. You want this to be compatible with default composer settings in the future, i.e. having a stable release of the api-pack. So you should already add a branch alias for your master branch, and use 1.0 as version in flex instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@fabpot
Copy link
Member

fabpot commented Apr 20, 2017

Thank you @dunglas.

@fabpot fabpot closed this in 0662535 Apr 20, 2017
VolCh pushed a commit to VolCh/recipes that referenced this pull request Nov 30, 2017
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.

4 participants