swagger-api / swagger-api/swagger-codegen

[php-symfony][question] Generated code contains no entrypoint?

Open
#8,398 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

When I generate a server stub using the php-silex preset I get an index.php. If I google "silex .htaccess" I can easily find the mod_rewrite directives to get it working. However, when I generate code using the php-symfony preset I cannot find the entrypoint.
I attempted to combine the php-silex and php-symfony generated codebases (since silex is a symfony project) like so:

(index.php):
use Swagger\Server\Controller\GetTypesListController;
$app->GET('/image/list/types', function (Application $app, Request $request) {
    $tlc = new GetTypesListController();
    $response = $tlc->getTypeListAction($request);
    return $response;//new Response('How about implementing getTypeList as a GET method ?');
});

However, then I get errors like:

"Fatal error: Uncaught Error: Call to a member function getApiHandler() on null"

I modified the getApiHandler function of my generated GetTypesListController to instantiate the apiServer variable:

public function getApiHandler()
{
    if (!isset($this->apiServer)){
        $this->apiServer = new \Swagger\Server\Api\ApiServer();
    }
    return $this->apiServer->getApiHandler('getTypesList');
}

but this just gave me another error:

Undefined property: Swagger\Server\Controller\GetTypesListController::$container

(referencing SymfonyBundle-php/Controller/Controller.php on line 149)

I am obviously doing something wrong. I would really appreciate being pointed in the right direction.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the php-symfony generated output with the php-silex index.php entrypoint described in the issue. Trace GetTypesListController::getApiHandler and SymfonyBundle-php/Controller/Controller.php around line 149, focusing on how ApiServer and the container are initialized. Done means the generated Symfony server has a documented entrypoint and no longer raises the reported null or undefined-property errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.