2017 © Pedro Peláez
 

symfony-bundle swagger-tools-bundle

Doctrine entities, controllers & access-control file generators based on Swagger documents.

image

cethyworks/swagger-tools-bundle

Doctrine entities, controllers & access-control file generators based on Swagger documents.

  • Thursday, April 14, 2016
  • by Cethy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Cethyworks\SwaggerToolsBundle

Development tools for kleijnweb/swagger-bundle, (*1)

Doctrine entities, controllers & access-control file generators based on Swagger documents., (*2)

Install

$ composer require cethyworks-swagger-tools-bundle

Needs kleijnweb/swagger-bundle to be configured., (*3)

Commands

Doctrine Entities Generator

$ app/console swagger:generate:entities swagger.yml HelloApiBundle

This command auto-generate doctrine entities based on Swagger file resource definitions., (*4)

The resulting entities contains @ORM\ & @Assert\ annotations (@see Supported Swagger Properties below)., (*5)

See swagger:generate:entities --help for more details., (*6)

Id

The id attribute is forced to a guid format & UUID strategy., (*7)

Relations

The generator does not support relations., (*8)

Controllers Generator

$ app/console swagger:generate:controllers swagger.yml HelloApiBundle

This command auto-generate Controller classes (and corresponding ControllerTest classes) based on the Swagger file paths definitions and register them as services (as needed by kleijnweb/swagger-bundle)., (*9)

The resultant classes contains all the methods declared and matches the routing generated by kleijnweb/swagger-bundle., (*10)

How it works (internal behavior) :, (*11)

  • lists sf2 routes (needs SwaggerBundle working)
  • extracts ^swagger.{documentName}.{resource}.*.{action}$ from routes
  • build {resource}Controller.php with {action(s)} methods
  • register swagger.controller.{resource} service

See swagger:generate:controllers --help for more details., (*12)

Role Based Access Control Configuration Generator

$ app/console swagger:generate:access-control swagger.yml HelloApiBundle

This command auto-generate access-control configuration files based on the Swagger file paths/security definitions and register them in config/security.yml., (*13)

See swagger:generate:access-control --help for more details., (*14)

Supported Swagger Properties

  • readOnly
  • required* (Assert)
  • x-required* (Assert)
  • minLength/maxLength (Assert)
  • minimum/maximum (Assert)
  • minItems/maxItems (Assert)
  • enum (Assert)
  • type (Assert)
  • pattern (Assert)
  • format{date*,date-time*,email,uuid,url, custom*}* (Assert)
  • x-parent*
  • x-exclude*
  • x-serializer-exclude*
  • x-unique*

required & x-required

required is used by the swagger validator in KleijnWeb\SwaggerBundle\Test\ApiTestCase, x-required is only used by the generator., (*15)

Required properties are defined as an array & at the root level, eg :, (*16)

definitions:
  User:
    type: object
    required: ['firstName', 'lastName']
    x-required: ['id']
    properties:
      id:
        type: string
      firstName:
        type: string
      email:
        type: string
      comment: 
        type: string
        format: text

format

Swagger allow any string as format's value, Use it to add your custom Constraints., (*17)

example : format: "AppBundle\Validator\Constraints\MyCustomConstraint", (*18)

type: string & format: text

The generator recognize type: string w/ format: text as a doctrine type text., (*19)

x-parent

Custom swagger property providing the means to declare a parent class to the entity generated., (*20)

x-repository

Custom swagger property providing the means to declare a doctrine repository class to the entity generated., (*21)

x-exclude

Custom swagger property ; The generator will ignore definitions with x-exclude: false., (*22)

x-serializer-exclude

Custom swagger property ; The generator will set a @exclude in the entity for the Serializer., (*23)

x-unique

Custom swagger property ; The generator will set this property into @UniqueEntity., (*24)

Todo

  • Handle one2one relations
  • Handle many2many relations
  • Handle some basic behavior (timestampable)
  • Add Request $request on put/post&delete (or detect if paramType body)
  • exclude.yml file
  • -f/--force instead of -f=true
  • handle Swagger inheritance with allOf

License

MIT License, (*25)

Inspiration

KleijnWeb\SwaggerBundle & KleijnWeb\SwaggerBundleTools, (*26)

The Versions

14/04 2016