swagger_autogenerate 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1adeb3bac00fabb0f8f62df4b322a3a2ee4dc0068c5c404e9533e1a0e9f75f5b
4
- data.tar.gz: 10a0f11601d637b23378d2808a055e1140b4a79be7080b1e40ca4b5b668f2c57
3
+ metadata.gz: 5a79f228421fcf8a16a00e06ca839087079f3682a75b59a60db6b80711010958
4
+ data.tar.gz: f8ee425bfb9d3a65905ebd1a03c527b2d55b52590f217b5e2a400760f964d373
5
5
  SHA512:
6
- metadata.gz: ea65f1e69465f1deda419b6fda47d775a2935f71c8cbd1dd0b3bbdc268e777d76212c4d7b66ab43743f69fa54b303f51259f984a713ed2c95810d22e1afa0d3f
7
- data.tar.gz: b82d945b513d0e7c9bfa7f395985659043d9bff8c0bf782cc8c91dfd4664a16d612da7575546186fb7d18907622c97eefbc7d15d43bfb9f8db0d8c5bfd24f097
6
+ metadata.gz: b5867cf7d6d7dd713a5eb84eb2a1f9f222ad7c9e299a99a572fdad5596ddb181d9a47c217cc32345b4cae98aac8af09c9684738cd526d4b481f8282ae932bc90
7
+ data.tar.gz: 4e58b9f677e91a2811bbbd866ab948f0a5976312e5c7a8df1584337c4dc32d149cb6dd7bac946210abaf4fc14058bcde3ca76419055704d467ff965e830e23d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-02-20
3
+ ## [0.1.1] - 2024-05-27
4
+ ## [1.0.1] - 2024-05-31
4
5
 
5
6
  - Initial release
@@ -13,12 +13,14 @@ 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
20
- read_swaggger_trace
21
- write_swaggger_trace
20
+ if ENV[SWAGGER_ENVIRONMENT_VARIABLE].present?
21
+ read_swagger_trace
22
+ write_swagger_trace
23
+ end
22
24
  end
23
25
 
24
26
  private
@@ -27,7 +29,7 @@ module SwaggerAutogenerate
27
29
 
28
30
  # main methods
29
31
 
30
- def read_swaggger_trace
32
+ def read_swagger_trace
31
33
  path = request.path
32
34
 
33
35
  request.path_parameters.except(:controller, :format, :action).each do |k, v|
@@ -49,13 +51,13 @@ module SwaggerAutogenerate
49
51
  }
50
52
 
51
53
  hash[method].except!('requestBody') if hash[method]['requestBody'].blank?
52
- paths[path.to_s] ||= {}
53
- paths[path.to_s].merge!(hash)
54
+ @paths[path.to_s] ||= {}
55
+ @paths[path.to_s].merge!(hash)
54
56
  end
55
57
 
56
- def write_swaggger_trace
57
- if paths[current_path][request.method.downcase].present?
58
- paths[current_path][request.method.downcase]['responses'] = swagger_response
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
61
  end
60
62
 
61
63
  if File.exist?(swagger_location)
@@ -68,7 +70,7 @@ module SwaggerAutogenerate
68
70
  def create_file
69
71
  File.open(swagger_location, 'w') do |file|
70
72
  data = WITH_CONFIG ? swagger_config : {}
71
- data['paths'] = paths
73
+ data['paths'] = @paths
72
74
  organize_result(data['paths'])
73
75
  data = data.to_hash
74
76
  result = add_quotes_to_dates(YAML.dump(data))
@@ -83,15 +85,15 @@ module SwaggerAutogenerate
83
85
  permitted_classes: [Symbol, Date, ActiveSupport::HashWithIndifferentAccess]
84
86
  )
85
87
 
86
- return create_file if yaml_file.nil? || yaml_file['paths'].nil?
88
+ return create_file if @yaml_file.nil? || @yaml_file['paths'].nil?
87
89
 
88
- yaml_file.merge!(swagger_config) if WITH_CONFIG
90
+ @yaml_file.merge!(swagger_config) if WITH_CONFIG
89
91
 
90
92
  apply_yaml_file_changes
