richhollis / swagger-docs

Generates swagger-ui json files for Rails APIs with a simple DSL.
MIT License
750 stars 150 forks source link

Can't generate a working configuration for two API versions #92

Open donaldpiret opened 10 years ago

donaldpiret commented 10 years ago

I've been fighting for hours trying to get a working config file for swagger-docs, without success. Could use some help. Here is how things are set up for me (using a Rails app): controllers:

controllers ->
  api ->
    v1 ->
      api_controller.rb
      orders_controller.rb
    v2 ->
      api_controller.rb
      orders_controller.rb

Here is the relevant part of my routes:

constraints(ApiMatcher) do
    namespace :api, path: '/' do
      namespace :v2, path: 'v2', as: 'v2' do
        resources :orders, only: [:index, :create, :show, :update, :destroy]
      end

      namespace :v1, path: 'v1', as: 'v1' do
        get '/orders/list', to: 'io#index'

      end
    end
  end

Now I'm finding it completely impossible to get swagger-docs to generate the proper path for both the docs and the actual resources

Here's what I'm trying:

Swagger::Docs::Config.register_apis({
  'v1' => {
    # the extension used for the API
    api_extension_type: :json,
    # the output location where your .json files are written to
    api_file_path: 'public/api/v1',
    # the URL base path to your API
    base_path: 'http://api.poblano.dev:3000',
    controller_base_path: 'api/v1',
    # if you want to delete all .json files at each generation
    clean_directory: true,
    camelize_model_properties: false
  },
  'v2' => {
    # the extension used for the API
    api_extension_type: :json,
    # the output location where your .json files are written to
    api_file_path: 'public/api/v2',
    api_file_name: 'v2.json',
    # the URL base path to your API
    base_path: 'http://api.poblano.dev:3000',
    controller_base_path: 'api/v2',
    # if you want to delete all .json files at each generation
    clean_directory: true,
    camelize_model_properties: false
  }
})

If I don't add the controller_base_path property then the generated paths are correct, but documentation for every single endpoint is generated for both api versions (so it doesn't scope by the proper controller namespace). If I do add the controller_base_path property however my resource paths in the generated documentation look like this:

  "basePath": "http://api.poblano.dev:3000/api/v2/",
  "resourcePath": "carriers",
  "apis": [
    {
      "path": "v2/carriers.json",

Resulting in duplication. I want to get rid of the api/v2 in the base path of the resources. Please help!

donaldpiret commented 10 years ago

Any help on this? We're really stuck because of this issue.

dpehrson commented 10 years ago

Hitting this issue as well, can't find a configuration that works.

fotinakis commented 9 years ago

Just to steal some thunder and offer an alternative here, this is supported by my swagger-blocks gem if you're interested (bearing in mind that it's an unrelated project and a different doc format).

angelolao commented 8 years ago

same issue, what did you guys see? 😄

Stanley3 commented 7 years ago

I also want to know.

harshparihar commented 6 years ago

Facing same issue. Any workaround?