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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a79f228421fcf8a16a00e06ca839087079f3682a75b59a60db6b80711010958
4
- data.tar.gz: f8ee425bfb9d3a65905ebd1a03c527b2d55b52590f217b5e2a400760f964d373
3
+ metadata.gz: 0b52220aecae46c5818f0640a1ca979f59d38fba0720e2d5a35685fbb6c06bbd
4
+ data.tar.gz: 995666a3bd4de256824656420231be0c38d564aa236a6bfca10659d1474908ff
5
5
  SHA512:
6
- metadata.gz: b5867cf7d6d7dd713a5eb84eb2a1f9f222ad7c9e299a99a572fdad5596ddb181d9a47c217cc32345b4cae98aac8af09c9684738cd526d4b481f8282ae932bc90
7
- data.tar.gz: 4e58b9f677e91a2811bbbd866ab948f0a5976312e5c7a8df1584337c4dc32d149cb6dd7bac946210abaf4fc14058bcde3ca76419055704d467ff965e830e23d4
6
+ metadata.gz: c966988c943c3d108a30fa1abc38cef2295679e8f02b2f1dd302a64eedca45d5c97f37ff2c30f7ca35c516b92fa797ea6a0670a25ef1c587cef97ab22433f569
7
+ data.tar.gz: a6e6c285bdad27980d524f221c8ae5204e06a3ed222de805c2c5a6ebcda637c5e312712f395aa9247bae4002182fad5d264056c0b837a9a38c7ff5dd0d105d1c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,5 @@
1
1
  ## [Unreleased]
2
2
 
3
3
  ## [0.1.1] - 2024-05-27
4
- ## [1.0.1] - 2024-05-31
5
-
4
+ ## [1.0.2] - 2024-05-31
6
5
  - Initial release
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
- $ bundle install
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
- @paths = {}
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
- @paths[path.to_s] ||= {}
55
- @paths[path.to_s].merge!(hash)
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 @paths[current_path][request.method.downcase].present?
60
- @paths[current_path][request.method.downcase]['responses'] = swagger_response
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'] = @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 @yaml_file.nil? || @yaml_file['paths'].nil?
88
+ return create_file if yaml_file.nil? || yaml_file['paths'].nil?
89
89
 
90
- @yaml_file.merge!(swagger_config) if WITH_CONFIG
90
+ yaml_file.merge!(swagger_config) if WITH_CONFIG
91
91
 
92
92
  apply_yaml_file_changes
93
- organize_result(@yaml_file['paths'])
94
- @yaml_file = convert_to_hash(@yaml_file)
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(@yaml_file))
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
- @paths ||= {}
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 => @paths[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'] = @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 = @paths[current_path][request.method.downcase]['parameters'].pluck('name') - yaml_file['paths'][current_path][request.method.downcase]['parameters'].pluck('name')
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 = @paths[current_path][request.method.downcase]['parameters'].find { |parameter| parameter['name'] == param_name }
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 @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']
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 @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
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 = @paths[current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].select { |parameter| parameter == param_name }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_autogenerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MohammedBuraiah