swagger_autogenerate 1.1.2 → 1.2.1
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 +4 -4
- data/CHANGELOG.md +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/swagger_autogenerate/configuration.rb +5 -3
- data/lib/swagger_autogenerate/swagger_trace.rb +28 -9
- data/lib/swagger_autogenerate/version.rb +1 -1
- data/lib/swagger_autogenerate.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f642d29cd299f7f2e7b32b7e87a89f6a6b0f037f11bd5c7bcabbfd56d34de1
|
4
|
+
data.tar.gz: 624631c39528ce4d096325dc638e2031363424124cc9922032005a44e26a2fd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2208abc4d89eac17e33f02f3c8a541ee9f68c6b1590ed93a7785ee941b9cc31e3b7fe3f74ad16689cf93639329fe85a30334651449ce7ace10699ef3ef4e1760
|
7
|
+
data.tar.gz: 8ef10a7cd712aa5114ac38395b189d84f7ec83fa9b05b64ac5ce0c8b5f7632d4cb33dea35d4cc4211c66471dae5f7ee6e15810fe7394951d1afd07ef0cd17154
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
-
|
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, :
|
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
|
-
@
|
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.
|
24
|
-
::SwaggerAutogenerate.configuration.
|
24
|
+
def self.swagger_path_environment_variable
|
25
|
+
::SwaggerAutogenerate.configuration.swagger_path_environment_variable
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
-
SwaggerTrace.
|
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
|
-
|
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[
|
435
|
-
|
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(
|
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
|
data/lib/swagger_autogenerate.rb
CHANGED
@@ -15,7 +15,8 @@ module SwaggerAutogenerate
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.allow_swagger?
|
18
|
-
ENV[SwaggerTrace.
|
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
|
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-
|
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
|