swagger_autogenerate 1.2.2 → 1.2.5
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/swagger_autogenerate/configuration.rb +3 -2
- data/lib/swagger_autogenerate/swagger_trace.rb +37 -12
- data/lib/swagger_autogenerate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fbb1ab2c8c24337c43f68b09a4452cbbf5256ac31f44d1b35ea392488c43708
|
4
|
+
data.tar.gz: 89f43851ca840877b888e5e83217af2b42ba0fa694943885e67e76b5178e63ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8f034a350700b4b0a73e6d8b935d659c5b2c470da0a510f1652e182ba044f20eacebd1c7127b3591c37b7b18f54a599d92fbe7de4301595e3d8526a55a948c2
|
7
|
+
data.tar.gz: 5ec0cb3486777df804a45f8e7c0f49e2f05c0dc8906e808f6378fecacd5d3776330ab99f3d3a59a0477b1dbd7428ba8a8e51f1b6843816f7412d4f43b3a8c3d7
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,8 +47,8 @@ To configure the swagger_autogenerate gem in your Rails application, follow thes
|
|
47
47
|
```
|
48
48
|
SwaggerAutogenerate.configure do |config|
|
49
49
|
config.with_config = true
|
50
|
-
config.with_example_description = true
|
51
50
|
config.with_multiple_examples = true
|
51
|
+
action_for_old_examples = :append # :replace or :append
|
52
52
|
config.with_response_description = true
|
53
53
|
end
|
54
54
|
|
@@ -64,7 +64,7 @@ This file should contain the test scenarios for each action (e.g., index, show,
|
|
64
64
|
|
65
65
|
3) Run the spec code using the rspec command and set the environment variable SWAGGER to the desired YAML file name. For example:
|
66
66
|
```
|
67
|
-
|
67
|
+
SWAGGER_GENERATE_PATH='employee_apis.yaml' rspec spec/your_path/employees_controller_spec.rb
|
68
68
|
```
|
69
69
|
4) This command runs the spec file and instructs the swagger_autogenerate gem to generate Swagger YAML documentation and save it to the file named employee_apis.yaml.
|
70
70
|
5) Once the command finishes executing, you will have the Swagger YAML documentation generated based on the test scenarios in the employees_controller_spec.rb file.
|
@@ -2,7 +2,7 @@ module SwaggerAutogenerate
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :with_config, :with_multiple_examples, :with_rspec_examples, :with_example_description,
|
4
4
|
:with_response_description, :swagger_path_environment_variable, :generate_swagger_environment_variable,
|
5
|
-
:default_path, :environment_name, :security, :swagger_config, :response_status
|
5
|
+
:default_path, :environment_name, :security, :swagger_config, :response_status, :action_for_old_examples
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@with_config = true
|
@@ -11,7 +11,8 @@ module SwaggerAutogenerate
|
|
11
11
|
# remove this when we do not need it any more
|
12
12
|
@with_example_description = true
|
13
13
|
@with_response_description = true
|
14
|
-
@
|
14
|
+
@action_for_old_examples = :append # :replace or :append
|
15
|
+
@swagger_path_environment_variable = 'SWAGGER_GENERATE_PATH'
|
15
16
|
@generate_swagger_environment_variable = 'SWAGGER_GENERATE'
|
16
17
|
@default_path = 'swagger'
|
17
18
|
@environment_name = :test
|
@@ -13,6 +13,7 @@ module SwaggerAutogenerate
|
|
13
13
|
@default_path = ::SwaggerAutogenerate.configuration.default_path
|
14
14
|
@request = request
|
15
15
|
@response = response
|
16
|
+
@action_for_old_examples = ::SwaggerAutogenerate.configuration.action_for_old_examples
|
16
17
|
@@paths = {}
|
17
18
|
end
|
18
19
|
|
@@ -49,7 +50,8 @@ module SwaggerAutogenerate
|
|
49
50
|
|
50
51
|
attr_reader :request, :response, :current_path, :yaml_file, :configuration,
|
51
52
|
:with_config, :with_multiple_examples, :with_rspec_examples,
|
52
|
-
:with_response_description, :security, :response_status, :swagger_config,
|
53
|
+
:with_response_description, :security, :response_status, :swagger_config,
|
54
|
+
:default_path, :action_for_old_examples
|
53
55
|
|
54
56
|
# main methods
|
55
57
|
|
@@ -62,6 +64,9 @@ module SwaggerAutogenerate
|
|
62
64
|
|
63
65
|
@current_path = path
|
64
66
|
method = request.method.to_s.downcase
|
67
|
+
|
68
|
+
process_replacing_examples
|
69
|
+
|
65
70
|
hash =
|
66
71
|
{
|
67
72
|
method => {
|
@@ -131,6 +136,26 @@ module SwaggerAutogenerate
|
|
131
136
|
|
132
137
|
# Helpers
|
133
138
|
|
139
|
+
def process_replacing_examples
|
140
|
+
$removed_examples ||= []
|
141
|
+
if action_for_old_examples == :replace && !$removed_examples.include?({ @current_path => request.method.to_s.downcase })
|
142
|
+
current_yaml_file = YAML.load(
|
143
|
+
File.read(swagger_location),
|
144
|
+
aliases: true,
|
145
|
+
permitted_classes: [Symbol, Date, ActiveSupport::HashWithIndifferentAccess]
|
146
|
+
)
|
147
|
+
|
148
|
+
current_yaml_file["paths"][@current_path][request.method.to_s.downcase] = {}
|
149
|
+
|
150
|
+
File.open(swagger_location, 'w') do |file|
|
151
|
+
result = add_quotes_to_dates(YAML.dump(current_yaml_file))
|
152
|
+
file.write(result)
|
153
|
+
end
|
154
|
+
|
155
|
+
$removed_examples << { @current_path => request.method.to_s.downcase }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
134
159
|
def add_quotes_to_dates(string)
|
135
160
|
string = remove_quotes_in_dates(string)
|
136
161
|
string.gsub(/\b\d{4}-\d{2}-\d{2}\b/, "'\\0'")
|
@@ -173,6 +198,15 @@ module SwaggerAutogenerate
|
|
173
198
|
hash
|
174
199
|
end
|
175
200
|
|
201
|
+
def schema_type(value)
|
202
|
+
return 'integer' if number?(value)
|
203
|
+
return 'boolean' if (value.try(:downcase) == 'true') || (value.try(:downcase) == 'false')
|
204
|
+
return 'string' if value.instance_of?(String) || value.instance_of?(Symbol)
|
205
|
+
return 'array' if value.instance_of?(Array)
|
206
|
+
|
207
|
+
'object'
|
208
|
+
end
|
209
|
+
|
176
210
|
def set_parameters(parameters, parameter, required: false)
|
177
211
|
return if parameter.blank?
|
178
212
|
|
@@ -378,15 +412,6 @@ module SwaggerAutogenerate
|
|
378
412
|
false
|
379
413
|
end
|
380
414
|
|
381
|
-
def schema_type(value)
|
382
|
-
return 'integer' if number?(value)
|
383
|
-
return 'boolean' if (value.try(:downcase) == 'true') || (value.try(:downcase) == 'false')
|
384
|
-
return 'string' if value.instance_of?(String) || value.instance_of?(Symbol)
|
385
|
-
return 'array' if value.instance_of?(Array)
|
386
|
-
|
387
|
-
'object'
|
388
|
-
end
|
389
|
-
|
390
415
|
def example(value)
|
391
416
|
return value.to_i if number?(value)
|
392
417
|
return convert_to_date(value) if value.instance_of?(String) && is_valid_date?(value)
|
@@ -396,14 +421,14 @@ module SwaggerAutogenerate
|
|
396
421
|
end
|
397
422
|
|
398
423
|
def is_valid_date?(string)
|
399
|
-
Date.
|
424
|
+
Date.strptime(string)
|
400
425
|
true
|
401
426
|
rescue ArgumentError
|
402
427
|
false
|
403
428
|
end
|
404
429
|
|
405
430
|
def convert_to_date(string)
|
406
|
-
datetime =
|
431
|
+
datetime = Date.strptime(string)
|
407
432
|
datetime.strftime('%Y-%m-%d')
|
408
433
|
rescue ArgumentError
|
409
434
|
string
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_autogenerate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MohammedBuraiah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generating Swagger YAML Automatically Based on Existing Test Cases in
|
14
14
|
Ruby on Rails
|