swagger_autogenerate 1.0.1 → 1.0.2
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 +1 -2
- data/README.md +15 -6
- data/lib/swagger_autogenerate/swagger_trace.rb +21 -21
- data/lib/swagger_autogenerate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b52220aecae46c5818f0640a1ca979f59d38fba0720e2d5a35685fbb6c06bbd
|
4
|
+
data.tar.gz: 995666a3bd4de256824656420231be0c38d564aa236a6bfca10659d1474908ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c966988c943c3d108a30fa1abc38cef2295679e8f02b2f1dd302a64eedca45d5c97f37ff2c30f7ca35c516b92fa797ea6a0670a25ef1c587cef97ab22433f569
|
7
|
+
data.tar.gz: a6e6c285bdad27980d524f221c8ae5204e06a3ed222de805c2c5a6ebcda637c5e312712f395aa9247bae4002182fad5d264056c0b837a9a38c7ff5dd0d105d1c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,12 @@ automating Swagger YAML generation in Ruby on Rails offers a range of benefits f
|
|
7
7
|
|
8
8
|
The gem automatically observes the request/response patterns during the execution of test scenarios, generating accurate Swagger YAML files that reflect the API's behavior. developers and consumers can better understand and interact with the APIs.
|
9
9
|
|
10
|
+
## Dependencies
|
11
|
+
|
12
|
+
The SwaggerAutogenerate gem depends on the rspec-rails gem, which brings the RSpec testing framework to Ruby on Rails.
|
13
|
+
Please install rspec-rails first: https://github.com/rspec/rspec-rails
|
14
|
+
Then continue the installation process.
|
15
|
+
|
10
16
|
## Installation
|
11
17
|
|
12
18
|
1) Open your Gemfile located at ./Gemfile
|
@@ -18,7 +24,9 @@ The gem automatically observes the request/response patterns during the executio
|
|
18
24
|
end
|
19
25
|
```
|
20
26
|
3) Install the gem and add to the application's Gemfile by executing:
|
21
|
-
|
27
|
+
```
|
28
|
+
bundle install
|
29
|
+
```
|
22
30
|
|
23
31
|
## Configuration
|
24
32
|
|
@@ -31,6 +39,11 @@ To configure the swagger_autogenerate gem in your Rails application, follow thes
|
|
31
39
|
```
|
32
40
|
include SwaggerAutogenerate if Rails.env.test? && ENV['SWAGGER'].present?
|
33
41
|
```
|
42
|
+
in the #Example-step you will set the ENV['SWAGGER'],
|
43
|
+
|
44
|
+
By setting the ENV['SWAGGER'] environment variable, you can specify the path to the new file,
|
45
|
+
whether it's a specific file (e.g., ../myfile.yaml) or a directory (e.g., ../docs).
|
46
|
+
This flexibility ensures that the documentation can be easily integrated into your project's structure and workflow.
|
34
47
|
|
35
48
|
### Step 2 (optional)
|
36
49
|
1) Create a file called swagger_autogenerate.rb in the ./config/initializers
|
@@ -56,7 +69,7 @@ To generate Swagger YAML documentation for the APIs implemented in the Employees
|
|
56
69
|
$ spec/your_path/employees_controller_spec.rb
|
57
70
|
This file should contain the test scenarios for each action (e.g., index, show, create) of the controller.
|
58
71
|
|
59
|
-
3)Run the spec code using the rspec command and set the environment variable SWAGGER to the desired YAML file name. For example:
|
72
|
+
3) Run the spec code using the rspec command and set the environment variable SWAGGER to the desired YAML file name. For example:
|
60
73
|
```
|
61
74
|
SWAGGER='employee_apis.yaml' rspec spec/your_path/employees_controller_spec.rb
|
62
75
|
```
|
@@ -69,7 +82,3 @@ that the generated documentation will depend on the test scenarios defined in yo
|
|
69
82
|
## License
|
70
83
|
|
71
84
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
72
|
-
|
73
|
-
## Code of Conduct
|
74
|
-
|
75
|
-
Everyone interacting in the SwaggerAutogenerate project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/swagger_autogenerate/blob/master/CODE_OF_CONDUCT.md).
|
@@ -13,7 +13,7 @@ module SwaggerAutogenerate
|
|
13
13
|
def initialize(request, response)
|
14
14
|
@request = request
|
15
15
|
@response = response
|
16
|
-
|
16
|
+
@@paths = {}
|
17
17
|
end
|
18
18
|
|
19
19
|
def call
|
@@ -51,13 +51,13 @@ module SwaggerAutogenerate
|
|
51
51
|
}
|
52
52
|
|
53
53
|
hash[method].except!('requestBody') if hash[method]['requestBody'].blank?
|
54
|
-
|
55
|
-
|
54
|
+
paths[path.to_s] ||= {}
|
55
|
+
paths[path.to_s].merge!(hash)
|
56
56
|
end
|
57
57
|
|
58
58
|
def write_swagger_trace
|
59
|
-
if
|
60
|
-
|
59
|
+
if paths[current_path][request.method.downcase].present?
|
60
|
+
paths[current_path][request.method.downcase]['responses'] = swagger_response
|
61
61
|
end
|
62
62
|
|
63
63
|
if File.exist?(swagger_location)
|
@@ -70,7 +70,7 @@ module SwaggerAutogenerate
|
|
70
70
|
def create_file
|
71
71
|
File.open(swagger_location, 'w') do |file|
|
72
72
|
data = WITH_CONFIG ? swagger_config : {}
|
73
|
-
data['paths'] =
|
73
|
+
data['paths'] = paths
|
74
74
|
organize_result(data['paths'])
|
75
75
|
data = data.to_hash
|
76
76
|
result = add_quotes_to_dates(YAML.dump(data))
|
@@ -85,15 +85,15 @@ module SwaggerAutogenerate
|
|
85
85
|
permitted_classes: [Symbol, Date, ActiveSupport::HashWithIndifferentAccess]
|
86
86
|
)
|
87
87
|
|
88
|
-
return create_file if
|
88
|
+
return create_file if yaml_file.nil? || yaml_file['paths'].nil?
|
89
89
|
|
90
|
-
|
90
|
+
yaml_file.merge!(swagger_config) if WITH_CONFIG
|
91
91
|
|
92
92
|
apply_yaml_file_changes
|
93
|
-
organize_result(
|
94
|
-
@yaml_file = convert_to_hash(
|
93
|
+
organize_result(yaml_file['paths'])
|
94
|
+
@yaml_file = convert_to_hash(yaml_file)
|
95
95
|
File.open(swagger_location, 'w') do |file|
|
96
|
-
result = add_quotes_to_dates(YAML.dump(
|
96
|
+
result = add_quotes_to_dates(YAML.dump(yaml_file))
|
97
97
|
file.write(result)
|
98
98
|
end
|
99
99
|
end
|
@@ -298,7 +298,7 @@ module SwaggerAutogenerate
|
|
298
298
|
# Static
|
299
299
|
|
300
300
|
def paths
|
301
|
-
|
301
|
+
@@paths ||= {}
|
302
302
|
end
|
303
303
|
|
304
304
|
def security
|
@@ -420,7 +420,7 @@ module SwaggerAutogenerate
|
|
420
420
|
|
421
421
|
def check_path
|
422
422
|
unless old_paths.key?(current_path)
|
423
|
-
yaml_file['paths'].merge!({ current_path =>
|
423
|
+
yaml_file['paths'].merge!({ current_path => paths[current_path] })
|
424
424
|
end
|
425
425
|
end
|
426
426
|
|
@@ -444,29 +444,29 @@ module SwaggerAutogenerate
|
|
444
444
|
|
445
445
|
def check_parameters
|
446
446
|
if old_paths[current_path][request.method.downcase]['parameters'].blank?
|
447
|
-
yaml_file['paths'][current_path][request.method.downcase]['parameters'] =
|
447
|
+
yaml_file['paths'][current_path][request.method.downcase]['parameters'] = paths[current_path][request.method.downcase]['parameters']
|
448
448
|
end
|
449
449
|
end
|
450
450
|
|
451
451
|
def check_parameter
|
452
|
-
param_names =
|
452
|
+
param_names = paths[current_path][request.method.downcase]['parameters'].pluck('name') - yaml_file['paths'][current_path][request.method.downcase]['parameters'].pluck('name')
|
453
453
|
param_names.each do |param_name|
|
454
|
-
param =
|
454
|
+
param = paths[current_path][request.method.downcase]['parameters'].find { |parameter| parameter['name'] == param_name }
|
455
455
|
yaml_file['paths'][current_path][request.method.downcase]['parameters'].push(param)
|
456
456
|
end
|
457
457
|
end
|
458
458
|
|
459
459
|
def check_request_bodys
|
460
|
-
if
|
461
|
-
yaml_file['paths'][current_path][request.method.downcase]['requestBody'] =
|
460
|
+
if paths[current_path][request.method.downcase]['requestBody'].present? && old_paths[current_path][request.method.downcase]['requestBody'].nil?
|
461
|
+
yaml_file['paths'][current_path][request.method.downcase]['requestBody'] = paths[current_path][request.method.downcase]['requestBody']
|
462
462
|
end
|
463
463
|
end
|
464
464
|
|
465
465
|
def check_request_body
|
466
|
-
if
|
467
|
-
param_names =
|
466
|
+
if paths[current_path][request.method.downcase]['requestBody'].present?
|
467
|
+
param_names = paths[current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].keys - yaml_file['paths'][current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].keys
|
468
468
|
param_names.each do |param_name|
|
469
|
-
param =
|
469
|
+
param = paths[current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].select { |parameter| parameter == param_name }
|
470
470
|
yaml_file['paths'][current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].merge!(param)
|
471
471
|
end
|
472
472
|
end
|