Skip to content

Change output to be compatible with swagger-ui #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6691ba2
Adds support for models and body param type
chebyte Apr 24, 2014
a724d70
Fixes specs
chebyte Apr 24, 2014
32ea455
Lots of changes to make API doc compatible with swagger-ui
May 8, 2014
87c8c7b
Properly describe arrays in parse_entity_models()
May 8, 2014
b69cdaa
Correctly handle arrays of items and complex types in params
May 12, 2014
0642b43
Fix (some of the) specs
May 12, 2014
376a327
Merge branch 'refs/heads/pr/104' into swagger-ui
May 12, 2014
55fc220
Clean up after merge of PR #104
May 12, 2014
af690af
Check for complex types in parse_params
May 12, 2014
78a294a
Add all options for add_swagger_documentation to README.md
May 26, 2014
a25e9ef
Add comment to add authorizations to operations
May 26, 2014
26e13fa
Clean up output in lib/grape-swagger.rb
May 27, 2014
f88ada9
Fix file upload elements
May 28, 2014
239a348
Remove unneeded (and disallowed according to spec) elements from the …
May 28, 2014
60e3012
Fix API paths and add a default description
May 28, 2014
4302ea1
Clean up commented-out code
May 28, 2014
50541bd
Clean up authorizations
May 28, 2014
b3a11fa
Fix specs
May 28, 2014
9a9d85f
Change the way required properties in models are indicated in the JSON
May 28, 2014
d205202
Fix non-reentrantness in #parse_entity_models
May 28, 2014
2f35d85
Add #is_primitive? and #generate_typeref
May 28, 2014
eb3991c
Replace .rvmrc with new-style RVM config files
May 30, 2014
865acf9
Allow returning arrays
May 30, 2014
14e4afa
Convert data types to defined Swagger types
May 30, 2014
50e968c
Fix specs
May 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grape-swagger
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.0.0-p353
48 changes: 0 additions & 48 deletions .rvmrc

This file was deleted.

81 changes: 77 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ end

## Configure
You can pass a hash with some configuration possibilities to ```add_swagger_documentation```, all of these are optional:
* ```:mount_path``` The path were the API documentation is loaded, default '/swagger_doc'

* ```:target_class``` The API class to document, default `self`
* ```:mount_path``` The path where the API documentation is loaded, default '/swagger_doc'
* ```:class_name```
* ```:markdown``` Allow markdown in `notes`, default `false`
* ```:hide_format``` , Don't add '.(format)' to the end of URLs, default `false`
* ```:api_version``` Version of the API that's being exposed
* ```: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.
* ```:markdown``` Allow markdown in `notes`, default `false`
* ```:authorizations``` Added to the `authorizations` key in the JSON documentation
* ```:include_base_url``` Add base path to the URLs, default `true`
* ```:root_base_path``` Add `basePath` key to the JSON documentation, default `true`
* ```:info``` Added to the `info` key in the JSON documentation
* ```:models``` Allows adds an array with the entities for build models specifications. You need to use grape-entity gem.
* ```:hide_documentation_path``` Don't show the '/swagger_doc' path in the generated swagger documentation

* ```:format```

## Swagger Header Parameters

Expand Down Expand Up @@ -113,6 +122,71 @@ module API
end
```

### Relationships

1xN

```ruby
module API
module Entities
class Client < Grape::Entity
expose :name, :documentation => { :type => "string", :desc => "Name" }
expose :addresses, using: Entities::Address, documentation: {type: 'Address', desc: 'Addresses.', param_type: 'body', is_array: true}
end

class Address < Grape::Entity
expose :street, :documentation => { :type => "string", :desc => "Street." }
end

end

class Clients < Grape::API
version 'v1'

desc 'Clients index', {
params: Entities::Client.documentation
}
get '/clients' do
...
end
end
add_swagger_documentation models: [Entities::Client, Entities::Address]
end
```

1x1

Note: is_array is false by default

```ruby
module API
module Entities
class Client < Grape::Entity
expose :name, :documentation => { :type => "string", :desc => "Name" }
expose :address, using: Entities::Address, documentation: {type: 'Address', desc: 'Addresses.', param_type: 'body', is_array: false}
end

class Address < Grape::Entity
expose :street, :documentation => { :type => "string", :desc => "Street" }
end

end

class Clients < Grape::API
version 'v1'

desc 'Clients index', {
params: Entities::Client.documentation
}
get '/clients' do
...
end
end
add_swagger_documentation models: [Entities::Client, Entities::Address]
end
```


## Swagger additions
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).

Expand Down Expand Up @@ -165,4 +239,3 @@ end

Copyright (c) 2012 Tim Vandecasteele. See LICENSE.txt for
further details.

Loading