richhollis / swagger-docs

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

index action wrong data #110

Closed isaiev closed 8 years ago

isaiev commented 9 years ago

I added swagger_api: index from readme exaple: swagger_api :index do summary "Fetches all User items" notes "This lists all the active users" param :query, :page, :integer, :optional, "Page number" param :path, :nested_id, :integer, :optional, "Team Id" response :unauthorized response :not_acceptable, "The request you made is not acceptable" response :requested_range_not_satisfiable end

The problem is that I'm not getting a list of all objects, but this: { "apiVersion": "1.0", "swaggerVersion": "1.2", "basePath": "http://localhost:3000/", "resourcePath": "users", "apis": [ { "path": "api/v1/users.json", "operations": [ { "summary": "Fetches all User items", "notes": "This lists all the active users", "method": "get", "nickname": "Api::V1::Users#index" } ] }, { "path": "api/v1/users.json", "operations": [ { "summary": "Creates a new User", "parameters": [ { "paramType": "form", "name": "user[name]", "type": "string", "description": "First name", "required": true }, { "paramType": "form", "name": "user[provider]", "type": "string", "description": "Social provider", "required": true }, { "paramType": "form", "name": "user[uid]", "type": "string", "description": "Social user id", "required": true } ], "responseMessages": [ { "code": 201, "responseModel": null, "message": "Created" }, { "code": 406, "responseModel": null, "message": "Not Acceptable" } ], "method": "post", "nickname": "Api::V1::Users#create" } ] }, { "path": "api/v1/users/{id}.json", "operations": [ { "summary": "Fetches a single User item", "parameters": [ { "paramType": "path", "name": "id", "type": "integer", "description": "User Id", "required": false } ], "responseMessages": [ { "code": 200, "responseModel": "User", "message": "Success" }, { "code": 404, "responseModel": null, "message": "Not Found" } ], "method": "get", "nickname": "Api::V1::Users#show" } ] } ], "models": { "User": { "id": "User", "required": [ "id", "name", "access_token", "provider", "uid" ], "properties": { "id": { "type": "integer", "description": "User Id" }, "name": { "type": "string", "description": "Name" }, "accessToken": { "type": "string", "description": "Access token" }, "provider": { "type": "string", "description": "Social provider" }, "uid": { "type": "string", "description": "Social user id" } }, "description": "A Tag object." } } }

What I'm doing wrong?

krukgit commented 9 years ago

What's your swagger configuration? It looks like it's hitting your documentation folder instead of your api code.

My config/initializers/swagger_docs.rb that more or less works:

class Swagger::Docs::Config
  self.register_apis({
                      "1.0" => {
                                api_file_path: "public/docs/swagger/",
                                base_path: 'http://server.com/',
                                clean_directory: false,
                                base_api_controller: "ApplicationController",
                                camelize_model_properties: false
                               }
                     })
end
richhollis commented 8 years ago

Closing (possible config error).

pdurkim commented 8 years ago

i'm getting the same results

Swagger::Docs::Config.register_apis({
  "3.0" => {
    :api_extension_type => :json,
    :api_file_path => "public",
    :base_path => "http://localhost:3000",
    :clean_directory => false,
    :parent_controller => Api::V3::BaseController
  }
});

Here's a link to my stackoverflow post: http://stackoverflow.com/questions/35786472/swagger-docs-index-method. The post doesn't reflect that everything is currently V3 so ignore the discrepancy.