zircote / swagger-php

A php swagger annotation and parsing library
http://zircote.github.io/swagger-php/
Apache License 2.0
5.08k stars 931 forks source link

swagger dynamic generate swagger-docs/swagger.json yii2-rest #280

Closed bhavikac closed 8 years ago

bhavikac commented 8 years ago

hello, i have downloaded yii2-rest with swagger-ui, swagger-doc and swagger-api. it is loading swagger-docs/swagger.json when we run ui of swagger api, i have problem regarding that how can dynamically general this swagger.json file please help

bfanger commented 8 years ago

To generate a swagger.json with swagger-php you'll need to add annotations to your code as described in the Readme.md and docs/Getting-started.md guide.

tech-mint commented 7 years ago

i have same issue. instead of routing swager ui to a static file i want to route it to a swagger-gen.php file. in this file i have written:

$swagger = \Swagger\scan('app/v2/method');

file_put_contents('app/v2/method/swagger.json', json_encode($swagger), LOCK_EX);
chmod("app/v2/method/swagger.json", 0755);

$attachment_location = "app/v2/method/swagger.json";
if (file_exists($attachment_location)) {

    header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
    header("Cache-Control: public"); // needed for internet explorer
    header("Content-Type: application/json");
    header("Content-Transfer-Encoding: Binary");
    header("Content-Length:".filesize($attachment_location));
    header("Content-Disposition: attachment; filename=swagger.json");
    readfile($attachment_location);
    die();
} else {
    die("Error: Swagger File not found.");
}

but swagger ui says:

Failed to load spec.

{"schemaValidationMessages":[{"level":"error","message":"Can't read from file my-domain/api/v2/method/swagger"}]}