Giter Club home page Giter Club logo

grape-swagger's People

Contributors

anakinj avatar arturoherrero avatar bikolya avatar calebwoods avatar claymodel avatar dblock avatar dhruvcw avatar frodrigo avatar hedgesky avatar idyll avatar ioanatia avatar jdmurphy avatar joelvh avatar krisalyssa avatar kzaitsev avatar lefnord avatar lest avatar lidimayra avatar magni- avatar mattyr avatar myxoh avatar olleolleolle avatar pbendersky avatar stefan-kolb avatar swistaczek avatar takahashim avatar texpert avatar thogg4 avatar tim-vandecasteele avatar u2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grape-swagger's Issues

uninitialized class variable @@hide_format

NameError (uninitialized class variable @@hide_format in #Class:0x00000006debf88):
grape-swagger (0.6.0) lib/grape-swagger.rb:68:in `block (2 levels) in setup'

i'm using mruby 1.9.2-p290, i dont know whether this will work on higher version, but simply i dont think initialize a class variable in Class.new(Grape::API) can be reached in helpers do(which means Module.new)

No way to specify a 'body' parameter for a PUT request

Because of the following code in grape-swagger.rb, around line 126:

paramType = path.match(":#{param}") ? 'path' : (method == 'POST') ? 'body' : 'query'

you cannot have a nice swagger UI for a PUT method with a text box for body. Should the above be amended to be something like this:

paramType = path.match(":#{param}") ? 
  'path' : (method == 'POST' || method == 'PUT') ? 'body' : 'query'

or should we introduce a DSL way to specify param type of 'body', something along the lines of

params do
  optional :body, body: true, desc: 'This parameter is the body of the request'
end

I am willing to submit a pull request once an acceptable approach is determined..

Empty field for group parameters' name with type hash or Array

Take the following example:

params do
  optional :preferences, type: Array do
    requires :key
    requires :value
  end

  requires :name, type: Hash do
    requires :first_name
    requires :last_name
  end
end

In swagger-ui, there would be an empty text field for preferences and name. Is this suppoed to be this way ? Tested using the github version of grape and grape-swagger.

Thanks

Latest swagger-ui compatibility

Hi,

Great work with this project, I've been using it for a wile to document my grape api's, unfortunately the latest version of swagger-ui throws This API is using a deprecated version of Swagger!

Planning for a new version?

Regards,

API basePath is coming back with port

I am trying to serve the docs from a relative path for an app using HTTPS. The Swagger JSON returns something like

{
  "apiVersion":"v1",
  "swaggerVersion":"1.2",
  "resourcePath":"",
  "apis":[{
    "path":"/auth/user.{format}",
    "operations":[{
      "produces":["application/xml","application/json", "application/vnd.api+json","text/plain"],
      "notes":"",
      "summary":"",
      "nickname":"GET-auth-user---format-",
      "httpMethod":"GET",
      "parameters":[]
     }
  ]}],
  "basePath":"https://accounts.kyck.dev:80/api"}

https and port 80 are in direct conflict. I have tried various options with add_swagger_documentation, including include_base_url: false and root_base_path: false

Not sure what I am doing wrong, but would love some help.

swagger_doc.json being created with incorrect data.

Hello,

I currently have our Grape API mounted at /api, but the swagger_doc.json file being generated does not reflect that fact - it's assuming we have it mounted at /, which causes discovery problems for swagger-UI.

The generated doc looks like (formatted for readability):

{
  "apiVersion":"0.1",
  "swaggerVersion":"1.1",
  "basePath":"http://localhost:3000",
  "operations":[],
  "apis":[
    {
      "path":"/swagger_doc/sites.{format}"
    },
    {
      "path":"/swagger_doc/users.{format}"
    },
    {
      "path":"/swagger_doc/photos.{format}"
    },
    {
      "path":"/swagger_doc/.{format}"
    }
  ]
}

I believe the basePath should be http://localhost:3000/api

Additionally, the apiVersion in the generated doc is 0.1, but the specified version of our API is v1, so I'm not sure what's going on there, but that's also incorrect.

allowMultiple

Hello,

why can't I use the allowMultiple Fieldname described here:
https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#524-parameter-object

Actually I want the multiple option box from:
http://petstore.swagger.wordnik.com/#!/pet/findPetsByStatus

There are predefined values for a parameter with an enum "available, pending, sold":

{
         "path":"/pet/findByStatus",
         "operations":[
            {
               "method":"GET",
               "summary":"Finds Pets by status",
               "notes":"Multiple status values can be provided with comma seperated strings",
               "type":"array",
               "items":{
                  "$ref":"Pet"
               },
               "nickname":"findPetsByStatus",
               "authorizations":{

               },
               "parameters":[
                  {
                     "name":"status",
                     "description":"Status values that need to be considered for filter",
                     "defaultValue":"available",
                     "required":true,
                     "type":"string",
                     "paramType":"query",
                     "allowMultiple":true,
                     "enum":[
                        "available",
                        "pending",
                        "sold"
                     ]
                  }
               ],
               "responseMessages":[
                  {
                     "code":400,
                     "message":"Invalid status value"
                  }
               ]
            }
         ]
      },

undefined method `mount' for class `Class' (NameError)

Hi. I am just updated from 0.2.0 to 0.3.0. As soon I run "rails s" I am getting now this exception:

.rvm/gems/ruby-1.9.3-p392@versioneye/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:8:in singletonclass': undefined methodmount' for class `Class' (NameError)

Any ideas?

Trying to get JSON post documentation right.

I'm hoping this isn't an extremely stupid question...

I loaded up grape-swagger, and set some basic options, and for the most part it is working great! However, I've been stuck trying to figure out how to generate the documentation in a way to tell swagger-ui that my api expects post-data of a json.

Using the same swagger-ui code, I can point to the petstore example api, and see that it looks like it is acting the way I would like, with the param type as body, and they content type as application/json. Inspecting the example petstore endpoint swagger at http://petstore.swagger.wordnik.com:80/api/pet, I suspect that the "consumes: "application/json", and parameter paramType: "body", are the bits that I am not figuring out how to render, and would make the swagger-ui work this way.

Is there any chance someone could give an example of how to do this?

Thanks!

version problem

mount V2 => '/api' (routes.rb)
version 'v2', :using => :path, :vendor => 'hal'
add_swagger_documentation(:base_path => "http://#{APP_CONFIG['default_hosts']["#{Rails.env}"]}/api/v2") if Rails.env.development?
Request URL

http://0.0.0.0:3000/api/v2/{version}/seller/53.json

mounted app does not work with latest grape

I just tried to update my app to the latest grape, but it fails. My app has the API mounted in /api and consists of several mounted grape classes

module API
  class Base < Grape::API
    default_format :json

    mount API::Assets => '/assets'

    add_swagger_documentation(
      hide_documentation_path: true,
    )
  end
end

The /swagger_doc/ is missing in the path for the sub modules.

Do I need to change something to make it work again? Is this a bug?

Questions on documentation - Usage section

Hello,

I need some help regarding the Usage section in the documentation.
Should I put the following code in a file called root.rb and place it under the app/api folder?
I tried that but whe I hit http://localhost:3000/swagger_docs.json I got an error saying that "/swagger_docs.json" does not exist. Do I need to define another route in routes.rb?

require 'grape-swagger'

module API
  class Root < Grape::API
    mount API::Cats
    mount API::Dogs
    mount API::Pirates
    add_swagger_documentation
  end
end

Also, if I only have one set of API, do I still need to do this?
Or can I just put add_swagger_documentation line in the individual API files?

grape-swagger version 0.6.0 not supporting post methods

In version 0.5.0 , the POST methods are working properly
but in version 0.6.0 , i am getting TypeError : can't convert nil into Hash for the POST methods

Full trace:
rack (1.4.5) lib/rack/request.rb:221:in merge' rack (1.4.5) lib/rack/request.rb:221:inparams'
grape (0.5.0) lib/grape/http/request.rb:6:in params' grape (0.5.0) lib/grape/endpoint.rb:172:inparams'
grape (0.5.0) lib/grape/endpoint.rb:395:in block in run' grape (0.5.0) lib/grape/endpoint.rb:394:ineach'
grape (0.5.0) lib/grape/endpoint.rb:394:in run' grape (0.5.0) lib/grape/endpoint.rb:164:inblock in call!'
grape (0.5.0) lib/grape/middleware/base.rb:24:in call' grape (0.5.0) lib/grape/middleware/base.rb:24:incall!'
grape (0.5.0) lib/grape/middleware/base.rb:18:in call' grape (0.5.0) lib/grape/middleware/base.rb:24:incall!'
grape (0.5.0) lib/grape/middleware/base.rb:18:in call' grape (0.5.0) lib/grape/middleware/error.rb:26:inblock in call!'
grape (0.5.0) lib/grape/middleware/error.rb:25:in catch' grape (0.5.0) lib/grape/middleware/error.rb:25:incall!'
grape (0.5.0) lib/grape/middleware/base.rb:18:in call' rack (1.4.5) lib/rack/head.rb:9:incall'
rack (1.4.5) lib/rack/builder.rb:134:in call' grape (0.5.0) lib/grape/endpoint.rb:165:incall!'
grape (0.5.0) lib/grape/endpoint.rb:155:in call' rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:inblock in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in block in recognize' rack-mount (0.8.3) lib/rack/mount/code_generation.rb:68:inoptimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in recognize' rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:incall'
grape (0.5.0) lib/grape/api.rb:480:in call' grape (0.5.0) lib/grape/api.rb:49:incall!'
grape (0.5.0) lib/grape/api.rb:45:in call' journey (1.0.4) lib/journey/router.rb:68:inblock in call'
journey (1.0.4) lib/journey/router.rb:56:in each' journey (1.0.4) lib/journey/router.rb:56:incall'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in call' omniauth (1.1.4) lib/omniauth/strategy.rb:184:incall!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in call' omniauth (1.1.4) lib/omniauth/strategy.rb:184:incall!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in call' newrelic_rpm (3.6.5.130) lib/new_relic/rack/error_collector.rb:12:incall'
newrelic_rpm (3.6.5.130) lib/new_relic/rack/agent_hooks.rb:22:in call' newrelic_rpm (3.6.5.130) lib/new_relic/rack/browser_monitoring.rb:16:incall'
newrelic_rpm (3.6.5.130) lib/new_relic/rack/developer_mode.rb:28:in call' rack-google-analytics (0.11.0) lib/rack/google-analytics.rb:18:in_call'
rack-google-analytics (0.11.0) lib/rack/google-analytics.rb:15:in call' warden (1.2.1) lib/warden/manager.rb:35:inblock in call'
warden (1.2.1) lib/warden/manager.rb:34:in catch' warden (1.2.1) lib/warden/manager.rb:34:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in call' rack (1.4.5) lib/rack/etag.rb:23:incall'
rack (1.4.5) lib/rack/conditionalget.rb:35:in call' actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in call' actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:incall'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in context' rack (1.4.5) lib/rack/session/abstract/id.rb:205:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in call' activerecord (3.2.13) lib/active_record/query_cache.rb:64:incall'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in call' actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in _run__153453904__call__699551650__callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:405:in__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in _run_call_callbacks' activesupport (3.2.13) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in call' actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in call' railties (3.2.13) lib/rails/rack/logger.rb:32:incall_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in block in call' activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:intagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in call' actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:incall'
rack (1.4.5) lib/rack/methodoverride.rb:21:in call' rack (1.4.5) lib/rack/runtime.rb:17:incall'
activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.4.5) lib/rack/lock.rb:15:incall'
actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in call' railties (3.2.13) lib/rails/engine.rb:479:incall'
railties (3.2.13) lib/rails/application.rb:223:in call' railties (3.2.13) lib/rails/railtie/configurable.rb:30:inmethod_missing'
rack-cors (0.2.8) lib/rack/cors.rb:54:in call' rack (1.4.5) lib/rack/content_length.rb:14:incall'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in call' thin (1.5.1) lib/thin/connection.rb:81:inblock in pre_process'
thin (1.5.1) lib/thin/connection.rb:79:in catch' thin (1.5.1) lib/thin/connection.rb:79:inpre_process'
thin (1.5.1) lib/thin/connection.rb:54:in process' thin (1.5.1) lib/thin/connection.rb:39:inreceive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in run_machine' eventmachine (1.0.3) lib/eventmachine.rb:187:inrun'
thin (1.5.1) lib/thin/backends/base.rb:63:in start' thin (1.5.1) lib/thin/server.rb:159:instart'
rack (1.4.5) lib/rack/handler/thin.rb:13:in run' rack (1.4.5) lib/rack/server.rb:268:instart'
railties (3.2.13) lib/rails/commands/server.rb:70:in `start'

can you help me identify the problem

How do can I reorganize the endpoints?

Hi,

So let's say we have an Eclass endpoint. Inside there are several other endpoints. In this specific case, how could I make the /api/v2/eclasses/{eclass_id}/users.jsona top level endpoint (such as Eclasses?

captura de pantalla 2014-02-19 a la s 09 18 40

entity documentation support for array of entities?

hi there I have the following grape-entites

module HQ
  module Entities
    class Client < Grape::Entity
      expose :created_by_id, documentation: {type: Integer, desc: "Created by id"}
      expose :updated_by_id, documentation: {type: Integer, desc: "Updated by id"}
      expose :first_name,    documentation: {type: String, desc: 'First Name.'}
      expose :last_name,     documentation: {type: String, desc: 'Last Name.'}
      expose :zipcode,       documentation: {type: String, desc: 'Zip Code.'}
      expose :emails, using: HQ::Entities::Email, documentation: {type: ::Item, desc: 'Emails.'}
    end
  end
end

module HQ
  module Entities
    class Email < Grape::Entity
      expose :address, documentation: {type: Integer, desc: "Email"}
    end
  end
end

the problem that I need that swagger generate the UI with the complex form I means client has many emails

      expose :emails, using: HQ::Entities::Email, documentation: {type: Array, desc: 'Emails.'}

what type I need to use? I added array but it show me just as string field like this

https://www.evernote.com/shard/s143/sh/a53f78c8-5599-4148-811f-e6b7617cd13a/419383ac0d5d9e5bac0a06278ac481da

$ref for complex nested data types

Hi,
Does anyone knows how to use grape-swagger to generate documentation for complex response data types?
For example:
I have the following grape entity

  class CreatedCustomer < BaseEntity
    expose :customer, using: Entities::Customer, documentation: { type: 'Customer'}
    expose :token, using: Entities::AuthResult, documentation: { type: 'AuthResult'}

When I generate documentation for CreatedCustomer response there is no $ref inside CreatedCustomer model which is as far as I understood the way to reference complex models in swagger. Moreover the only model generated by grape-swagger is CreatedCustomer.
Generated model looks like this:

"CreatedCustomer":
{"id":"CreatedCustomer","name":"CreatedCustomer",
"properties":{"customer":{"type":"Customer"}
}}

While i would expect something like this(ignoring second field for sake of example)

"CreatedCustomer":
{"id":"CreatedCustomer","name":"CreatedCustomer",
"properties":{"customer":{"$ref":"Customer"}
}}

"Customer":
{"id":"Customer", "name":"Customer",
"properties":{"email":{"type":"string"}
}}

Example app?

I'm having a hard time getting it to work correctly. Anybody has a demo app I can take a look at?

swagger-ui doesn't honor required parameters in optional group

Take for example the following :

params do
  requires :id, type: Integer
  optional :text, type: String, regexp: /^[a-z]+$/
  group :media do
    requires :url
  end
  optional :audio do
    requires :format, type: Symbol, values: [:mp3, :wav, :aac, :ogg], default: :mp3
  end
end
put ':id' do
  # params[:id] is an Integer
end

When using swagger-ui, the parameter format is always required, even though audio is optional.

this gem supports model schema and body param type ?

hi there I was seeing the code but seems that this gem doesnt support models and body param type, this is correct? I need that swagger-ui shows model schema and body param like this screenshot

captura de pantalla 2014-04-08 a la s 18 05 12

I have some way to do that with this gem?

thanks for advance

response content-types

Hi (again)
not sure if this is the right place to set the issue, but, what I have to do to describe the endpoints and being able to select the response content_type (actually, json or xml, jsonp later) from swagger-ui? I've seen the documentation(s, for grape and swagger) and I didn't find anything. Even trying

content_type :json, 'application/json'
content_type :xml, 'application/xml'

I didn't got anything. Using grape, grape-swagger with RoR 3.1.3
Cheers

w i l l y

Post params are not recognized (?)

Hi, im stucked... It seems that POST params are not displayed/parsed right. (GET is working)

An example:

desc "POST example with param"
params do
  requires :id, :type => Integer, :desc => "id."
end  
post :test do
  User.find_by_id(params[:id])
end

This endpoint works as expected with this command: (it return a JSON object of selected user)

curl -X POST -d '{"id": 1}' http://localhost:3000/api/v1/users/test.json -H 'Accept: application/json' -H 'Content-Type:application/json' -s

But the swagger-UI renders a textarea instead a simple input field and seems not to send the data in JSON.
The API yells:

"undefined method `each' for 1:Fixnum" 

Inspecting, it tells me, that the body is just "1", shouldn't this be {"id": 1}?

The generated definition:

        {
            "path": "/v1/users/test",
            "operations": [
                {
                    "notes": null,
                    "summary": "POST example with param",
                    "nickname": "POST--version-users-test---format-",
                    "httpMethod": "POST",
                    "tags": null,
                    "errorResponses": null,
                    "deprecated": null,
                    "responseClass": null,
                    "parameters": [
                        {
                            "paramType": "body",
                            "name": "id",
                            "description": "id.",
                            "dataType": "Integer",
                            "required": true,
                            "allowableValues": null,
                            "defaultValue": null,
                            "allowMultiple": null
                        }
                    ]
                }
            ]
        }

Or (hopefully...) did I miss something? Thanks and regards, Klaas

How to use it in Rails?

Can someone help me understand how I can configure grape-swagger on a Rails app? I followed the instructions, but I'm still having trouble. swagger_doc.json is throwing a routing error.

...help??

Dynamic BasePath with prefix

I want to mount my route api on /api/

for some reason grape-swagger doesn't pick this up by default. I assume it is because of request.base_url.

There is a handy config option called :base_path but sadly this is a simple variable and wont have access to the request object and since I do not want to hard code the hostname it wont work.

I tried setting this to a lambda function with out much joy as well.

I hacked around this by adding a :base_path_suffix config option see drubin@93608a5

add_swagger_documentation({
   :base_path_suffix=> '/api', 
   :api_version=>'v1',
   :hide_documentation_path=>true,
   :markdown=>true
   }
  )

If any one has a better work around? or can point me in why request would not work as part of a lambda function it would be great.

Project dead?

No, really? A bunch of damn useful pull requests, hanging there for months, and not a single comment given. Tim, I know you're alive, give some love to this repo, will you?

Passing required http headers to Swagger

Swagger supports 3 types of parameters: query, body and header. Since it is common to place and authentication token in the header of an app, or to even use basic authentication with a token, we need a way to move this into swagger.

To get this going I think the simplest way to start is placing headers in the same block with notes and just describing them.

In the future I am thinking we need to add a special header field specifically for basic auth into swagger-ui because even though you can add the Authorization header you still need to Base64 encode either your token or your username/password combo.

I have a working version of the former in a branch on my fork. The latter needs more thought.

Both need to have discussions on how this should properly be moved into Grape - if it is providing a facility for required parameters then it should also handle prescribing basic auth or required headers.

Should be able to override the generated nicknames

Currently we have to accept the nickname that is auto generated for each operation. It would be nice to be able to specify a nickname in the endpoint directly.

I have a fix for this and will be submitting a pull request shortly.
/Leon

Configuring add_swagger_documentation (using Rails)

Hi,
I am a little unclear on how to set the :mount_path and/or :base_path options on add_swagger_documentation. Here’s my context:

Rails’ routes.rb:

    require 'grape'
          Blog::Application.routes.draw do
              mount Blog::API => "/api"
         end 

The API code:

       module Blog
        class API < Grape::API
       mount Blog::API1
       add_swagger_documentation  
            end
         end
        module Blog
           class API1 < Grape::API
       format  :json 
       before do
          header['Access-Control-Allow-Origin'] = '*'
          header['Access-Control-Request-Method'] = '*'
        end
                resource :weblogs do
                ……and so on ……

So, for add_swagger_documentation, how do I set the :mount_path and/or :base_path options?

Many thanks, D

Undefined method 'mount'

I don't run Rails but Goliath. How should I mount API's when I don't have the mount method?
I tried PadrinoEatsGrape but it's pretty confusing and files are missing (boot.rb etc).

I tried the Rack way e.g 'run API_FOO' in a config.ru file but:
gems/grape-swagger-0.2.0/lib/grape-swagger.rb:6:in singletonclass': undefined methodmount' for class `Class' (NameError)

Should I try to find a rack middleware that gives the mount method?

Occasional (inconsistent) Ruby 1.9 idioms

My environment still requires sticking to v.1.8.7. When trying to rack up my app, I get error messages for 1.9-style hash declarations:

/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/backports-2.6.5/lib/backports/tools.rb:314:in `require_without_backports': /home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:71: odd number list for Hash (SyntaxError)
                apiVersion: api_version,
                           ^
/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:71: syntax error, unexpected ':', expecting '}'
                apiVersion: api_version,
                           ^
/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:72: syntax error, unexpected ':', expecting '='
                swaggerVersion: "1.1",
                               ^
/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:72: syntax error, unexpected ',', expecting kEND
/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:73: syntax error, unexpected ',', expecting kEND
/home/uriel/.rvm/gems/ruby-1.8.7-p352/gems/grape-swagger-0.3.0/lib/grape-swagger.rb:75: syntax error, unexpected ':', expecting kEND
                apis: routes_array

Cannot test Grape API (inside Rails 3) using online swagger UI.

Hi,

I have a Rails 3 application with a REST API built using Grape. Some relevant code excerpts are as follows:

routes.rb

   require 'grape'
   Blog::Application.routes.draw do  
       mount Blog::API => "/"
   end

api.rb

  require 'grape'
  require 'grape-swagger'
  module Blog
      class API < Grape::API
       mount Blog::API1
      add_swagger_documentation
  end
  end

api1.rb

   require 'grape'
   module Blog
      class API1 < Grape::API
          format :json
          resource :weblogs do
               get do
                   Weblog.all
               end
          ……………………..

The API works fine when I test it with curl. I’ve deployed it to Cloud Foundry if you want to test it. The URL is http://blog-api.cloudfoundry.com and a sample curl request would be:
curl -i http://blog-api.cloudfoundry.com/weblogs

I’ve followed your instructions for adding grape-swagger and then try to explore it using the online swagger demo. Everything renders ok, however, when I test any part of my api using the demo, the response body is empty and the response code is 0; although the log file on the server-side shows the request being handled. Any thoughts as to what is wrong?

Many thanks, Diarmuid

Grape 4.0.0

Any plans to update this lib in that way that it works together with Grape 4.0.0 ?

Release updated gem

Last release (v0.3.0) was in October 2012. Can you release an update that works with grape 0.3.x? Current master branch depends on grape 0.2.0.

I believe I have issues with 0.3.0 gem which were fixed in commits some time ago.

Thanks!

Pickup API version from Grape

I am unclear about how to specify the API version.
When I set version 'v1' then I still see "apiVersion":"0.1" in the JSON, which was a surprise for me.

More details:

In this implementation grape-swagger sets the apiVersion to 0.1:

class Root < Grape::API
  version 'v1', :using => :path
  add_swagger_documentation
  [...]
end
{"apiVersion":"0.1","swaggerVersion":"1.1",...}

In this implementation grape-swagger sets the apiVersion to v1

class Root < Grape::API
  version 'v1', :using => :path
  add_swagger_documentation :api_version => "v1"
  [...]
end
{"apiVersion":"v1","swaggerVersion":"1.1",...}

The 2nd implementation example looks redundant to me. I might just not understand how this is meant to be used.

Is this the intended behavior?

Option to completely hide API route if unauthorized

I want to make only some routes visible to all users and some only to people who have an API key. I don't want to show them in Swagger at all if they don't provide a valid API key (this would be useful for admin API or unpublished features).

Is it possible? I couldn't find a solution for this.

Where is the correct place to document HTTP status code handling?

In the combination of grape, grape-swagger, and swagger UI, it is sometimes difficult to figure out where the correct place for documenting certain features is.

Here my understanding of the components, just to double check that I got this right:

  • grape (for building the API)
  • grape-swagger (for building swagger specs out of a grape API)
  • swagger UI (for building an interactive console

Now my question:

Swagger supports the documentation of the HTTP status codes that are generated by an API. I couldn't find any explanation in either of the relevant repositories about how to create a grape API such that grape-swagger can pick up the status codes automatically.

I read the source of grape-swagger and from there derive that this is how it works:

    get '/', :http_codes => [
      [400, "Invalid parameter entry"],
    ] do
      ...
    end

This leads to this JSON snippet in the generated swagger specs:

  "operations": [
    {
      "errorResponses": [
        {
          "reason": "Invalid parameter entry ",
          "code": 400
        }
      ],

And it is visualized in swagger UI like this:
http_status_code_swagger

Any recommendation on where this feature should be documented?

Question: Swagger-compliant JSON generation for Rails

This is a question, rather than an issue. Sorry for abusing the project issues for this purpose but I didn't see a better way to contact you.

My question is if you came a across a gem that can generate Swagger-compliant JSON for pure Rails APIs? I am currently using plain ActionControllers and ActiveModel::Serializer for my API, and I haven't found a way yet to marry that with Swagger nicely.

Out of curiosity: Why do you favor grape for API building?

Thanks a lot :)

File Upload

One of the API Endpoints expects an file upload. The api works fine, but swagger-ui does not render an file upload. Instead of that it renders an input filed. What I have to do to get a file upload rendered?
Many Thanks in advance.

Adding swagger documentation for multiple Grape APIs in single Rails app

In our Rails app we are mounting two separate Grape APIs, e.g. /api/partner/v1 and /api/clients/v1. Now when I call add_swagger_documentation for each of these APIs, two separate swagger_doc entry points are mounted correctly. However querying these two entry points returns the same API documentation. E.g. querying /api/partner/v1/swagger_doc.json returns the documentation for API::Partner but querying /api/clients/v1/swagger_doc.json also returns the documentation for API::Partner.

I've been doing some debugging on this issue and it seems that the @@target_class class variable points to the same API class in the get @@mount_path definition:

get @@mount_path do
  Rails.logger.debug("XXXX self class: #{self.class}, #{self.class.object_id}")
  header['Access-Control-Allow-Origin'] = '*'
  header['Access-Control-Request-Method'] = '*'
  routes = @@target_class::combined_routes
  Rails.logger.debug("XXXX routes for #{@@target_class}: #{routes}")

This is despite the fact that two separate documentation classes get created with separate class variable. Somehow these class variables get merged into a single new instance of the Grape::Endpoint class. Here is what I see in the logs:

Started GET "/api/client/v1/client_api_docs.json" for 127.0.0.1 at 2013-03-06 01:38:24 +0800
XXXX self class: Grape::Endpoint, 70097079507800
XXXX routes for API::Client: {"search"=>[version=v1, method=GET, path=/:version/search(.:format)]}

Started GET "/api/partner/v1/partner_api_docs.json" for 127.0.0.1 at 2013-03-06 01:19:14 +0800
XXXX self class: Grape::Endpoint, 70097079507800
XXXX routes for API::Client: {"client_api_docs"=>[version=v1, method=GET, path=/:version/client_api_docs(.:format), version=v1, method=GET, path=/:version/client_api_docs/:name(.:format)], "search"=>[version=v1, method=GET, path=/:version/search(.:format)]}

Maybe this data shouldn't be stored in class variables?

Header params

I created a repository (https://github.com/robertogyn19/grape-swagger-header) explaining the problem and how to reproduce it. If anyone has the same problem or can help me. I'm not even sure if the problem is in the grape-swagger.

The swagger-ui version: [Master](https://github.com/wordnik/swagger-ui/tree/4601f6270235489581acd80548620716506311a5 /)

Problem with header param on request

I'm having a problem to send the api_key parameter in the header of the request. Something like:

window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));

The swagger makes an OPTIONSrequest to the server and request / response headers is something like:

Request Headers:
OPTIONS /doc HTTP/1.1
Host: localhost:9292
Access-Control-Request-Method: GET
Origin: http://localhost:3001
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
Access-Control-Request-Headers: api_key
Accept: */*
Referer: http://localhost:3001/

Response Headers:
HTTP/1.1 204 No Content
Access-Control-Request-Headers: Content-Type, api_key
Access-Control-Request-Method: GET, POST, DELETE, PUT, PATCH, OPTIONS
Access-Control-Allow-Origin: *
Allow: OPTIONS, GET, HEAD
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-06-27)
Date: Wed, 20 Nov 2013 17:00:58 GMT
Connection: Keep-Alive

However I get an error message:

OPTIONS http://localhost:9292/doc Request header field Api_key is not allowed by Access-Control-Allow-Headers.

From what I read, thoroughly, this error is due to CORS, but api_key parameter is Access-Control-Request-Headers.

To check I executed:

$curl -i -X OPTIONS -H "api_key: '123'" -u roberto:pass localhost:9292/doc.json

HTTP/1.1 204 No Content 
Access-Control-Request-Headers: Content-Type, api_key, Authorization
Access-Control-Request-Method: GET, POST, DELETE, PUT, PATCH, OPTIONS
Access-Control-Allow-Origin: *
Allow: OPTIONS, GET, HEAD
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-06-27)
Date: Wed, 20 Nov 2013 17:41:36 GMT
Connection: Keep-Alive

To reproduce the error, follow these steps:

1. git clone [email protected]:robertogyn19/grape-swagger-header.git
Start server (localhost:9292)
2.1. cd grape-swagger-header/grape-swagger
2.2. gem install bundler (if not installed)
2.3. bundle install
2.4. bundle exec rackup
Start swagger client (localhost:3001)
3.1. cd grape-swagger-header/swagger-ui
3.2. npm install
3.3. node app.js
4. Open a browser on http://localhost:3001
5. Put any value on api_key box and click Explore

If you need any other information, let me know.

localhost is not allowed to access

Hi there
yes, I've read the 'Usage' section of the readme and checking the previous issues, and I have a quite opposite issue than Issue #19.
I have the API built using Rails 3 and the swagger-ui, both in the same machine, API responding on port 3003 (by running rails -p 3003 app-api), swagger-ui in the localhost/~user/Sites and, in addtition, in another_computer/~user/public_html, for remote testing purposes. In both cases, the API funcitons are listed ok, but it is impossible to make requests, I always get in debugger the (in)famous

submitting http://localhost:3003/api/uniprot/status.json
XMLHttpRequest cannot load http://localhost:3003/api/uniprot/status.json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

I have at the top of the file defining the API:

before do
    header['Access-Control-Allow-Origin'] = '*'
    header['Access-Control-Request-Method'] = '*'
    header['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT, PATCH, DELETE'
    header['Access-Control-Allow-Headers'] = 'true'
end

It is more than it is indicated at the docs, but after reading a couple of forum I just wanted to be sure.
And it is working OK if I use the online swagger-ui service...

I know I am missing something but I can't figure out what. can anybody light me up to solve this (annoying) issue??

Cheers and sorry if this is an silly (and repeating) issue.

w i l l y

swagger-codegen compatibility for output of client libraries from a grape API

I tried this recently without much luck as a couple of the fields were missing from the swagger description emitted by grape-swagger. Foolishly I didn't document this at the time so I'm not sure which fields these were. It may be the case that adding these fields isn't possible with the current grape DSL. I will investigate further as I require this functionality but have added this issue for now as a stake in the ground.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.