gitlab-grape-swagger 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.github/dependabot.yml +20 -0
- data/.github/workflows/ci.yml +45 -0
- data/.gitignore +44 -0
- data/.gitlab-ci.yml +19 -0
- data/.rspec +3 -0
- data/.rubocop.yml +136 -0
- data/.rubocop_todo.yml +60 -0
- data/.ruby-gemset +1 -0
- data/CHANGELOG.md +671 -0
- data/CONTRIBUTING.md +126 -0
- data/Dangerfile +3 -0
- data/Gemfile +45 -0
- data/Gemfile.lock +249 -0
- data/LICENSE.txt +20 -0
- data/README.md +1772 -0
- data/RELEASING.md +82 -0
- data/Rakefile +20 -0
- data/UPGRADING.md +201 -0
- data/example/api/endpoints.rb +131 -0
- data/example/api/entities.rb +18 -0
- data/example/config.ru +42 -0
- data/example/example_requests.postman_collection +146 -0
- data/example/splines.png +0 -0
- data/example/swagger-example.png +0 -0
- data/grape-swagger.gemspec +23 -0
- data/lib/grape-swagger/doc_methods/build_model_definition.rb +68 -0
- data/lib/grape-swagger/doc_methods/data_type.rb +110 -0
- data/lib/grape-swagger/doc_methods/extensions.rb +101 -0
- data/lib/grape-swagger/doc_methods/file_params.rb +17 -0
- data/lib/grape-swagger/doc_methods/format_data.rb +53 -0
- data/lib/grape-swagger/doc_methods/headers.rb +20 -0
- data/lib/grape-swagger/doc_methods/move_params.rb +209 -0
- data/lib/grape-swagger/doc_methods/operation_id.rb +32 -0
- data/lib/grape-swagger/doc_methods/optional_object.rb +30 -0
- data/lib/grape-swagger/doc_methods/parse_params.rb +190 -0
- data/lib/grape-swagger/doc_methods/path_string.rb +52 -0
- data/lib/grape-swagger/doc_methods/produces_consumes.rb +15 -0
- data/lib/grape-swagger/doc_methods/status_codes.rb +21 -0
- data/lib/grape-swagger/doc_methods/tag_name_description.rb +34 -0
- data/lib/grape-swagger/doc_methods/version.rb +20 -0
- data/lib/grape-swagger/doc_methods.rb +142 -0
- data/lib/grape-swagger/endpoint/params_parser.rb +76 -0
- data/lib/grape-swagger/endpoint.rb +476 -0
- data/lib/grape-swagger/errors.rb +17 -0
- data/lib/grape-swagger/instance.rb +7 -0
- data/lib/grape-swagger/model_parsers.rb +42 -0
- data/lib/grape-swagger/rake/oapi_tasks.rb +135 -0
- data/lib/grape-swagger/version.rb +5 -0
- data/lib/grape-swagger.rb +174 -0
- data/spec/issues/267_nested_namespaces.rb +55 -0
- data/spec/issues/403_versions_spec.rb +124 -0
- data/spec/issues/427_entity_as_string_spec.rb +39 -0
- data/spec/issues/430_entity_definitions_spec.rb +94 -0
- data/spec/issues/532_allow_custom_format_spec.rb +42 -0
- data/spec/issues/533_specify_status_code_spec.rb +78 -0
- data/spec/issues/537_enum_values_spec.rb +50 -0
- data/spec/issues/539_array_post_body_spec.rb +65 -0
- data/spec/issues/542_array_of_type_in_post_body_spec.rb +46 -0
- data/spec/issues/553_align_array_put_post_params_spec.rb +152 -0
- data/spec/issues/572_array_post_body_spec.rb +51 -0
- data/spec/issues/579_align_put_post_parameters_spec.rb +185 -0
- data/spec/issues/582_file_response_spec.rb +55 -0
- data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
- data/spec/issues/605_root_route_documentation_spec.rb +23 -0
- data/spec/issues/650_params_array_spec.rb +65 -0
- data/spec/issues/677_consumes_produces_add_swagger_documentation_options_spec.rb +100 -0
- data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
- data/spec/issues/721_set_default_parameter_location_based_on_consumes_spec.rb +62 -0
- data/spec/issues/751_deeply_nested_objects_spec.rb +190 -0
- data/spec/issues/776_multiple_presents_spec.rb +59 -0
- data/spec/issues/784_extensions_on_params_spec.rb +42 -0
- data/spec/issues/809_utf8_routes_spec.rb +55 -0
- data/spec/issues/832_array_hash_float_decimal_spec.rb +114 -0
- data/spec/issues/847_route_param_options_spec.rb +37 -0
- data/spec/issues/873_wildcard_segments_path_parameters_spec.rb +28 -0
- data/spec/issues/878_optional_path_segments_spec.rb +29 -0
- data/spec/issues/881_handle_file_params_spec.rb +38 -0
- data/spec/issues/883_query_array_parameter_spec.rb +46 -0
- data/spec/issues/884_dont_document_non_schema_examples_spec.rb +49 -0
- data/spec/issues/887_prevent_duplicate_operation_ids_spec.rb +35 -0
- data/spec/lib/data_type_spec.rb +111 -0
- data/spec/lib/endpoint/params_parser_spec.rb +124 -0
- data/spec/lib/endpoint_spec.rb +153 -0
- data/spec/lib/extensions_spec.rb +185 -0
- data/spec/lib/format_data_spec.rb +115 -0
- data/spec/lib/model_parsers_spec.rb +104 -0
- data/spec/lib/move_params_spec.rb +444 -0
- data/spec/lib/oapi_tasks_spec.rb +163 -0
- data/spec/lib/operation_id_spec.rb +55 -0
- data/spec/lib/optional_object_spec.rb +47 -0
- data/spec/lib/parse_params_spec.rb +68 -0
- data/spec/lib/path_string_spec.rb +101 -0
- data/spec/lib/produces_consumes_spec.rb +116 -0
- data/spec/lib/tag_name_description_spec.rb +80 -0
- data/spec/lib/version_spec.rb +28 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/empty_model_parser.rb +23 -0
- data/spec/support/grape_version.rb +13 -0
- data/spec/support/mock_parser.rb +23 -0
- data/spec/support/model_parsers/entity_parser.rb +334 -0
- data/spec/support/model_parsers/mock_parser.rb +346 -0
- data/spec/support/model_parsers/representable_parser.rb +406 -0
- data/spec/support/namespace_tags.rb +93 -0
- data/spec/support/the_paths_definitions.rb +109 -0
- data/spec/swagger_v2/api_documentation_spec.rb +42 -0
- data/spec/swagger_v2/api_swagger_v2_additional_properties_spec.rb +83 -0
- data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +48 -0
- data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +36 -0
- data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +79 -0
- data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +145 -0
- data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +137 -0
- data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +56 -0
- data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +64 -0
- data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +58 -0
- data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +57 -0
- data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +109 -0
- data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +48 -0
- data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +153 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +355 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +217 -0
- data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +247 -0
- data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +80 -0
- data/spec/swagger_v2/api_swagger_v2_response_spec.rb +147 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +135 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +216 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_models_spec.rb +53 -0
- data/spec/swagger_v2/api_swagger_v2_response_with_root_spec.rb +153 -0
- data/spec/swagger_v2/api_swagger_v2_spec.rb +245 -0
- data/spec/swagger_v2/api_swagger_v2_status_codes_spec.rb +93 -0
- data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +90 -0
- data/spec/swagger_v2/boolean_params_spec.rb +38 -0
- data/spec/swagger_v2/default_api_spec.rb +175 -0
- data/spec/swagger_v2/deprecated_field_spec.rb +25 -0
- data/spec/swagger_v2/description_not_initialized_spec.rb +39 -0
- data/spec/swagger_v2/endpoint_versioned_path_spec.rb +130 -0
- data/spec/swagger_v2/errors_spec.rb +77 -0
- data/spec/swagger_v2/float_api_spec.rb +36 -0
- data/spec/swagger_v2/form_params_spec.rb +76 -0
- data/spec/swagger_v2/grape-swagger_spec.rb +17 -0
- data/spec/swagger_v2/guarded_endpoint_spec.rb +162 -0
- data/spec/swagger_v2/hide_api_spec.rb +147 -0
- data/spec/swagger_v2/host_spec.rb +43 -0
- data/spec/swagger_v2/inheritance_and_discriminator_spec.rb +57 -0
- data/spec/swagger_v2/mount_override_api_spec.rb +58 -0
- data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
- data/spec/swagger_v2/namespace_tags_prefix_spec.rb +122 -0
- data/spec/swagger_v2/namespace_tags_spec.rb +78 -0
- data/spec/swagger_v2/namespaced_api_spec.rb +121 -0
- data/spec/swagger_v2/nicknamed_api_spec.rb +25 -0
- data/spec/swagger_v2/operation_id_api_spec.rb +27 -0
- data/spec/swagger_v2/param_multi_type_spec.rb +82 -0
- data/spec/swagger_v2/param_type_spec.rb +95 -0
- data/spec/swagger_v2/param_values_spec.rb +180 -0
- data/spec/swagger_v2/params_array_collection_format_spec.rb +105 -0
- data/spec/swagger_v2/params_array_spec.rb +225 -0
- data/spec/swagger_v2/params_example_spec.rb +38 -0
- data/spec/swagger_v2/params_hash_spec.rb +77 -0
- data/spec/swagger_v2/params_nested_spec.rb +92 -0
- data/spec/swagger_v2/parent_less_namespace_spec.rb +32 -0
- data/spec/swagger_v2/reference_entity_spec.rb +129 -0
- data/spec/swagger_v2/security_requirement_spec.rb +46 -0
- data/spec/swagger_v2/simple_mounted_api_spec.rb +332 -0
- data/spec/version_spec.rb +10 -0
- metadata +225 -0
data/RELEASING.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Releasing Grape-Swagger
|
2
|
+
|
3
|
+
There are no particular rules about when to release grape-swagger. Any co-maintainer is encouraged to release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
4
|
+
|
5
|
+
### Release
|
6
|
+
|
7
|
+
Run tests, check that all tests succeed locally.
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle install
|
11
|
+
rake
|
12
|
+
```
|
13
|
+
|
14
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/ruby-grape/grape-swagger) for all supported platforms.
|
15
|
+
|
16
|
+
Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
|
17
|
+
|
18
|
+
```
|
19
|
+
### 0.7.2 (February 6, 2014)
|
20
|
+
```
|
21
|
+
|
22
|
+
Remove the lines with "Your contribution here.", since there will be no more contributions to this release.
|
23
|
+
|
24
|
+
Commit your changes.
|
25
|
+
|
26
|
+
```
|
27
|
+
git add CHANGELOG.md lib/grape-swagger/version.rb
|
28
|
+
git commit -m "Preparing for release, 0.7.2."
|
29
|
+
git push origin master
|
30
|
+
```
|
31
|
+
|
32
|
+
Release.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake release
|
36
|
+
|
37
|
+
grape-swagger 0.7.2 built to pkg/grape-swagger-0.7.2.gem.
|
38
|
+
Tagged v0.7.2.
|
39
|
+
Pushed git commits and tags.
|
40
|
+
Pushed grape-swagger 0.7.2 to rubygems.org.
|
41
|
+
```
|
42
|
+
|
43
|
+
### Prepare for the Next Version
|
44
|
+
|
45
|
+
Increment the minor version, the third number, modify [lib/grape-swagger/version.rb](lib/grape-swagger/version.rb). For example, change `0.7.1` to `0.7.2`. Major versions are incremented in pull requests that require it.
|
46
|
+
|
47
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
48
|
+
|
49
|
+
```
|
50
|
+
### 0.7.3 (Next)
|
51
|
+
|
52
|
+
#### Features
|
53
|
+
|
54
|
+
* Your contribution here.
|
55
|
+
|
56
|
+
#### Fixes
|
57
|
+
|
58
|
+
* Your contribution here.
|
59
|
+
```
|
60
|
+
|
61
|
+
Commit your changes.
|
62
|
+
|
63
|
+
```
|
64
|
+
git add CHANGELOG.md lib/grape-swagger/version.rb
|
65
|
+
git commit -m "Preparing for next developer iteration, 0.7.3."
|
66
|
+
git push origin master
|
67
|
+
```
|
68
|
+
|
69
|
+
### Make an Announcement
|
70
|
+
|
71
|
+
Make an announcement on the [ruby-grape@googlegroups.com](mailto:ruby-grape@googlegroups.com) mailing list. The general format is as follows.
|
72
|
+
|
73
|
+
```
|
74
|
+
Grape-Swagger 0.7.2 has been released.
|
75
|
+
|
76
|
+
There were 8 contributors to this release, not counting documentation.
|
77
|
+
|
78
|
+
Please note the breaking API change in ...
|
79
|
+
|
80
|
+
[copy/paste CHANGELOG here]
|
81
|
+
|
82
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
|
8
|
+
require 'rake'
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
require 'rubocop/rake_task'
|
18
|
+
RuboCop::RakeTask.new(:rubocop)
|
19
|
+
|
20
|
+
task default: %i[spec rubocop]
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
## Upgrading Grape-swagger
|
2
|
+
|
3
|
+
### Upgrading to >= 1.5.0
|
4
|
+
|
5
|
+
- The names generated for body parameter definitions and their references has changed. It'll now include the HTTP action as well as any path parameters.
|
6
|
+
- E.g, given a `PUT /things/:id` endpoint, `paths.things/{id}.put.parameters` in the generated Swaggerfile will contain the following:
|
7
|
+
- With `grape-swagger < 1.5.0`: `{ "name": "Things", ..., "schema": { "$ref": "#/definitions/putThings" } }`
|
8
|
+
- With `grape-swagger >= 1.5.0`: `{ "name": "putThingsId", ..., "schema": { "$ref": "#/definitions/putThingsId" } }`
|
9
|
+
- If you use the `nickname` option for an endpoint, that nickname will be used for both the parameter name and its definition reference.
|
10
|
+
- E.g., if the endpoint above were nicknamed `put-thing`, the generated Swaggerfile will contain `{ "name": "put-thing", ..., "schema": { "$ref": "#/definitions/put-thing" } }`
|
11
|
+
|
12
|
+
|
13
|
+
### Upgrading to >= 1.4.2
|
14
|
+
|
15
|
+
- `additionalProperties` has been deprecated and will be removed in a future version of `grape-swagger`. It has been replaced with `additional_properties`.
|
16
|
+
- The value of the `enum` attribute is now always an Array. If it has only one value, it will be a one-element Array.
|
17
|
+
|
18
|
+
### Upgrading to >= 1.4.0
|
19
|
+
|
20
|
+
- Official support for ruby < 2.5 removed, ruby 2.5 only in testing mode, but no support.
|
21
|
+
|
22
|
+
### Upgrading to >= 1.3.0
|
23
|
+
|
24
|
+
- The model (entity) description no longer comes from the route description. It will have a default value: `<<EntityName>> model`.
|
25
|
+
|
26
|
+
### Upgrading to >= 1.2.0
|
27
|
+
|
28
|
+
- The entity_name class method is now called on parent classes for inherited entities. Now you can do this
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
module Some::Long::Module
|
32
|
+
class Base < Grape::Entity
|
33
|
+
# ... other shared logic
|
34
|
+
def self.entity_name
|
35
|
+
"V2::#{self.to_s.demodulize}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def MyEntity < Base
|
40
|
+
# ....
|
41
|
+
end
|
42
|
+
|
43
|
+
def OtherEntity < Base
|
44
|
+
# revert back to the default behavior by hiding the method
|
45
|
+
private_class_method :entity_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
- Full class name is modified to use `_` separator (e.g. `A_B_C` instead of `A::B::C`).
|
51
|
+
|
52
|
+
### Upgrading to >= 1.1.0
|
53
|
+
|
54
|
+
Full class name is used for referencing entity by default (e.g. `A::B::C` instead of just `C`). `Entity` and `Entities` suffixes and prefixes are omitted (e.g. if entity name is `Entities::SomeScope::MyFavourite::Entity` only `SomeScope::MyFavourite` will be used).
|
55
|
+
|
56
|
+
### Upgrading to >= 0.26.1
|
57
|
+
|
58
|
+
The format can now be specified,
|
59
|
+
to achieve it for definition properties one have to use grape-swagger-entity >= 0.1.6.
|
60
|
+
|
61
|
+
Usage of option `markdown` won't no longer be supported,
|
62
|
+
cause OAPI accepts [GFM](https://help.github.com/articles/github-flavored-markdown) and plain text.
|
63
|
+
(see: [description of `Info`](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/2.0.md#info-object))
|
64
|
+
|
65
|
+
### Upgrading to >= 0.25.2
|
66
|
+
|
67
|
+
Avoids ambiguous documentation of array parameters,
|
68
|
+
by enforcing correct usage of both possibilities:
|
69
|
+
|
70
|
+
1. Array of primitive types
|
71
|
+
```ruby
|
72
|
+
params do
|
73
|
+
requires :foo, type: Array[String]
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
2. Array of objects
|
78
|
+
```ruby
|
79
|
+
params do
|
80
|
+
requires :put_params, type: Array do
|
81
|
+
requires :op, type: String
|
82
|
+
requires :path, type: String
|
83
|
+
requires :value, type: String
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### Upgrading to >= 0.25.0
|
89
|
+
|
90
|
+
The global tag set now only includes tags for documented routes. This behaviour has impact in particular for calling the documtation of a specific route.
|
91
|
+
|
92
|
+
### Upgrading to >= 0.21.0
|
93
|
+
|
94
|
+
With grape >= 0.21.0, `grape-entity` support moved to separate gem `grape-swagger-entity`, if you use grape entity, update your Gemfile:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
gem 'grape-swagger'
|
98
|
+
gem 'grape-swagger-entity'
|
99
|
+
```
|
100
|
+
|
101
|
+
`add_swagger_documentation` has changed from
|
102
|
+
``` ruby
|
103
|
+
add_swagger_documentation \
|
104
|
+
api_version: '0.0.1'
|
105
|
+
```
|
106
|
+
to
|
107
|
+
|
108
|
+
``` ruby
|
109
|
+
add_swagger_documentation \
|
110
|
+
doc_version: '0.0.1'
|
111
|
+
```
|
112
|
+
|
113
|
+
The API version self, would be set by grape, see -> [spec for #403](https://github.com/ruby-grape/grape-swagger/blob/master/spec/issues/403_versions_spec.rb).
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
### Upgrading to >= 0.10.2
|
118
|
+
|
119
|
+
With grape >= 0.12.0, support for `notes` is replaced by passing a block `detail` option specified. For future compatibility, update your code:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
desc 'Get all kittens!', notes: 'this will expose all the kittens'
|
123
|
+
```
|
124
|
+
|
125
|
+
to
|
126
|
+
|
127
|
+
``` ruby
|
128
|
+
desc 'Get all kittens!' do
|
129
|
+
detail 'this will expose all the kittens'
|
130
|
+
end
|
131
|
+
```
|
132
|
+
Be aware of https://github.com/ruby-grape/grape/issues/920, currently grape accepts either an option hash OR a block for `desc`.
|
133
|
+
|
134
|
+
### Upgrading to >= 0.9.0
|
135
|
+
|
136
|
+
#### Grape-Swagger-Rails
|
137
|
+
|
138
|
+
If you're using [grape-swagger-rails](https://github.com/ruby-grape/grape-swagger-rails), remove the `.json` extension from `GrapeSwaggerRails.options.url`.
|
139
|
+
|
140
|
+
For example, change
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
GrapeSwaggerRails.options.url = '/api/v1/swagger_doc.json'
|
144
|
+
```
|
145
|
+
|
146
|
+
to
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
GrapeSwaggerRails.options.url = '/api/v1/swagger_doc'
|
150
|
+
```
|
151
|
+
|
152
|
+
See [#187](https://github.com/ruby-grape/grape-swagger/issues/187) for more information.
|
153
|
+
|
154
|
+
#### Grape 0.10.0
|
155
|
+
|
156
|
+
If your API uses Grape 0.10.0 or newer with a single `format :json` directive, add `hide_format: true` to `add_swagger_documentation`. Otherwise nested routes will render with `.json` links to your API documentation, which will fail with a 404 Not Found.
|
157
|
+
|
158
|
+
### Upgrading to >= 0.8.0
|
159
|
+
|
160
|
+
#### Changes in Configuration
|
161
|
+
|
162
|
+
The following options have been added, removed or have been changed in the grape-swagger interface:
|
163
|
+
|
164
|
+
* `markdown: true/false` => `markdown: GrapeSwagger::Markdown::KramdownAdapter`
|
165
|
+
|
166
|
+
#### Markdown
|
167
|
+
|
168
|
+
You can now configure a markdown adapter. This was originally changed because of performance issues with Kramdown and the `markdown` option no longer takes a boolean argument. Built-in adapters include Kramdown and Redcarpet.
|
169
|
+
|
170
|
+
##### Kramdown
|
171
|
+
|
172
|
+
To configure the markdown with Kramdown, add the kramdown gem to your Gemfile:
|
173
|
+
|
174
|
+
`gem 'kramdown'`
|
175
|
+
|
176
|
+
Configure grape-swagger as follows:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
add_swagger_documentation (
|
180
|
+
markdown: GrapeSwagger::Markdown::KramdownAdapter
|
181
|
+
)
|
182
|
+
```
|
183
|
+
|
184
|
+
#### Redcarpet
|
185
|
+
|
186
|
+
To configure markdown with Redcarpet, add the redcarpet and the rouge gem to your Gemfile. Note that Redcarpet does not work with JRuby.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
gem 'redcarpet'
|
190
|
+
gem 'rouge'
|
191
|
+
```
|
192
|
+
|
193
|
+
Configure grape-swagger as follows:
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
add_swagger_documentation (
|
197
|
+
markdown: GrapeSwagger::Markdown::RedcarpetAdapter
|
198
|
+
)
|
199
|
+
```
|
200
|
+
|
201
|
+
See [#142](https://github.com/ruby-grape/grape-swagger/pull/142) and documentation section [Markdown in Notes](https://github.com/ruby-grape/grape-swagger#markdown-in-notes) for more information.
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'grape-entity'
|
2
|
+
require './api/entities'
|
3
|
+
|
4
|
+
module Api
|
5
|
+
class Spline
|
6
|
+
attr_accessor :id, :x, :y, :reticulated
|
7
|
+
end
|
8
|
+
|
9
|
+
module Endpoints
|
10
|
+
class Root < Grape::API
|
11
|
+
desc 'API Root'
|
12
|
+
get do
|
13
|
+
{
|
14
|
+
splines_url: '/splines',
|
15
|
+
file_url: '/file'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Splines < Grape::API
|
21
|
+
@@splines = []
|
22
|
+
|
23
|
+
namespace :splines do
|
24
|
+
#
|
25
|
+
desc 'Get all splines',
|
26
|
+
is_array: true,
|
27
|
+
http_codes: [
|
28
|
+
{ code: 200, message: 'get Splines', model: Api::Entities::Splines },
|
29
|
+
{ code: 422, message: 'SplinesOutError' }
|
30
|
+
]
|
31
|
+
get do
|
32
|
+
present :items, @@splines, with: Entities::Splines
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
desc 'Return a spline.',
|
37
|
+
http_codes: [
|
38
|
+
{ code: 200, message: 'get Splines' },
|
39
|
+
{ code: 422, message: 'SplinesOutError' }
|
40
|
+
]
|
41
|
+
params do
|
42
|
+
requires :id, type: Integer, desc: 'Spline id.'
|
43
|
+
end
|
44
|
+
get ':id' do
|
45
|
+
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]
|
46
|
+
|
47
|
+
present @@splines[params[:id] - 1], with: Entities::Splines
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
desc 'Create a spline.',
|
52
|
+
http_codes: [
|
53
|
+
{ code: 201, message: 'Spline created', model: Api::Entities::Splines }
|
54
|
+
]
|
55
|
+
params do
|
56
|
+
requires :spline, type: Hash do
|
57
|
+
requires :x, type: Numeric
|
58
|
+
requires :y, type: Numeric
|
59
|
+
end
|
60
|
+
optional :reticulated, type: Boolean, default: true, desc: 'True if the spline is reticulated.'
|
61
|
+
end
|
62
|
+
post do
|
63
|
+
spline = Spline.new
|
64
|
+
spline.id = @@splines.size + 1
|
65
|
+
spline.x = (params[:spline][:x] / params[:spline][:y] || 0.0)
|
66
|
+
spline.y = (params[:spline][:y] / params[:spline][:x] || 0.0)
|
67
|
+
spline.reticulated = params[:reticulated]
|
68
|
+
|
69
|
+
@@splines << spline
|
70
|
+
|
71
|
+
present spline, with: Entities::Splines
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
desc 'Update a spline.',
|
76
|
+
http_codes: [
|
77
|
+
{ code: 200, message: 'update Splines', model: Api::Entities::Splines },
|
78
|
+
{ code: 422, message: 'SplinesOutError' }
|
79
|
+
]
|
80
|
+
params do
|
81
|
+
requires :id, type: Integer, desc: 'Spline id.'
|
82
|
+
optional :spline, type: Hash do
|
83
|
+
optional :x, type: Numeric
|
84
|
+
optional :y, type: Numeric
|
85
|
+
end
|
86
|
+
optional :reticulated, type: Boolean, default: true, desc: 'True if the spline is reticulated.'
|
87
|
+
end
|
88
|
+
put ':id' do
|
89
|
+
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]
|
90
|
+
|
91
|
+
update_data = params[:spline]
|
92
|
+
spline = @@splines[params[:id] - 1]
|
93
|
+
|
94
|
+
spline.reticulated = !!update_data[:reticulated]
|
95
|
+
spline.x = update_data[:x] / update_data[:y] || 0.0
|
96
|
+
spline.y = update_data[:y] / update_data[:x] || 0.0
|
97
|
+
|
98
|
+
present spline, with: Entities::Splines
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
desc 'Delete a spline.'
|
103
|
+
params do
|
104
|
+
requires :id, type: Integer, desc: 'Spline id.'
|
105
|
+
end
|
106
|
+
delete ':id' do
|
107
|
+
error!(code: 422, message: 'SplinesOutError') unless @@splines[params[:id] - 1]
|
108
|
+
|
109
|
+
@@splines.delete_at(params[:id] - 1)
|
110
|
+
{ 'deleted' => params[:id] }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class FileAccessor < Grape::API
|
116
|
+
namespace :file do
|
117
|
+
desc 'Update image',
|
118
|
+
details: "# TEST api for testing uploading\n
|
119
|
+
# curl --form file=@splines.png http://localhost:9292/file/upload",
|
120
|
+
content_type: 'application/octet-stream'
|
121
|
+
post 'upload' do
|
122
|
+
filename = params[:file][:filename]
|
123
|
+
content_type 'binary', 'application/octet-stream'
|
124
|
+
# env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
|
125
|
+
header 'Content-Disposition', "attachment; filename*=UTF-8''#{URI.escape(filename)}"
|
126
|
+
params[:file][:tempfile].read
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'grape-entity'
|
2
|
+
|
3
|
+
module Api
|
4
|
+
module Entities
|
5
|
+
class Splines < Grape::Entity
|
6
|
+
expose :id, documentation: { type: Integer, desc: 'identity of a resource' }
|
7
|
+
expose :x, documentation: { type: Float, desc: 'x-value' }
|
8
|
+
expose :y, documentation: { type: Float, desc: 'y-value' }
|
9
|
+
expose :path, documentation: { type: String, desc: 'the requested resource' }
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def path
|
14
|
+
"/#{object.class.name.demodulize.to_s.underscore}/#{object.id}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/example/config.ru
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Bundler.require ENV['RACK_ENV']
|
2
|
+
|
3
|
+
use Rack::Cors do
|
4
|
+
allow do
|
5
|
+
origins '*'
|
6
|
+
resource '*', headers: :any, methods: [:get, :post, :put, :delete, :options]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'grape'
|
11
|
+
|
12
|
+
require './api/endpoints'
|
13
|
+
require './api/entities'
|
14
|
+
|
15
|
+
class Base < Grape::API
|
16
|
+
require '../lib/grape-swagger'
|
17
|
+
format :json
|
18
|
+
|
19
|
+
mount Api::Endpoints::Root
|
20
|
+
mount Api::Endpoints::Splines
|
21
|
+
mount Api::Endpoints::FileAccessor
|
22
|
+
|
23
|
+
before do
|
24
|
+
header['Access-Control-Allow-Origin'] = '*'
|
25
|
+
header['Access-Control-Request-Method'] = '*'
|
26
|
+
end
|
27
|
+
|
28
|
+
# global exception handler, used for error notifications
|
29
|
+
rescue_from :all do |e|
|
30
|
+
raise e
|
31
|
+
error_response(message: "Internal server error: #{e}", status: 500)
|
32
|
+
end
|
33
|
+
|
34
|
+
add_swagger_documentation hide_documentation_path: true,
|
35
|
+
api_version: 'v1',
|
36
|
+
info: {
|
37
|
+
title: 'Horses and Hussars',
|
38
|
+
description: 'Demo app for dev of grape swagger 2.0'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
run Base.new
|
@@ -0,0 +1,146 @@
|
|
1
|
+
{
|
2
|
+
"id": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
3
|
+
"name": "grape-rackup",
|
4
|
+
"description": "",
|
5
|
+
"order": [
|
6
|
+
"cf633582-c2ea-cb44-24d7-d64e73a65049",
|
7
|
+
"60bd637b-7b77-b280-d4f7-3d3d38cd86ef",
|
8
|
+
"4780e2ef-f05d-f464-9d18-538c5960be3c",
|
9
|
+
"f83c2241-c239-13ea-bffb-255436e95863",
|
10
|
+
"0648649b-9e54-1bc5-f835-2c690f67d47a"
|
11
|
+
],
|
12
|
+
"folders": [],
|
13
|
+
"timestamp": 1453407636651,
|
14
|
+
"owner": "",
|
15
|
+
"remoteLink": "",
|
16
|
+
"public": false,
|
17
|
+
"requests": [
|
18
|
+
{
|
19
|
+
"id": "0648649b-9e54-1bc5-f835-2c690f67d47a",
|
20
|
+
"headers": "Content-Type: application/json\n",
|
21
|
+
"url": "http://localhost:9292/splines/1",
|
22
|
+
"preRequestScript": "",
|
23
|
+
"pathVariables": {},
|
24
|
+
"method": "DELETE",
|
25
|
+
"data": [],
|
26
|
+
"dataMode": "params",
|
27
|
+
"version": 2,
|
28
|
+
"tests": "",
|
29
|
+
"currentHelper": "normal",
|
30
|
+
"helperAttributes": {},
|
31
|
+
"time": 1453408596777,
|
32
|
+
"name": "http://localhost:9292/splines",
|
33
|
+
"description": "",
|
34
|
+
"collectionId": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
35
|
+
"responses": []
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"id": "4780e2ef-f05d-f464-9d18-538c5960be3c",
|
39
|
+
"headers": "Content-Type: application/json\n",
|
40
|
+
"url": "http://localhost:9292/splines/1",
|
41
|
+
"pathVariables": {},
|
42
|
+
"preRequestScript": "",
|
43
|
+
"method": "GET",
|
44
|
+
"collectionId": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
45
|
+
"data": [
|
46
|
+
{
|
47
|
+
"key": "required_group[required_param_1]",
|
48
|
+
"value": "sadf",
|
49
|
+
"type": "text",
|
50
|
+
"enabled": true
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"key": "required_group[required_param_2]",
|
54
|
+
"value": "fgsd",
|
55
|
+
"type": "text",
|
56
|
+
"enabled": true
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"dataMode": "params",
|
60
|
+
"name": "http://localhost:9292/splines",
|
61
|
+
"description": "",
|
62
|
+
"descriptionFormat": "html",
|
63
|
+
"time": 1453408415061,
|
64
|
+
"version": 2,
|
65
|
+
"responses": [],
|
66
|
+
"tests": "",
|
67
|
+
"currentHelper": "normal",
|
68
|
+
"helperAttributes": {}
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"id": "60bd637b-7b77-b280-d4f7-3d3d38cd86ef",
|
72
|
+
"headers": "Content-Type: application/json\n",
|
73
|
+
"url": "http://localhost:9292/splines",
|
74
|
+
"pathVariables": {},
|
75
|
+
"preRequestScript": "",
|
76
|
+
"method": "GET",
|
77
|
+
"collectionId": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
78
|
+
"data": [
|
79
|
+
{
|
80
|
+
"key": "required_group[required_param_1]",
|
81
|
+
"value": "sadf",
|
82
|
+
"type": "text",
|
83
|
+
"enabled": true
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"key": "required_group[required_param_2]",
|
87
|
+
"value": "fgsd",
|
88
|
+
"type": "text",
|
89
|
+
"enabled": true
|
90
|
+
}
|
91
|
+
],
|
92
|
+
"dataMode": "params",
|
93
|
+
"name": "http://localhost:9292/splines",
|
94
|
+
"description": "",
|
95
|
+
"descriptionFormat": "html",
|
96
|
+
"time": 1453408387712,
|
97
|
+
"version": 2,
|
98
|
+
"responses": [],
|
99
|
+
"tests": "",
|
100
|
+
"currentHelper": "normal",
|
101
|
+
"helperAttributes": {}
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"id": "cf633582-c2ea-cb44-24d7-d64e73a65049",
|
105
|
+
"headers": "Content-Type: application/json\n",
|
106
|
+
"url": "http://localhost:9292/splines",
|
107
|
+
"pathVariables": {},
|
108
|
+
"preRequestScript": "",
|
109
|
+
"method": "POST",
|
110
|
+
"collectionId": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
111
|
+
"data": [],
|
112
|
+
"dataMode": "raw",
|
113
|
+
"name": "http://localhost:9292/splines",
|
114
|
+
"description": "",
|
115
|
+
"descriptionFormat": "html",
|
116
|
+
"time": 1453407769825,
|
117
|
+
"version": 2,
|
118
|
+
"responses": [],
|
119
|
+
"tests": "",
|
120
|
+
"currentHelper": "normal",
|
121
|
+
"helperAttributes": {},
|
122
|
+
"rawModeData": "{\n \"spline\":{\n \"x\":1.23,\n \"y\":3.14\n }\n}"
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"id": "f83c2241-c239-13ea-bffb-255436e95863",
|
126
|
+
"headers": "Content-Type: application/json\n",
|
127
|
+
"url": "http://localhost:9292/splines/1",
|
128
|
+
"pathVariables": {},
|
129
|
+
"preRequestScript": "",
|
130
|
+
"method": "PUT",
|
131
|
+
"collectionId": "1a2c4a65-9c99-3435-17db-307763b28fd1",
|
132
|
+
"data": [],
|
133
|
+
"dataMode": "raw",
|
134
|
+
"name": "http://localhost:9292/splines",
|
135
|
+
"description": "",
|
136
|
+
"descriptionFormat": "html",
|
137
|
+
"time": 1453408494448,
|
138
|
+
"version": 2,
|
139
|
+
"responses": [],
|
140
|
+
"tests": "",
|
141
|
+
"currentHelper": "normal",
|
142
|
+
"helperAttributes": {},
|
143
|
+
"rawModeData": "{\n \"spline\":{\n \"x\":131.23,\n \"y\":93.14\n }\n}"
|
144
|
+
}
|
145
|
+
]
|
146
|
+
}
|
data/example/splines.png
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require 'grape-swagger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'gitlab-grape-swagger'
|
8
|
+
s.version = GrapeSwagger::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['LeFnord', 'Tim Vandecasteele']
|
11
|
+
s.email = ['pscholz.le@gmail.com', 'tim.vandecasteele@gmail.com']
|
12
|
+
s.homepage = 'https://gitlab.com/gitlab-org/ruby/gems/grape-swagger'
|
13
|
+
s.summary = 'Add auto generated documentation to your Grape API that can be displayed with Swagger.'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
17
|
+
|
18
|
+
s.required_ruby_version = '>= 2.7'
|
19
|
+
s.add_runtime_dependency 'grape', '~> 1.3'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.require_paths = ['lib']
|
23
|
+
end
|