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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3808df464b57163b3cf5adffec3a2b2bda782648d1ee9ad1731b5fbdf0a64fc5
|
|
4
|
+
data.tar.gz: a7687ffba660a3093fa22f318b0c586957532fe376c82fafc213e0cd1f947a11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
111
|
-
model
|
|
112
|
-
|
|
113
|
-
|
|
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 :
|
|
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"]
|
|
120
|
-
schema["default"]
|
|
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
|