oas_rails 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/oas_rails/builders/responses_builder.rb +4 -1
- data/lib/oas_rails/configuration.rb +1 -1
- data/lib/oas_rails/version.rb +1 -1
- data/lib/oas_rails/yard/example_tag.rb +12 -0
- data/lib/oas_rails/yard/oas_rails_factory.rb +20 -1
- data/lib/oas_rails/yard/request_body_example_tag.rb +2 -3
- data/lib/oas_rails/yard/response_example_tag.rb +12 -0
- data/lib/oas_rails/yard/response_tag.rb +1 -0
- data/lib/oas_rails.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f833de18481bb481d9f698a2f10a3b7f1a1512623cd335932659736f94b2161
|
4
|
+
data.tar.gz: 343243f10ae846b8eb42ca75cdd3d69332fe19b41192959bb355603fa2148242
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e41ce594245affa26d85f05bba1fbdb1b6dacbb1d112c42aaa63c0837654a56d4afdd9eb442bc7000f3ceda90fb254aea5712a5e2d3aeff58d1505d869957a3
|
7
|
+
data.tar.gz: 1be4b42da76e635d82ee95f663ea9ca950873b2c6037779598cfa0c284076a022a05aaeb772dd66f5a08b76bedbac7be3ac27453db0a07a4be8e7e0b3213bca9
|
data/README.md
CHANGED
@@ -197,7 +197,22 @@ Documents the responses of the endpoint and overrides the default responses foun
|
|
197
197
|
|
198
198
|
`# @response User not found by the provided Id(404) [Hash{success: Boolean, message: String}]`
|
199
199
|
|
200
|
-
`# @response Validation errors(422) [Hash{success: Boolean,
|
200
|
+
`# @response Validation errors(422) [Hash{success: Boolean, errors: Array<Hash{field: String, type: String, detail: Array<String>}>}]`
|
201
|
+
|
202
|
+
</details>
|
203
|
+
|
204
|
+
<details>
|
205
|
+
<summary style="font-weight: bold; font-size: 1.2em;">@response_example</summary>
|
206
|
+
|
207
|
+
**Structure**: `@response_example text(code) [String Hash]`
|
208
|
+
|
209
|
+
Documents response examples of the endpoint associated to a response code.
|
210
|
+
|
211
|
+
**Example**:
|
212
|
+
|
213
|
+
`# @response_example Invalida Email(422) [{success: "false", errors: [{field: "email", type: "email", detail: ["Invalid email"]}] }]`
|
214
|
+
|
215
|
+
`# @response_example Id not exists (404) [{success: "false", message: "Nothing found with the provided ID." }]`
|
201
216
|
|
202
217
|
</details>
|
203
218
|
|
@@ -8,7 +8,10 @@ module OasRails
|
|
8
8
|
|
9
9
|
def from_oas_route(oas_route)
|
10
10
|
oas_route.docstring.tags(:response).each do |tag|
|
11
|
-
|
11
|
+
content = ContentBuilder.new(@specification, :outgoing).with_schema(tag.schema).with_examples_from_tags(oas_route.docstring.tags(:response_example).filter { |re| re.code == tag.name }).build
|
12
|
+
response = ResponseBuilder.new(@specification).with_code(tag.name.to_i).with_description(tag.text).with_content(content).build
|
13
|
+
|
14
|
+
@responses.add_response(response)
|
12
15
|
end
|
13
16
|
|
14
17
|
self
|
@@ -26,7 +26,7 @@ module OasRails
|
|
26
26
|
@security_schemas = {}
|
27
27
|
@set_default_responses = true
|
28
28
|
@possible_default_responses = [:not_found, :unauthorized, :forbidden]
|
29
|
-
@response_body_of_default = "{ message: String }"
|
29
|
+
@response_body_of_default = "Hash{ success: !Boolean, message: String }"
|
30
30
|
end
|
31
31
|
|
32
32
|
def security_schema=(value)
|
data/lib/oas_rails/version.rb
CHANGED
@@ -37,6 +37,15 @@ module OasRails
|
|
37
37
|
ResponseTag.new(tag_name, code, name, schema)
|
38
38
|
end
|
39
39
|
|
40
|
+
# Parses a tag that represents a response example.
|
41
|
+
# @param tag_name [String] The name of the tag.
|
42
|
+
# @param text [String] The tag text to parse.
|
43
|
+
# @return [ResponseExampleTag] The parsed response example tag object.
|
44
|
+
def parse_tag_with_response_example(tag_name, text)
|
45
|
+
description, code, hash = extract_name_code_and_hash(text)
|
46
|
+
ResponseExampleTag.new(tag_name, description, content: hash, code:)
|
47
|
+
end
|
48
|
+
|
40
49
|
private
|
41
50
|
|
42
51
|
# Reusable method for extracting description, type, and content with an option to process content.
|
@@ -44,7 +53,7 @@ module OasRails
|
|
44
53
|
# @param process_content [Boolean] Whether to evaluate the content as a hash.
|
45
54
|
# @return [Array] An array containing the description, type, and content or remaining text.
|
46
55
|
def extract_description_type_and_content(text, process_content: false)
|
47
|
-
match = text.match(/^(.*?)\s*\[(
|
56
|
+
match = text.match(/^(.*?)\s*\[(.*)\]\s*(.*)$/)
|
48
57
|
raise ArgumentError, "Invalid tag format: #{text}" if match.nil?
|
49
58
|
|
50
59
|
description = match[1].strip
|
@@ -84,6 +93,16 @@ module OasRails
|
|
84
93
|
[name, code, schema]
|
85
94
|
end
|
86
95
|
|
96
|
+
# Specific method to extract name, code, and hash for responses examples.
|
97
|
+
# @param text [String] The text to parse.
|
98
|
+
# @return [Array] An array containing the name, code, and schema.
|
99
|
+
def extract_name_code_and_hash(text)
|
100
|
+
name, code = extract_text_and_parentheses_content(text)
|
101
|
+
_, type, = extract_description_type_and_content(text)
|
102
|
+
hash = eval_content(type)
|
103
|
+
[name, code, hash]
|
104
|
+
end
|
105
|
+
|
87
106
|
# Evaluates a string as a hash, handling errors gracefully.
|
88
107
|
# @param content [String] The content string to evaluate.
|
89
108
|
# @return [Hash] The evaluated hash, or an empty hash if an error occurs.
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module OasRails
|
2
2
|
module YARD
|
3
|
-
class RequestBodyExampleTag <
|
3
|
+
class RequestBodyExampleTag < ExampleTag
|
4
4
|
attr_accessor :content
|
5
5
|
|
6
6
|
def initialize(tag_name, text, content: {})
|
7
|
-
super
|
8
|
-
@content = content
|
7
|
+
super
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
data/lib/oas_rails.rb
CHANGED
@@ -47,9 +47,11 @@ module OasRails
|
|
47
47
|
|
48
48
|
module YARD
|
49
49
|
autoload :RequestBodyTag, 'oas_rails/yard/request_body_tag'
|
50
|
+
autoload :ExampleTag, 'oas_rails/yard/example_tag'
|
50
51
|
autoload :RequestBodyExampleTag, 'oas_rails/yard/request_body_example_tag'
|
51
52
|
autoload :ParameterTag, 'oas_rails/yard/parameter_tag'
|
52
53
|
autoload :ResponseTag, 'oas_rails/yard/response_tag'
|
54
|
+
autoload :ResponseExampleTag, 'oas_rails/yard/response_example_tag'
|
53
55
|
autoload :OasRailsFactory, 'oas_rails/yard/oas_rails_factory'
|
54
56
|
end
|
55
57
|
|
@@ -84,6 +86,7 @@ module OasRails
|
|
84
86
|
'Request body Example' => [:request_body_example, :with_request_body_example],
|
85
87
|
'Parameter' => [:parameter, :with_parameter],
|
86
88
|
'Response' => [:response, :with_response],
|
89
|
+
'Response Example' => [:response_example, :with_response_example],
|
87
90
|
'Endpoint Tags' => [:tags],
|
88
91
|
'Summary' => [:summary],
|
89
92
|
'No Auth' => [:no_auth],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a-chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: method_source
|
@@ -130,10 +130,12 @@ files:
|
|
130
130
|
- lib/oas_rails/spec/tag.rb
|
131
131
|
- lib/oas_rails/utils.rb
|
132
132
|
- lib/oas_rails/version.rb
|
133
|
+
- lib/oas_rails/yard/example_tag.rb
|
133
134
|
- lib/oas_rails/yard/oas_rails_factory.rb
|
134
135
|
- lib/oas_rails/yard/parameter_tag.rb
|
135
136
|
- lib/oas_rails/yard/request_body_example_tag.rb
|
136
137
|
- lib/oas_rails/yard/request_body_tag.rb
|
138
|
+
- lib/oas_rails/yard/response_example_tag.rb
|
137
139
|
- lib/oas_rails/yard/response_tag.rb
|
138
140
|
homepage: https://github.com/a-chacon/oas_rails
|
139
141
|
licenses:
|