Developed with love by KnpLabs Hire us for your project!
69

api2symfony-bundle

by creads

NOT LONGER MAINTAINED - Symfony2 bundle allowing to automatically generate controllers from standard API specifications (RAML, Blueprint, Swagger...)

Api2Symfony Bundle

A Symfony2 bundle to automatically generate controllers from standard API specifications (RAML, Blueprint, Swagger...)

BUT... We only support the following specification formats now:

  • RAML

But we'd like to also support:

  • Blueprint
  • Swagger

This bundle uses the api2symfony library.

Installation

Using composer:

composer require creads/api2symfony-bundle 1.0.*@dev

Register the bundle by updating AppKernel.php:

<?php

// in AppKernel::registerBundles()
if (in_array($this->getEnvironment(), ['dev', 'test'])) {
        // ...
        $bundles[] = new Creads\Api2SymfonyBundle\Api2SymfonyBundle();
        // ...
};

Use case

The bundle provides a command:

app/console.php api2symfony:generate:raml path/to/api.raml Some\\Namespace

Example

php app/console.php api2symfony:generate:raml path/to/api.raml Acme\\DemoBundle

New controller dumped at app/cache/dev/api2symfony/Acme/DemoBundle/1_0_1_alpha/PostsController.php


    #%RAML 0.8
    title: Api Example
    version: 1.0.1-alpha

    /posts:
      description: Collection of available post resource
      get:
        description: Get a list of post
      post:
        description: Create a new post
      /{id}:
        displayName: Post
        get:
          description: Get a single post
          responses:
            200:
              body:
                application/json:
                  example: |
                    {
                      "title": "An amazing news"
                    }
        delete:
          description: Delete a specific post
        /comments:
          description: Collection of available post's comments
          displayName: Comments
          get:
            description: Get list of comment for given post
          post:
            description: Comment a post

Generated code:


    <?php

    namespace Acme\DemoBundle\1_0_1_alpha;

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;

    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

    /**
     * Collection of available post resource
     *
     * This is an auto generated class provided by Creads\Api2Symfony PHP library.
     */
    class PostsController extends Controller
    {
        /**
         * Get a list of post
         *
         * @Route("/posts", name="get_posts")
         * @Method({"GET"})
         */
        public function getPostsAction()
        {

        }

        /**
         * Create a new post
         *
         * @Route("/posts", name="post_posts")
         * @Method({"POST"})
         */
        public function postPostsAction()
        {

        }

        /**
         * Get a single post
         *
         * @Route("/posts/{id}", name="get_posts_post")
         * @Method({"GET"})
         */
        public function getPostsPostAction($id)
        {
            return new Response('{"title": "An amazing news"}', 200, array('Content-Type' => 'application/json'));
        }

        /**
         * Delete a specific post
         *
         * @Route("/posts/{id}", name="delete_posts_post")
         * @Method({"DELETE"})
         */
        public function deletePostsPostAction($id)
        {

        }

        /**
         * Get list of comment for given post
         *
         * @Route("/posts/{id}/comments", name="get_posts_post_comments")
         * @Method({"GET"})
         */
        public function getPostsPostCommentsAction($id)
        {

        }

        /**
         * Comment a post
         *
         * @Route("/posts/{id}/comments", name="post_posts_post_comments")
         * @Method({"POST"})
         */
        public function postPostsPostCommentsAction($id)
        {

        }
    }
Copyright (c) 2014 Creads

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
  • Merge pull request #12 from kix/patch-1
    By pitpit, 4 years ago
  • Update README.md
    By kix, 4 years ago
  • fix readme
    By , 5 years ago
  • fix dependencie version
    By qpautrat, 5 years ago
  • follow dev
    By qpautrat, 5 years ago
  • Merge pull request #6 from creads/bug/require_autoloader
    By qpautrat, 5 years ago
  • fix bootstraping files
    By qpautrat, 5 years ago
  • Merge branch 'master' of github.com:creads/api2symfony-bundle into feature/enhanced-command
    By pitpit, 5 years ago
  • make the question be clever
    By pitpit, 5 years ago
  • Merge pull request #4 from pitpit/feature/enhanced-command
    By qpautrat, 5 years ago
  • wording
    By pitpit, 5 years ago
  • Enhances api2symfony:generate:raml command * add help text to command
    By pitpit, 5 years ago
  • update dependence version
    By qpautrat, 5 years ago
  • resolve deprecated
    By qpautrat, 5 years ago
  • update dependencies
    By qpautrat, 5 years ago
  • Update README.md
    By pitpit, 5 years ago
  • Update LICENSE
    By pitpit, 5 years ago
  • same description everywhere
    By pitpit, 5 years ago
  • Merge pull request #2 from pitpit/feature/moved-dumper
    By qpautrat, 5 years ago
  • Merge pull request #1 from pitpit/bugfix/test-not-conventional
    By qpautrat, 5 years ago
  • removed app/cache files
    By pitpit, 5 years ago
  • fixed command output
    By pitpit, 5 years ago
  • removed unused class
    By pitpit, 5 years ago
  • fixed according to last api2symfony PR https://github.com/creads/api2symfony/pull/8
    By pitpit, 5 years ago
  • ignoring app/cache and app/log
    By pitpit, 5 years ago
  • moved test/ to tests/
    By pitpit, 5 years ago
  • dumper has been moved to https://github.com/creads/api2symfony
    By pitpit, 5 years ago
  • initial commit
    By qpautrat, 5 years ago