swagger-ui no route matches
wonderer007 opened this issue · comments
I am generating swagger docs using rails 5 API, below is my swagger.rb
class Swagger::Docs::Config
def self.base_api_controller
ActionController::API
end
end
Swagger::Docs::Config.register_apis({
"1.0" => {
:controller_base_path => "",
# the extension used for the API
:api_extension_type => :son,
# the output location where your .json files are written to
:api_file_path => "public",
# the URL base path to your API
:base_path => "http://localhost:3000/api",
# if you want to delete all .json files at each generation
:clean_directory => false,
# add custom attributes to api-docs
:attributes => {
:info => {
"title" => "Bookstore App",
"description" => "This is an API for an online bookstore",
"termsOfServiceUrl" => "https://github.com/switzersc/rails-5-api-tutorial",
"contact" => "shelbyswitzer@gmail.com",
"license" => "Apache 2.0",
"licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
}
}
}
})
I have able to run
rake swagger:docs
successfully and it generated .json file inside public/api folder but I cannot be able to access swagger docs UI through my base path which is http://localhost:3000/api I think I am doing something wrong here
Thanks for reading
Try manually adding a "/" to basePath in api-docs.json
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "/",
"apis": [
{
"path": "some path",
"description": "some description"
}
],
"authorizations": null
}
This did fix it for me but I am still trying to figure out how to solve the problem permanently because it will refresh once you run rake swagger:docs
As a temporary fix i did .sh script
#!/bin/bash -
set -o nounset # Treat unset variables as an error
sed 's/"basePath": "",/"basePath": "/ipa-swagger",/' public/ipa-swagger/api-docs.json > public/ipa-swagger/api-docs-tmp.json;
mv public/ipa-swagger/api-docs-tmp.json public/ipa-swagger/api-docs.json;
#This is the path to my files in my case
FILES=public/ipa-swagger/api/v1/*
for i in $FILES
do
sed 's/"basePath": "",/"basePath": "/",/' $i > $i-tmp;
mv $i-tmp $i;
done
#Example
FILES=public/ipa-swagger/employee_api/v1/*
for i in $FILES
do
sed 's/"basePath": "",/"basePath": "/",/' $i > $i-tmp;
mv $i-tmp $i;
done
Every time you want to refresh your swagger docs you'll have to run
rake swagger:docs && ./script.sh
Hopefully it helps :)