Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger-ui no route matches #155

Open
wonderer007 opened this issue Nov 7, 2016 · 2 comments
Open

swagger-ui no route matches #155

wonderer007 opened this issue Nov 7, 2016 · 2 comments

Comments

@wonderer007
Copy link

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

@lal-s
Copy link

lal-s commented Feb 10, 2017

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

@Amir-Elbashary
Copy link

Amir-Elbashary commented Jan 3, 2018

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants