Skip to content

Commit 2a07023

Browse files
author
Craig S. Cottingham
committed
Merge pull request #105 from CraigCottingham/swagger-ui
Change output to be compatible with swagger-ui
2 parents ef40b78 + 50e968c commit 2a07023

13 files changed

+374
-229
lines changed

.ruby-gemset

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grape-swagger

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby-2.0.0-p353

.rvmrc

-48
This file was deleted.

README.markdown

+77-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ end
4545

4646
## Configure
4747
You can pass a hash with some configuration possibilities to ```add_swagger_documentation```, all of these are optional:
48-
* ```:mount_path``` The path were the API documentation is loaded, default '/swagger_doc'
48+
49+
* ```:target_class``` The API class to document, default `self`
50+
* ```:mount_path``` The path where the API documentation is loaded, default '/swagger_doc'
51+
* ```:class_name```
52+
* ```:markdown``` Allow markdown in `notes`, default `false`
53+
* ```:hide_format``` , Don't add '.(format)' to the end of URLs, default `false`
4954
* ```:api_version``` Version of the API that's being exposed
5055
* ```:base_path``` Basepath of the API that's being exposed, this configuration parameter accepts a Proc to evaluate base_path, useful when you need to use request attributes to determine the base_path.
51-
* ```:markdown``` Allow markdown in `notes`, default `false`
56+
* ```:authorizations``` Added to the `authorizations` key in the JSON documentation
57+
* ```:include_base_url``` Add base path to the URLs, default `true`
58+
* ```:root_base_path``` Add `basePath` key to the JSON documentation, default `true`
59+
* ```:info``` Added to the `info` key in the JSON documentation
60+
* ```:models``` Allows adds an array with the entities for build models specifications. You need to use grape-entity gem.
5261
* ```:hide_documentation_path``` Don't show the '/swagger_doc' path in the generated swagger documentation
53-
62+
* ```:format```
5463

5564
## Swagger Header Parameters
5665

@@ -113,6 +122,71 @@ module API
113122
end
114123
```
115124

125+
### Relationships
126+
127+
1xN
128+
129+
```ruby
130+
module API
131+
module Entities
132+
class Client < Grape::Entity
133+
expose :name, :documentation => { :type => "string", :desc => "Name" }
134+
expose :addresses, using: Entities::Address, documentation: {type: 'Address', desc: 'Addresses.', param_type: 'body', is_array: true}
135+
end
136+
137+
class Address < Grape::Entity
138+
expose :street, :documentation => { :type => "string", :desc => "Street." }
139+
end
140+
141+
end
142+
143+
class Clients < Grape::API
144+
version 'v1'
145+
146+
desc 'Clients index', {
147+
params: Entities::Client.documentation
148+
}
149+
get '/clients' do
150+
...
151+
end
152+
end
153+
add_swagger_documentation models: [Entities::Client, Entities::Address]
154+
end
155+
```
156+
157+
1x1
158+
159+
Note: is_array is false by default
160+
161+
```ruby
162+
module API
163+
module Entities
164+
class Client < Grape::Entity
165+
expose :name, :documentation => { :type => "string", :desc => "Name" }
166+
expose :address, using: Entities::Address, documentation: {type: 'Address', desc: 'Addresses.', param_type: 'body', is_array: false}
167+
end
168+
169+
class Address < Grape::Entity
170+
expose :street, :documentation => { :type => "string", :desc => "Street" }
171+
end
172+
173+
end
174+
175+
class Clients < Grape::API
176+
version 'v1'
177+
178+
desc 'Clients index', {
179+
params: Entities::Client.documentation
180+
}
181+
get '/clients' do
182+
...
183+
end
184+
end
185+
add_swagger_documentation models: [Entities::Client, Entities::Address]
186+
end
187+
```
188+
189+
116190
## Swagger additions
117191
grape-swagger allows you to add an explanation in markdown in the notes field. Which would result in proper formatted markdown in Swagger UI. The default Swagger UI doesn't allow HTML in the notes field, so you need to use an adapted version of Swagger UI (you can find one at https://github.com/tim-vandecasteele/swagger-ui/tree/vasco).
118192

@@ -165,4 +239,3 @@ end
165239

166240
Copyright (c) 2012 Tim Vandecasteele. See LICENSE.txt for
167241
further details.
168-

0 commit comments

Comments
 (0)