Search code examples
swaggerswagger-2.0swagger-php

How to use PHP variable in Swagger Annotations


First of all am so excited about this Swagger PHP, very expressive!

Is there any way we can give PHP variables within swagger annotations.

Below is my code:

define('API_PATH', '/api/demo');

/**
 * @SWG\Swagger(
 * basePath="{API_PATH}",
 * host="11.7.11.16:xxxx",
 * schemes={"http"},

Tried giving like $api_path inside annotation as well but its taking as string and API call is failing....

basePath="$api_path",

Any help will be appreciated


Solution

  • You could consider using the constant:

    in constants.php

     define('API_PATH', ''/api/demo");
    

    in api.php

    /**
     * @SWG\Swagger(basePath=API_PATH, ...)
     */
    

    Which can be loaded using the bootstrap option:

    $ swagger --bootstrap constants.php api.php