grape-swagger 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9967e826af18b69a0b87166977ee09b1c3845ac614148b4664b9703156fc7226
4
- data.tar.gz: df1b2b105532ff3a93af03919a75d476323f574e9493ee96760b3664b44df741
3
+ metadata.gz: c36235d1ec48b00075496c2d59151a87e42f2b7f34c876db913504a7706c1a70
4
+ data.tar.gz: 0d7aac2f325422f53218257e4cb8e2bef51e73e424a53d88b244c3073c614656
5
5
  SHA512:
6
- metadata.gz: b387fb75c6148eece8ed8c9c057b5ec047c341b8ef5404f4aa3992c144eb7b11e320d76b0bee81bca7ceea56942b6b4b101089e003fcc967c95c64e45d1a30d0
7
- data.tar.gz: dc275ae7d3c463a82b87d7674a0e3e28aa9154d751b9aae9d6a22f255df6b5ecd49688a69700bfa1306502418f832cdf9931e7384e4eb8771ed29650830e6069
6
+ metadata.gz: 13d4c18cf80ce43aedde8a3347be17ebda40fd6e2b56496459226f350e273b31cd6c74d79d75b68e2461d47dd6f0aeaec3080709aebbcf5b6beb9b8162f949bb
7
+ data.tar.gz: 949ebd6da1fcdb3c398e6070a035f50a9e211ed27a93694b275f5e09a9d1266c675f04f7b1e9583329689fcc9a38fd50cdac8dd6c1de87c486016e63faacce57
data/CHANGELOG.md CHANGED
@@ -8,6 +8,23 @@
8
8
 
9
9
  * Your contribution here.
10
10
 
