Closed bhavikac closed 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.
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"}]}
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