91
- organize_result(yaml_file['paths'])
92
- @yaml_file = convert_to_hash(yaml_file)
93
+ organize_result(@yaml_file['paths'])
94
+ @yaml_file = convert_to_hash(@yaml_file)
93
95
  File.open(swagger_location, 'w') do |file|
94
- result = add_quotes_to_dates(YAML.dump(yaml_file))
96
+ result = add_quotes_to_dates(YAML.dump(@yaml_file))
95
97
  file.write(result)
96
98
  end
97
99
  end
@@ -296,7 +298,7 @@ module SwaggerAutogenerate
296
298
  # Static
297
299
 
298
300
  def paths
299
- @@paths ||= {}
301
+ @paths ||= {}
300
302
  end
301
303
 
302
304
  def security
@@ -418,7 +420,7 @@ module SwaggerAutogenerate
418
420
 
419
421
  def check_path
420
422
  unless old_paths.key?(current_path)
421
- yaml_file['paths'].merge!({ current_path => paths[current_path] })
423
+ yaml_file['paths'].merge!({ current_path => @paths[current_path] })
422
424
  end
423
425
  end
424
426
 
@@ -442,29 +444,29 @@ module SwaggerAutogenerate
442
444
 
443
445
  def check_parameters
444
446
  if old_paths[current_path][request.method.downcase]['parameters'].blank?
445
- 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']
446
448
  end
447
449
  end
448
450
 
449
451
  def check_parameter
450
- 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')
451
453
  param_names.each do |param_name|
452
- 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 }
453
455
  yaml_file['paths'][current_path][request.method.downcase]['parameters'].push(param)
454
456
  end
455
457
  end
456
458
 
457
459
  def check_request_bodys
458
- if paths[current_path][request.method.downcase]['requestBody'].present? && old_paths[current_path][request.method.downcase]['requestBody'].nil?
459
- 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']
460
462
  end
461
463
  end
462
464
 
463
465
  def check_request_body
464
- if paths[current_path][request.method.downcase]['requestBody'].present?
465
- 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
466
468
  param_names.each do |param_name|
467
- 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 }
468
470
  yaml_file['paths'][current_path][request.method.downcase]['requestBody']['content']['multipart/form-data']['schema']['properties'].merge!(param)
469
471
  end
470
472
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.1"
5
5
  end
Binary file
Binary file
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["MohammedBuraiah"]
9
9
  spec.email = ["mohammed.buraiah.1996@gmail.com"]
10
10
 
11
- spec.summary = "Write a short summary, because RubyGems requires one."
12
- spec.description = "Write a longer description or delete this line."
11
+ spec.summary = "Automating Swagger YAML generation in Ruby on Rails offers a range of benefits for API documentation"
12
+ spec.description = "Generating Swagger YAML Automatically Based on Existing Test Cases in Ruby on Rails"
13
13
  spec.homepage = "https://github.com/MohammedBuraiah/swagger_autogenerate"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_autogenerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MohammedBuraiah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-27 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Write a longer description or delete this line.
13
+ description: Generating Swagger YAML Automatically Based on Existing Test Cases in
14
+ Ruby on Rails
14
15
  email:
15
16
  - mohammed.buraiah.1996@gmail.com
16
17
  executables: []
@@ -28,6 +29,8 @@ files:
28
29
  - lib/swagger_autogenerate/swagger_trace.rb
29
30
  - lib/swagger_autogenerate/version.rb
30
31
  - sig/swagger_autogenerate.rbs
32
+ - swagger_autogenerate-0.1.0.gem
33
+ - swagger_autogenerate-0.1.1.gem
31
34
  - swagger_autogenerate.gemspec
32
35
  homepage: https://github.com/MohammedBuraiah/swagger_autogenerate
33
36
  licenses:
@@ -55,5 +58,6 @@ requirements: []
55
58
  rubygems_version: 3.4.19
56
59
  signing_key:
57
60
  specification_version: 4
58
- summary: Write a short summary, because RubyGems requires one.
61
+ summary: Automating Swagger YAML generation in Ruby on Rails offers a range of benefits
62
+ for API documentation
59
63
  test_files: []