swagger_autogenerate 1.1.2 → 1.2.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: fa0e0d56334a728cbd835bf8ecf0cf4b2c330eb62aeb92e6b9bc20d1251ed5cd
4
- data.tar.gz: c5869ad74ec90bffdb1a58bdfbb52645849b14f88e81e876f5b856d280dab536
3
+ metadata.gz: f6f642d29cd299f7f2e7b32b7e87a89f6a6b0f037f11bd5c7bcabbfd56d34de1
4
+ data.tar.gz: 624631c39528ce4d096325dc638e2031363424124cc9922032005a44e26a2fd8
5
5
  SHA512:
6
- metadata.gz: 7766553dbaa81ee1506f36727411a24e36d9dd7c73bc4733a2bc034be406b2c94e4526f7c73467e1d383cf3e566fecaa6ea592a06627f4a5778dba61cd5f142e
7
- data.tar.gz: ab857ce41cc465f94b961c61d2f3bbeb48195c8bf5472152c43524384caa57313325b852df8417e2c07489fed8ae0e656c941d9c91a395ea6e16895ace7a990c
6
+ metadata.gz: 2208abc4d89eac17e33f02f3c8a541ee9f68c6b1590ed93a7785ee941b9cc31e3b7fe3f74ad16689cf93639329fe85a30334651449ce7ace10699ef3ef4e1760
7
+ data.tar.gz: 8ef10a7cd712aa5114ac38395b189d84f7ec83fa9b05b64ac5ce0c8b5f7632d4cb33dea35d4cc4211c66471dae5f7ee6e15810fe7394951d1afd07ef0cd17154
data/CHANGELOG.md CHANGED
@@ -12,5 +12,7 @@
12
12
  ## [1.1.0] - 2024-06-23
13
13
  ## [1.1.1] - 2024-06-26
14
14
  ## [1.1.2] - 2024-08-17
15
+ ## [1.2.0] - 2024-09-08
16
+ ## [1.2.1] - 2024-09-08
15
17
 
16
18
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagger_autogenerate (1.1.2)
4
+ swagger_autogenerate (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -64,7 +64,7 @@ This file should contain the test scenarios for each action (e.g., index, show,
64
64
 
65
65
  3) Run the spec code using the rspec command and set the environment variable SWAGGER to the desired YAML file name. For example:
66
66
  ```
67
- SWAGGER='employee_apis.yaml' rspec spec/your_path/employees_controller_spec.rb
67
+ SWAGGER_PATH='employee_apis.yaml' rspec spec/your_path/employees_controller_spec.rb
68
68
  ```
69
69
  4) This command runs the spec file and instructs the swagger_autogenerate gem to generate Swagger YAML documentation and save it to the file named employee_apis.yaml.
70
70
  5) Once the command finishes executing, you will have the Swagger YAML documentation generated based on the test scenarios in the employees_controller_spec.rb file.
@@ -1,8 +1,8 @@
1
1
  module SwaggerAutogenerate
2
2
  class Configuration
3
3
  attr_accessor :with_config, :with_multiple_examples, :with_rspec_examples, :with_example_description,
4
- :with_response_description, :swagger_environment_variable,
5
- :environment_name, :security, :swagger_config, :response_status
4
+ :with_response_description, :swagger_path_environment_variable, :generate_swagger_environment_variable,
5
+ :default_path, :environment_name, :security, :swagger_config, :response_status
6
6
 
7
7
  def initialize
8
8
  @with_config = true
@@ -11,7 +11,9 @@ 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_environment_variable = 'SWAGGER'
14
+ @swagger_path_environment_variable = 'SWAGGER_PATH'
15
+ @generate_swagger_environment_variable = 'SWAGGER_GENERATE'
16
+ @default_path = 'swagger'
15
17
  @environment_name = :test
16
18
  @security = default_security
17
19
  @swagger_config = default_swagger_config
@@ -10,6 +10,7 @@ module SwaggerAutogenerate
10
10
  @security = ::SwaggerAutogenerate.configuration.security
11
11
  @swagger_config = ::SwaggerAutogenerate.configuration.swagger_config
12
12
  @response_status = ::SwaggerAutogenerate.configuration.response_status
13
+ @default_path = ::SwaggerAutogenerate.configuration.default_path
13
14
  @request = request
14
15
  @response = response
15
16
  @@paths = {}
@@ -20,12 +21,20 @@ module SwaggerAutogenerate
20
21
  write_swagger_trace
