swagger_autogenerate 1.2.2 → 1.2.4

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: baeb0333fe686eb9c041d44e0a37f816ea1467b5eff9acb59189bf2c8ee1ca22
4
- data.tar.gz: b4a9d7f8bcbacd061cc7f61058e81d3eebf31908ddb47058155ba45b8d6d0df9
3
+ metadata.gz: 4d62d2b3204e47e668408ea353aa7f5015a9f1a8f86e727e635b1030e999f587
4
+ data.tar.gz: 7cbcbfc449684fe35db3c76c7c8bb0ae357ebabf8585ba7289c3b6d58abec9a9
5
5
  SHA512:
6
- metadata.gz: 78da25f6d4ff424ecfe162016f2f5565c4ac1f9995767f45efa4030d95df9a15132a2ebaf692620fd5bc500916b69689dac5fd8aeac6ee53ea67ee64a2764779
7
- data.tar.gz: 87d783020090efc560b3ae50dc21846a7e9b3f682119fbc4c61b8610450e165dc1b7fd6c9fd64b6648a809d6a7c14c3bdb7ff0e5c34b723ea8cea86f5e39fc1d
6
+ metadata.gz: f9dea5813fe7a651d4fa59d618b86a02a2e909a23bdcb8744aa56bd96ff667143482d52316b70f78868c2cbbf3de5e2e6104b9cdb8f13e00e6a2483f15ac2da7
7
+ data.tar.gz: a7fa27d728d65a7e8d2fb58dcb052c81d1486a1d3c89b3326851797419cff037e28322eec8284a19f81be1c4121ed9dd33a83605a31ee1606bdccfa61b30c813
data/CHANGELOG.md CHANGED
@@ -15,5 +15,7 @@
15
15
  ## [1.2.0] - 2024-09-08
16
16
  ## [1.2.1] - 2024-09-08
17
17
  ## [1.2.2] - 2024-09-12
18
+ ## [1.2.3] - 2024-09-12
19
+ ## [1.2.4] - 2024-09-15
18
20
 
19
21
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagger_autogenerate (1.2.2)
4
+ swagger_autogenerate (1.2.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- @swagger_path_environment_variable = 'SWAGGER_PATH'
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, :default_path
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'")
@@ -396,14 +421,14 @@ module SwaggerAutogenerate
396
421
  end
397
422
 
398
423
  def is_valid_date?(string)
399
- Date.parse(string)
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 = DateTime.parse(string)
431
+ datetime = DateTime.strptime(string)
407
432
  datetime.strftime('%Y-%m-%d')
408
433
  rescue ArgumentError
409
434
  string
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "1.2.2"
4
+ VERSION = "1.2.4"
5
5
  end
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.2
4
+ version: 1.2.4
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-12 00:00:00.000000000 Z
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