cethyworks/swagger-tools-bundle
Development tools for kleijnweb/swagger-bundle
Doctrine entities, controllers & access-control file generators based on Swagger documents.
$ composer require cethyworks-swagger-tools-bundle
Needs kleijnweb/swagger-bundle to be configured.
$ app/console swagger:generate:entities swagger.yml HelloApiBundle
This command auto-generate doctrine entities based on Swagger file resource definitions.
The resulting entities contains @ORM\ & @Assert\ annotations (@see Supported Swagger Properties below).
See swagger:generate:entities --help for more details.
The id attribute is forced to a guid format & UUID strategy.
The generator does not support relations.
$ 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).
The resultant classes contains all the methods declared and matches the routing generated by kleijnweb/swagger-bundle.
How it works (internal behavior) :
^swagger.{documentName}.{resource}.*.{action}$ from routes{resource}Controller.php with {action(s)} methodsswagger.controller.{resource} serviceSee swagger:generate:controllers --help for more details.
$ 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.
See swagger:generate:access-control --help for more details.
required & x-requiredrequired is used by the swagger validator in KleijnWeb\SwaggerBundle\Test\ApiTestCase, x-required is only used by the generator.
Required properties are defined as an array & at the root level, eg :
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
formatSwagger allow any string as format's value, Use it to add your custom Constraints.
example : format: "AppBundle\Validator\Constraints\MyCustomConstraint"
type: string & format: textThe generator recognize type: string w/ format: text as a doctrine type text.
x-parentCustom swagger property providing the means to declare a parent class to the entity generated.
x-repositoryCustom swagger property providing the means to declare a doctrine repository class to the entity generated.
x-excludeCustom swagger property ; The generator will ignore definitions with x-exclude: false.
x-serializer-excludeCustom swagger property ; The generator will set a @exclude in the entity for the Serializer.
x-uniqueCustom swagger property ; The generator will set this property into @UniqueEntity.
Request $request on put/post&delete (or detect if paramType body)MIT License
How can I help you explore Laravel packages today?