11
+
12
+ ### 2.0.3 (April 26, 2024)
13
+
14
+ #### Fixes
15
+
16
+ * [#922](https://github.com/ruby-grape/grape-swagger/pull/922): Force request body to be an schema object - [@numbata](https://github.com/numbata)
17
+ * [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)
18
+ * [#924](https://github.com/ruby-grape/grape-swagger/pull/924): fix: Use mount_path to narrow down urls_for - [@chibicco](https://github.com/chibicco)
19
+
20
+
21
+ ### 2.0.2 (Februar 2, 2024)
22
+
23
+ #### Fixes
24
+
25
+ * [#918](https://github.com/ruby-grape/grape-swagger/pull/918): Fix params extension does not work when param_type is body - [@numbata](https://github.com/numbata)
26
+
27
+
11
28
  ### 2.0.1 (Januar 2, 2024)
12
29
 
13
30
  #### Features
@@ -18,6 +35,7 @@
18
35
 
19
36
  * [#916](https://github.com/ruby-grape/grape-swagger/pull/916): Restore Ruby 3.0 support - [@godfat](https://github.com/godfat)
20
37
 
38
+
21
39
  ### 2.0.0 (November 7, 2023)
22
40
 
23
41
  #### Features
@@ -63,7 +81,6 @@
63
81
  * [#846](https://github.com/ruby-grape/grape-swagger/pull/846): Refactor oapi fetch task [@Vachman](https://github.com/Vachman)
64
82
  * [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of enum to be Array [@takahashim](https://github.com/takahashim)
65
83
 
66
-
67
84
  ### 1.4.3 (January 5, 2022)
68
85
 
69
86
  #### Fixes
data/UPGRADING.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Upgrading Grape-swagger
2
2
 
3
+ ### Upgrading to >= x.y.z
4
+
5
+ - Grape-swagger now documents array parameters within an object schema in Swagger. This aligns with grape's JSON structure requirements and ensures the documentation is correct.
6
+ - Previously, arrays were documented as standalone arrays, which could be incorrect based on grape's expectations.
7
+ - Check your API documentation and update your code or tests that use the old array format.
8
+
9
+ Attention: This update may require you to make changes to ensure your API integrations continue to work correctly.
10
+ For detailed reasons behind this update, refer to GitHub issue #666.
11
+
3
12
  ### Upgrading to >= 1.5.0
4
13
 
5
14
  - 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.
@@ -18,8 +18,6 @@ module GrapeSwagger
18
18
 
19
19
  params_to_move = movable_params(params)
20
20
 
21
- return (params + correct_array_param(params_to_move)) if should_correct_array?(params_to_move)
22
-
23
21
  params << parent_definition_of_params(params_to_move, path, route)
24
22
 
25
23
  params
@@ -27,21 +25,11 @@ module GrapeSwagger
27
25
 
28
26
  private
29
27
 
30
- def should_correct_array?(param)
31
- param.length == 1 && param.first[:in] == 'body' && param.first[:type] == 'array'
32
- end
33
-
34
- def correct_array_param(param)
35
- param.first[:schema] = { type: param.first.delete(:type), items: param.first.delete(:items) }
36
-
37
- param
38
- end
39
-
40
28
  def parent_definition_of_params(params, path, route)
41
29
  definition_name = OperationId.build(route, path)
42
- build_definition(definition_name, params)
30
+ # NOTE: Parent definition is always object
31
+ @definitions[definition_name] = object_type
43
32
  definition = @definitions[definition_name]
44
-
45
33
  move_params_to_new(definition, params)
46
34
 
47
35
  definition[:description] = route.description if route.try(:description)
@@ -53,6 +41,7 @@ module GrapeSwagger
53
41
  params, nested_params = params.partition { |x| !x[:name].to_s.include?('[') }
54
42
  params.each do |param|
55
43
  property = param[:name]
44
+
56
45
  param_properties, param_required = build_properties([param])
57
46
  add_properties_to_definition(definition, param_properties, param_required)
58
47
  related_nested_params, nested_params = nested_params.partition { |x| x[:name].start_with?("#{property}[") }
@@ -86,6 +75,7 @@ module GrapeSwagger
86
75
  else
87
76
  document_as_property(param)
88
77
  end
78
+ add_extension_properties(properties[name], param)
89
79
 
90
80
  required << name if deletable?(param) && param[:required]
91
81
  end
@@ -102,6 +92,12 @@ module GrapeSwagger
102
92
  end
103
93
  end
104
94
 
95
+ def add_extension_properties(definition, values)
96
+ values.each do |key, value|
97
+ definition[key] = value if key.start_with?('x-')
98
+ end
99
+ end
100
+
105
101
  def document_as_property(param)
106
102
  property_keys.each_with_object({}) do |x, memo|
107
103
  next unless param.key?(x)
@@ -190,7 +186,7 @@ module GrapeSwagger
190
186
  end
191
187
 
192
188
  def move_methods
193
- [:post, :put, :patch, 'POST', 'PUT', 'PATCH']
189
+ [:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
194
190
  end
195
191
 
196
192
  def includes_body_param?(params)
@@ -70,7 +70,7 @@ module GrapeSwagger
70
70
 
71
71
  def document_array_param(value_type, definitions)
72
72
  if value_type[:documentation].present?
73
- param_type = value_type[:documentation][:param_type]
73
+ param_type = value_type[:documentation][:param_type] || value_type[:documentation][:in]
74
74
  doc_type = value_type[:documentation][:type]
75
75
  type = DataType.mapping(doc_type) if doc_type && !DataType.request_primitive?(doc_type)
76
76
  collection_format = value_type[:documentation][:collectionFormat]
@@ -108,6 +108,10 @@ module GrapeSwagger
108
108
  set_additional_properties, additional_properties = parse_additional_properties(definitions, value_type)
109
109
  array_items[:additionalProperties] = additional_properties if set_additional_properties
110
110
 
111
+ if value_type.key?(:items)
112
+ GrapeSwagger::DocMethods::Extensions.add_extensions_to_root(value_type[:items], array_items)
113
+ end
114
+
111
115
  array_items
112
116
  end
113
117
 
@@ -63,7 +63,7 @@ module GrapeSwagger
63
63
  resource - if given only for that it would be generated (optional)'
64
64
  task validate: :environment do
65
65
  # :nocov:
66
- ENV['store'] = 'true'
66
+ ENV.store('store', 'true')
67
67
  ::Rake::Task['oapi:fetch'].invoke
68
68
  exit if error?
69
69
 
@@ -95,7 +95,7 @@ module GrapeSwagger
95
95
  def urls_for(api_class)
96
96
  api_class.routes
97
97
  .map(&:path)
98
- .select { |e| e.include?('doc') }
98
+ .grep(/#{GrapeSwagger::DocMethods.class_variable_get(:@@mount_path)}/)
99
99
  .reject { |e| e.include?(':name') }
100
100
  .map { |e| format_path(e) }
101
101
  .map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }
@@ -108,7 +108,7 @@ module GrapeSwagger
108
108
  end
109
109
 
110
110
  def save_to_file?
111
- ENV['store'].present? && !error?
111
+ ENV.fetch('store', nil).present? && !error?
112
112
  end
113
113
 
114
114
  def error?
@@ -118,10 +118,10 @@ module GrapeSwagger
118
118
  def file(url)
119
119
  api_version = url.split('/').last
120
120
 
121
- name = if ENV['store'] == 'true' || ENV['store'].blank?
121
+ name = if ENV.fetch('store', nil) == 'true' || ENV.fetch('store', nil).blank?
122
122
  "swagger_doc_#{api_version}.json"
123
123
  else
124
- ENV['store'].sub('.json', "_#{api_version}.json")
124
+ ENV.fetch('store').sub('.json', "_#{api_version}.json")
125
125
  end
126
126
 
127
127
  File.join(Dir.getwd, name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.3'
5
5
  end
data/lib/grape-swagger.rb CHANGED
@@ -40,7 +40,7 @@ module SwaggerRouting
40
40
  @target_class.combined_routes[resource] ||= []
41
41
  next if doc_klass.hide_documentation_path && route.path.match(/#{doc_klass.mount_path}($|\/|\(\.)/)
42
42
 
43
- @target_class.combined_routes[resource].unshift route
43
+ @target_class.combined_routes[resource] << route
44
44
  end
45
45
  end
46
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeFnord
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-01-02 00:00:00.000000000 Z
12
+ date: 2024-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.5.3
106
+ rubygems_version: 3.5.9
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Add auto generated documentation to your Grape API that can be displayed