swagger_autogenerate 1.2.1 → 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: f6f642d29cd299f7f2e7b32b7e87a89f6a6b0f037f11bd5c7bcabbfd56d34de1
4
- data.tar.gz: 624631c39528ce4d096325dc638e2031363424124cc9922032005a44e26a2fd8
3
+ metadata.gz: 4d62d2b3204e47e668408ea353aa7f5015a9f1a8f86e727e635b1030e999f587
4
+ data.tar.gz: 7cbcbfc449684fe35db3c76c7c8bb0ae357ebabf8585ba7289c3b6d58abec9a9
5
5
  SHA512:
6
- metadata.gz: 2208abc4d89eac17e33f02f3c8a541ee9f68c6b1590ed93a7785ee941b9cc31e3b7fe3f74ad16689cf93639329fe85a30334651449ce7ace10699ef3ef4e1760
7
- data.tar.gz: 8ef10a7cd712aa5114ac38395b189d84f7ec83fa9b05b64ac5ce0c8b5f7632d4cb33dea35d4cc4211c66471dae5f7ee6e15810fe7394951d1afd07ef0cd17154
6
+ metadata.gz: f9dea5813fe7a651d4fa59d618b86a02a2e909a23bdcb8744aa56bd96ff667143482d52316b70f78868c2cbbf3de5e2e6104b9cdb8f13e00e6a2483f15ac2da7
7
+ data.tar.gz: a7fa27d728d65a7e8d2fb58dcb052c81d1486a1d3c89b3326851797419cff037e28322eec8284a19f81be1c4121ed9dd33a83605a31ee1606bdccfa61b30c813
data/CHANGELOG.md CHANGED
@@ -14,5 +14,8 @@
14
14
  ## [1.1.2] - 2024-08-17
15
15
  ## [1.2.0] - 2024-09-08
16
16
  ## [1.2.1] - 2024-09-08
17
+ ## [1.2.2] - 2024-09-12
18
+ ## [1.2.3] - 2024-09-12
19
+ ## [1.2.4] - 2024-09-15
17
20
 
18
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.1)
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
@@ -82,9 +83,4 @@ module SwaggerAutogenerate
82
83
  def self.configure
83
84
  yield(configuration)
84
85
  end
85
-
86
- def self.extract_description(full_rspec_description)
87
- parts = full_rspec_description.split(' ')
88
- parts&.length > 1 ? parts[2..-1].join(" ") : full_rspec_description
89
- end
90
86
  end
@@ -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
@@ -528,9 +553,11 @@ module SwaggerAutogenerate
528
553
  end
529
554
 
530
555
  def handel_name_last_example(old_examples)
531
- last_example = old_examples.keys.last
532
- last_example += '-1' if json_example_plus_one(last_example) == last_example
533
- json_example_plus_one(last_example)
556
+ last_example = full_rspec_description || old_examples.keys.last
557
+ if old_examples.keys.include?(last_example)
558
+ last_example += '-1'
559
+ json_example_plus_one(last_example)
560
+ end
534
561
  end
535
562
 
536
563
  def add_properties_to_schema(last_example, main_path = yaml_file['paths'][current_path])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.4"
5
5
  end
@@ -25,7 +25,7 @@ if defined?(RSpec) && SwaggerAutogenerate.allow_swagger?
25
25
 
26
26
  RSpec.configure do |config|
27
27
  config.before(:each) do |example|
28
- SwaggerAutogenerate::SwaggerTrace.rspec_description = SwaggerAutogenerate.extract_description(example.metadata[:full_description])
28
+ SwaggerAutogenerate::SwaggerTrace.rspec_description = example&.metadata.dig(:example_group, :description)
29
29
  end
30
30
  end
31
31
  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.1
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-10 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