21
22
  end
22
23
 
23
- def self.swagger_environment_variable
24
- ::SwaggerAutogenerate.configuration.swagger_environment_variable
24
+ def self.swagger_path_environment_variable
25
+ ::SwaggerAutogenerate.configuration.swagger_path_environment_variable
25
26
  end
26
27
 
27
- def swagger_environment_variable
28
- SwaggerTrace.swagger_environment_variable
28
+ def swagger_path_environment_variable
29
+ SwaggerTrace.swagger_path_environment_variable
30
+ end
31
+
32
+ def self.generate_swagger_environment_variable
33
+ ::SwaggerAutogenerate.configuration.generate_swagger_environment_variable
34
+ end
35
+
36
+ def generate_swagger_environment_variable
37
+ SwaggerTrace.generate_swagger_environment_variable
29
38
  end
30
39
 
31
40
  def self.environment_name
@@ -40,7 +49,7 @@ module SwaggerAutogenerate
40
49
 
41
50
  attr_reader :request, :response, :current_path, :yaml_file, :configuration,
42
51
  :with_config, :with_multiple_examples, :with_rspec_examples,
43
- :with_response_description, :security, :response_status, :swagger_config
52
+ :with_response_description, :security, :response_status, :swagger_config, :default_path
44
53
 
45
54
  # main methods
46
55
 
@@ -294,13 +303,19 @@ module SwaggerAutogenerate
294
303
  { 'type' => 'array', 'items' => { 'oneOf' => item_schemas.uniq } }
295
304
  end
296
305
  when String
297
- { 'type' => 'string', 'example' => json }
306
+ if is_valid_date?(json)
307
+ { 'type' => 'Date', 'example' => json.to_date.to_s }
308
+ else
309
+ { 'type' => 'string', 'example' => json.to_s }
310
+ end
298
311
  when Integer
299
312
  { 'type' => 'integer', 'example' => json }
300
313
  when Float
301
314
  { 'type' => 'number', 'example' => json }
302
315
  when TrueClass, FalseClass
303
316
  { 'type' => 'boolean', 'example' => json }
317
+ when Date, Time, DateTime
318
+ { 'type' => 'Date', 'example' => json.to_date.to_s }
304
319
  else
305
320
  { 'type' => 'string', 'example' => json.to_s }
306
321
  end
@@ -431,10 +446,14 @@ module SwaggerAutogenerate
431
446
  def swagger_location
432
447
  return @swagger_location if instance_variable_defined?(:@swagger_location)
433
448
 
434
- if ENV[swagger_environment_variable].include?('.yaml') || ENV[swagger_environment_variable].include?('.yml')
435
- @swagger_location = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
449
+ if ENV[generate_swagger_environment_variable].present?
450
+ directory_path = Rails.root.join(default_path).to_s
451
+ FileUtils.mkdir_p(directory_path) unless File.directory?(directory_path)
452
+ @swagger_location = "#{directory_path}/#{tags.first}.yaml"
453
+ elsif ENV[swagger_path_environment_variable].include?('.yaml') || ENV[swagger_path_environment_variable].include?('.yml')
454
+ @swagger_location = Rails.root.join(ENV.fetch(swagger_path_environment_variable, nil).to_s).to_s
436
455
  else
437
- directory_path = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
456
+ directory_path = Rails.root.join(ENV.fetch(swagger_path_environment_variable, nil).to_s).to_s
438
457
  FileUtils.mkdir_p(directory_path) unless File.directory?(directory_path)
439
458
  @swagger_location = "#{directory_path}/#{tags.first}.yaml"
440
459
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "1.1.2"
4
+ VERSION = "1.2.1"
5
5
  end
@@ -15,7 +15,8 @@ module SwaggerAutogenerate
15
15
  end
16
16
 
17
17
  def self.allow_swagger?
18
- ENV[SwaggerTrace.swagger_environment_variable].present? && Rails.env.send("#{SwaggerTrace.environment_name.to_s}?")
18
+ (ENV[SwaggerTrace.swagger_path_environment_variable].present? || ENV[SwaggerTrace.generate_swagger_environment_variable].present?) &&
19
+ Rails.env.send("#{SwaggerTrace.environment_name.to_s}?")
19
20
  end
20
21
  end
21
22
 
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.1.2
4
+ version: 1.2.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-08-17 00:00:00.000000000 Z
11
+ date: 2024-09-10 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