Giter Site home page Giter Site logo

cnizzardini / cakephp-swagger-bake Goto Github PK

View Code? Open in Web Editor NEW
56.0 7.0 19.0 8.57 MB

Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.

Home Page: http://cakephpswaggerbake.cnizz.com/

License: MIT License

PHP 98.60% HTML 0.38% Twig 1.01%
cakephp cakephp4 cakephp-plugin cake-plugin swagger-ui swagger-documentation swagger-bake openapi cakephp-api redoc

cakephp-swagger-bake's People

Contributors

adrian-tiberius avatar archangeldesign avatar bmudda avatar cnizzardini avatar dogmatic69 avatar jamisonbryant avatar julyanof avatar lpj145 avatar nomahideki avatar segy avatar theglenn88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-swagger-bake's Issues

Setup CI pipeline

  • Setup CI pipeline using one of the Saas providers: TravisCI, CircleCI, etc...

SwagRequestBodyContent not working

Describe the bug
Argument 1 passed to SwaggerBake\Lib\OpenApi\Content::setSchema() must be an instance of SwaggerBake\Lib\OpenApi\Schema, string given, called in /var/www/personal/cakephp-swagger-bake/src/Lib/Annotation/SwagRequestBodyContentHandler.php on line 1

To Reproduce

Add the following to an HTTP POST method:

@Swag\SwagRequestBody(description="my description", required=true, ignoreCakeSchema=true)
@Swag\SwagRequestBodyContent(refEntity="#/components/schemas/Actor", mimeType="application/json")

Expected behavior
Expected JSON schema to be accepted

Create response codes from @throws

Response type codes of >= 400 and >= 500 can be created by looking at thrown exceptions.

Get 400 level exception types from Cake Exception classes.

Default to 500 if exception type is unknown or generic.

Support descriptions on @throw tags

Currently @throw only displays the exception classes short name in swagger ui. For example:

    /**
     * Edit method
     *
     * @param string|null $id Employee id.
     * @return \Cake\Http\Response|null|void HTTP 200 on successful edit
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */

Would only display as a 404 with "RecordNotFoundException" as the description. Add in the "When record not found" text to swagger ui.

Parameter spec

Parameter properties to be added:

  • deprecated
  • style
  • explode
  • allowReserved
  • example
  • format

@AbstractParameter annotation properties:

  • deprecated
  • allowEmptyValue
  • style
  • explode
  • allowReserved
  • example
  • format

Putting it together:

AbstractParameter is extended by @SwagQuery, @SwagForm, and @SwagHeader. These annotations are used by their respective classes in calls stemming from OperationFromRouteFactory

Related

XML example cannot be generated; root element name is undefined

Describe the bug
When using XML request or response the following error is generated in Swagger UI:

XML example cannot be generated; root element name is undefined

See swagger-api/swagger-ui#4650

To Reproduce
Set swagger_bake.php config to use XML and reload swagger page. Then go to any post/patch or response.

        'requestAccepts' => ['application/xml'],
        'responseContentTypes' => ['application/xml'],

Expected behavior

Renders example without error

Support Data Transfer Objects

Read a Data Transfer Object (DTO) and optionally set as schema, response schema and/or request schema. To handle as many DTO libraries as possible consider using an Interface. For example:

interface SwaggerBakeDtoInterface
{
    public function getSwaggerReadableArray() : array;
}

class MyDto implements SwaggerBakeDtoInterface
{
    public function getSwaggerReadableArray() : array
    {
        return [
            'fieldName' => 'string',
        ];
    }
}

Need to consider if this will support deep nesting complex data types.

Alternatively. We could accept a DTO class as an annotation argument and parse that for Doc Block comments:

/**
 * @Swag\DataTransferObject(class="\App\Dto\MyDto")
 */
public function index() {}
/**@var string $my_var description of this attribute*/
private $my_var

Feature Request: Merge Swagger.yml and PHP doc block

Right now, the definitions in config/swagger.yml override the ones in PHP doc block. It will be great to merge those so that documentation based detail can remain in doc block and overrides can be defined in the yml file.

Add ability to ignore a controller

Potential solution: Class level annotation on controllers such as @SwagIgnore or @SwagPath

/**
 * @SwagIgnore
 * @SwagPath(isVsible=false)
 */
