cnizzardini / cakephp-swagger-bake

Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
http://cakephpswaggerbake.cnizz.com/
MIT License
59 stars 20 forks source link

Cannot make controller working #534

Closed rudy1976s closed 8 months ago

rudy1976s commented 9 months ago

We have an application based on plugins. We followed the guide and creating a dedicated swagger_bake.php located in the plugin config folder. Here there is the sample code :

return [
    'SwaggerBake' => [
        'prefix' => '/api-blog',
        'yml' => '/vendor/acme/blog/config/swagger.yml',
        'json' => '/vendor/acme/blog/webroot/swagger.json',
        'webPath' => '/acme/blog/swagger.json',
        'hotReload' => Configure::read('debug'),
        'jsonOptions' => JSON_PRETTY_PRINT,
        'editActionMethods' => ['PATCH'],
        'requestAccepts' => [
            'application/json',
            'application/x-www-form-urlencoded',
            'application/xml',
        ],
        'responseContentTypes' => [
            'application/json',
            'application/xml',
            'application/hal+json',
            'application/json+ld'
        ],
        'docType' => 'swagger',
        'exceptionSchema' => 'Exception',
        'namespaces' => [
            'controllers' => ['\Acme\\Blog\\'],
            'entities' => ['\Acme\\Blog\\'],
            'tables' => ['\Acme\\Blog\\Model\\Table']
        ],
    ]
];

we have set up the XMl as follows :

` openapi: "3.0.0" info: version: 2.5.* title: Acme/Blog Api description: | Acme CMS Blog API license: name: MIT License paths: '/api-blog/posts/': get: summary: Index method description: 'This shows using the definitions from YML instead of reading from your cake routes and models. YML definitions take precedence over cake routes and models.' tags:

We have generated the json with the appropriate command.

We have generated routes for the controller we need to manage as follows :

` $routes->scope('/api-blog', function (RouteBuilder $builder) { (new AutoRouter($builder, new ResourceScanner('Acme\Blog')))->buildResources();

$builder->setExtensions(['json','xml']);

$builder->connect('/', [
    'plugin' => 'Acme/Blog', 'controller' => 'Swagger', 'action' => 'index'
]);
$builder->connect('/contexts/*', [
    'plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'contexts'
]);
$builder->connect('/vocab', [
    'plugin' => 'MixerApi/JsonLdView', 'controller' => 'JsonLd', 'action' => 'vocab'
]);
$builder->plugin('Acme/Blog', ['path' => '/'], function ($routes) {
    $routes->resources('Posts', [
        'only' => ['view','index'],
    ]);
    $routes->fallbacks();
});

});

`

Then we have created a controller with only two actions as mapped in the routes :

` declare(strict_types=1);

namespace Acme\Blog\Controller;

use Acme\Blog\Model\Entity\Post; use Acme\Blog\Model\Table\PostsTable; use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Http\Exception\MethodNotAllowedException; use MixerApi\Crud\Interfaces\ReadInterface; use MixerApi\Crud\Interfaces\SearchInterface; use SwaggerBake\Lib\Attribute\OpenApiPaginator; use SwaggerBake\Lib\Extension\CakeSearch\Attribute\OpenApiSearch;

/**

`

The swagger pages is visible, but actually the controller is always asking for view template missing , while it should not do, because we should dealing with restful routes. ( the base controller has request handler component loaded ) I think we miss something but after several trying we are unable to come though. We tried to download and run the mixerapi project ( to check something working) but the docker is not working ( I have opened a ticket for that yesterday ). I know this topic is complicated , but we are stuck, could you please help us understanding what is wrong with our implementation ?

Thank you in advance

Rudy

cnizzardini commented 9 months ago

Can you format this report better? Use triple ticks and specify the language. I fixed one for you so you have an example.

Next can you specify what versions of stuff you are using such as PHP, CakePHP and this library?

cnizzardini commented 9 months ago

When you say the swagger page is loading. Are the routes you expect to be there appearing?

cnizzardini commented 8 months ago

Closing due to lack of feedback.