|
45 | 45 |
|
46 | 46 | ## Configure
|
47 | 47 | 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` |
49 | 54 | * ```:api_version``` Version of the API that's being exposed
|
50 | 55 | * ```: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. |
52 | 61 | * ```:hide_documentation_path``` Don't show the '/swagger_doc' path in the generated swagger documentation
|
53 |
| - |
| 62 | +* ```:format``` |
54 | 63 |
|
55 | 64 | ## Swagger Header Parameters
|
56 | 65 |
|
@@ -113,6 +122,71 @@ module API
|
113 | 122 | end
|
114 | 123 | ```
|
115 | 124 |
|
| 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 | + |
116 | 190 | ## Swagger additions
|
117 | 191 | 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).
|
118 | 192 |
|
|
165 | 239 |
|
166 | 240 | Copyright (c) 2012 Tim Vandecasteele. See LICENSE.txt for
|
167 | 241 | further details.
|
168 |
| - |
|
0 commit comments