class FooController
{
...

Schema Property spec

Schema Property properties to be added:

  • title
  • default
  • nullable
  • deprecated
  • multipleOf
  • maximum
  • exclusiveMaximum
  • minimum
  • exclusiveMinimum
  • maxLength
  • minLength
  • pattern
  • maxItems
  • minItems
  • uniqueItems
  • maxProperties
  • minProperties
  • enum

@SwagEntityAttribute annotation properties:

Cake Schema:

  • format

Cake Validator

  • nullable
  • enum (inList)
  • minimum (greaterThanOrEqual)
  • maximum (lessThanOrEqual)
  • maxLength (maxLength)
  • minLength (minLength)
  • pattern (regex)
  • exclusiveMaximum (lessThan)
  • exclusiveMinimum (greaterThan)
  • maxItems (hasAtMost)
  • minItems (hasAtLeast)

Unit Tests:

  • SchemaPropertyValidation
  • SwagEntityAttribute

Misc:

Refactor how controllers are instantiated

SwaggerBack needs to instantiate controllers for doctrine/annotations to parse @Swag annotations and phpdocumentor/reflection-docblock to parse PHP doc blocks.

To do this, SwaggerBake iterates over the namespaces.controllers configuration array until it can find the controller. It does this in a few different places. This kind of hacky.

It should be possible to use the data in RouteDecorator and the configured route prefix for routes.php to instantiate the class. Scenarios to account for are controllers in:

  • App\Controller
  • Controllers that are part of Userland plugins
  • Controllers that are child namespaces of App\Controller (e.g. namespace App\Controller\Admin)
  • Child namespace in Userland plugins (getting fancy now)

Unit tests don't exist for these scenarios, they will need to be built first before a refactor can begin.

  • App\Controller namespace
  • App\Controller child namespace
  • Plugin\Controller namespace
  • Plugin\Controller child namespace

Custom schema type property not being converted properly

Describe the bug
components > schemas > NAME > type is not being set properly. object becomes 1.

To Reproduce
components:
schemas:
Exception:
type: object
properties:
code:
type: integer
example: 500
url:
type: string
example: /url/path
message:
type: string
example: Internal Error

Expected behavior
type object should remain as object.

Add ability to hide/show an entity

Include an entity via an annotation such as @SwagEntity, example:

/**
 * Employee Entity
 *
 * @SwagEntity(isVisibile=bool)
 */
class Employee extends Entity
{
...

This will allow a user to:

  • Hide schemas from displaying using isVisible=false
  • Display schemas that are not tied to routes using isVisible=true

Invalid data types per editor.swagger.io

Describe the bug
Swagger does not support decimal, float, uuid, or text. These need to be converted.

To Reproduce

  1. Generate schema using the cakephp-sakila-plugin
  2. Import JSON into editor.swagger.io
  3. Errors encountered

Expected behavior
No errors.

Path spec

Path properties to be added:

  • ref ($ref)
  • summary
  • description

@SwagPath annotation properties:

  • ref ($ref)
  • summary
  • description

Putting it together:

https://docs.google.com/spreadsheets/d/e/2PACX-1vRTWE7nsTouFdHZsG6OKlZ-1lHeJGI0wqNlRVEgiG4eCFY0dMxkBLaw313mU_a73U7emoRdFcGPUq94/pubhtml
https://swagger.io/specification/

Unit tests for console commands

Console commands don't have any unit tests. Refactor of testing and/or commands may be needed to make them testable.

  • BakeCommand
  • InstallCommand
  • ModelCommand
  • RouteCommand

Reference an entity from controller

Schema is only referenced by paths if the path is a core rest action: index, view, create, edit, and delete. Create a new annotation to force a reference in the response schema.

@SwagResponseSchema(refEntity="string")

See also #13

Schema spec

Schema properties to be added:

  • title
  • not

@SwagEntity annotation properties:

  • title
  • allOf
  • oneOf
  • anyOf
  • not

Putting it together:

  • Set new Schema properties from @SwagEntity annotations in SchemaFactory
  • New unit tests in SwagEntityTest will need annotations added to the test_app. @cnizzardini can assist with this if it proves difficult.

Related

Create demo project

Public demo project available on github and on a public web server showing usage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.