grape_openapi3 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0f1cd37cbd82e6e03da9a91253742ef3ce87db8796312f1e54e3da6d6681cd7
4
- data.tar.gz: 1875b127d847677e442a39031137c1aff3302f1ca3c1f5308346f90c07f8790c
3
+ metadata.gz: 3808df464b57163b3cf5adffec3a2b2bda782648d1ee9ad1731b5fbdf0a64fc5
4
+ data.tar.gz: a7687ffba660a3093fa22f318b0c586957532fe376c82fafc213e0cd1f947a11
5
5
  SHA512:
6
- metadata.gz: 520dce2913d16f0b748c2cb6be734adf73dae6c0981f7639a9d3a2be4ae38355d18f4ffaaae040777a4f0cb37334dfe4d4c03476b7829e8d4744d2d61c9a267b
7
- data.tar.gz: 8a043d71e49e6e40fb58e8da45378932e8a5c73bbf165c136ca03221464ceaca4e89d777538d1f5c407cc89a7f62b50096ed2c063d624db47273e2fef48ea73d
6
+ metadata.gz: b123656dde3a8542bad0647080a74c80d6e1a3a80efa73cfb850298ced9436776e016abcb6a94a7e67901f5b70620840171d9d54b73ae87227acbe45949d5a73
7
+ data.tar.gz: 4b31be25b8a836a6fbd740f66b8e74826bf6f9511e79783d5bc15cc6bbd818a8e83ae853bc88ee6bc574f208972ca6b0d120a91860ba2f9b375bc632bcadf737
@@ -81,8 +81,13 @@ module GrapeOpenapi3
81
81
  entity = @route[:success_entity]
82
82
  return { "description" => "Success" } unless entity
83
83
 
84
- # Unpack hash form: { code: 201, message: "Created", model: ProductEntity }
85
- description, entity_class = unpack_success(entity)
84
+ # Unpack hash form: { code: 201, message: "Created", model: ProductEntity, schema: {...} }
85
+ description, entity_class, inline_schema = unpack_success(entity)
86
+
87
+ if inline_schema
88
+ media = @route[:produces].first || "application/json"
89
+ return { "description" => description, "content" => { media => { "schema" => inline_schema } } }
90
+ end
86
91
 
87
92
  unless entity_class
88
93
  return { "description" => description }
@@ -98,19 +103,20 @@ module GrapeOpenapi3
98
103
  { "description" => description, "content" => { media => { "schema" => schema } } }
99
104
  end
100
105
 
101
- # Returns [description_string, entity_class_or_nil].
102
- # Accepts both the bare-class form and the hash form.
106
+ # Returns [description_string, entity_class_or_nil, inline_schema_or_nil].
107
+ # Accepts the bare-class form, the hash form with :model, and the hash form with :schema.
103
108
  def unpack_success(entity)
104
109
  if entity.is_a?(Class)
105
- return ["Success", entity]
110
+ return ["Success", entity, nil]
106
111
  end
107
112
 
108
- return ["Success", nil] unless entity.is_a?(Hash)
113
+ return ["Success", nil, nil] unless entity.is_a?(Hash)
109
114
 
110
- message = entity[:message] || entity["message"] || "Success"
111
- model = entity[:model] || entity["model"]
112
- klass = model.is_a?(Class) ? model : nil
113
- [message, klass]
115
+ message = entity[:message] || entity["message"] || "Success"
116
+ model = entity[:model] || entity["model"]
117
+ inline_schema = entity[:schema] || entity["schema"]
118
+ klass = model.is_a?(Class) ? model : nil
119
+ [message, klass, inline_schema]
114
120
  end
115
121
  end
116
122
  end
@@ -57,6 +57,9 @@ module GrapeOpenapi3
57
57
  private
58
58
 
59
59
  def location(name, defn)
60
+ # Path segments are structural — they always win over any explicit hint.
61
+ return :path if @path_names.include?(name)
62
+
60
63
  explicit = defn.dig(:documentation, :param_type)&.to_s ||
61
64
  defn.dig(:documentation, :in)&.to_s
62
65
 
@@ -68,8 +71,7 @@ module GrapeOpenapi3
68
71
  when "formData" then return :form
69
72
  end
70
73
 
71
- return :path if @path_names.include?(name)
72
- return :form if file_type?(defn[:type])
74
+ return :form if file_type?(defn[:type])
73
75
  BODY_METHODS.include?(@method) ? :body : :query
74
76
  end
75
77
 
@@ -116,8 +118,9 @@ module GrapeOpenapi3
116
118
 
117
119
  params.each do |name, defn|
118
120
  schema = TypeMapper.call(defn[:type] || String)
119
- schema["enum"] = Array(defn[:values]) if defn[:values]
120
- schema["default"] = defn[:default] unless defn[:default].nil?
121
+ schema["enum"] = Array(defn[:values]) if defn[:values]
122
+ schema["default"] = defn[:default] unless defn[:default].nil?
123
+ schema["nullable"] = true unless defn[:required]
121
124
 
122
125
  desc = defn[:desc] || defn[:description]
123
126
  schema["description"] = desc.to_s if desc
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeOpenapi3
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape_openapi3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rodrigonbarreto