swagger_autogenerate 1.0.2 → 1.0.4
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/README.md +8 -15
- data/lib/swagger_autogenerate/{swagger_public_methods.rb → configuration.rb} +30 -1
- data/lib/swagger_autogenerate/swagger_trace.rb +28 -26
- data/lib/swagger_autogenerate/version.rb +1 -1
- data/lib/swagger_autogenerate.rb +1 -1
- data/swagger_autogenerate-1.0.2.gem +0 -0
- data/swagger_autogenerate-1.0.3.gem +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9156a7957bb459cdcea51aa4aaac537911daeefa44cb6cbceb6756666a924048
|
4
|
+
data.tar.gz: 7505182c0f2e8875ecef5a19bdc1fa63f5af1586896c5d3d9c6fcd8607f4e416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 723c04173492313fe145364f36a0237b6c0ac490d82ef6bdc57ddd9949180a51319a77af17af6cef65b037811f1771eaa92fab052353ded4751de335e22ef07d
|
7
|
+
data.tar.gz: b1f5897b9e943f27a607575867b3f1fc229888947cffa8ee9ac37e23d76ebc442d6656527216d974bbb2ea9fb8333549833c1e95f6eac538d0c9fc3f75e734d5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,28 +37,21 @@ To configure the swagger_autogenerate gem in your Rails application, follow thes
|
|
37
37
|
2) Inside the class ApplicationController block.
|
38
38
|
3) Add the following code:
|
39
39
|
```
|
40
|
-
include SwaggerAutogenerate if Rails.env.test?
|
40
|
+
include SwaggerAutogenerate if Rails.env.test?
|
41
41
|
```
|
42
|
-
in the #Example-step you will set the ENV['SWAGGER'],
|
43
|
-
|
44
|
-
By setting the ENV['SWAGGER'] environment variable, you can specify the path to the new file,
|
45
|
-
whether it's a specific file (e.g., ../myfile.yaml) or a directory (e.g., ../docs).
|
46
|
-
This flexibility ensures that the documentation can be easily integrated into your project's structure and workflow.
|
47
42
|
|
48
43
|
### Step 2 (optional)
|
49
44
|
1) Create a file called swagger_autogenerate.rb in the ./config/initializers
|
50
|
-
2) Open the ./config/initializers/
|
45
|
+
2) Open the ./config/initializers/swagger_autogenerate.rb
|
51
46
|
3) Add the following code to the swagger_autogenerate.rb
|
52
47
|
```
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
WITH_RESPONSE_DESCRIPTION = true
|
59
|
-
SWAGGER_ENVIRONMENT_VARIABLE = 'SWAGGER'
|
60
|
-
end
|
48
|
+
SwaggerAutogenerate.configure do |config|
|
49
|
+
config.with_config = true
|
50
|
+
config.with_example_description = true
|
51
|
+
config.with_multiple_examples = true
|
52
|
+
config.with_response_description = true
|
61
53
|
end
|
54
|
+
|
62
55
|
```
|
63
56
|
$ This file is optional and allows you to customize the behavior of the gem by providing additional options.
|
64
57
|
|
@@ -1,5 +1,19 @@
|
|
1
1
|
module SwaggerAutogenerate
|
2
|
-
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :with_config, :with_multiple_examples, :with_example_description,
|
4
|
+
:with_response_description, :swagger_environment_variable
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@with_config = true
|
8
|
+
@with_multiple_examples = true
|
9
|
+
@with_example_description = true
|
10
|
+
@with_response_description = true
|
11
|
+
@swagger_environment_variable = 'SWAGGER'
|
12
|
+
@security = security
|
13
|
+
@swagger_config = swagger_config
|
14
|
+
@response_status = response_status
|
15
|
+
end
|
16
|
+
|
3
17
|
def response_status
|
4
18
|
{
|
5
19
|
100 => 'The initial part of the request has been received, and the client should proceed with sending the remainder of the request',
|
@@ -46,5 +60,20 @@ module SwaggerAutogenerate
|
|
46
60
|
}
|
47
61
|
}
|
48
62
|
end
|
63
|
+
|
64
|
+
def security
|
65
|
+
[
|
66
|
+
{ 'org_slug' => [] },
|
67
|
+
{ 'locale' => [] }
|
68
|
+
]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.configuration
|
73
|
+
@configuration ||= Configuration.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.configure
|
77
|
+
yield(configuration)
|
49
78
|
end
|
50
79
|
end
|
@@ -1,31 +1,40 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'configuration'
|
2
2
|
|
3
3
|
module SwaggerAutogenerate
|
4
4
|
class SwaggerTrace
|
5
|
-
WITH_CONFIG = true
|
6
|
-
WITH_MULTIPLE_EXAMPLES = true
|
7
|
-
WITH_EXAMPLE_DESCRIPTION = true
|
8
|
-
WITH_RESPONSE_DESCRIPTION = true
|
9
|
-
SWAGGER_ENVIRONMENT_VARIABLE = 'SWAGGER'
|
10
|
-
|
11
|
-
include SwaggerPublicMethods
|
12
|
-
|
13
5
|
def initialize(request, response)
|
6
|
+
@with_config = ::SwaggerAutogenerate.configuration.with_config
|
7
|
+
@with_multiple_examples = ::SwaggerAutogenerate.configuration.with_multiple_examples
|
8
|
+
@with_example_description = ::SwaggerAutogenerate.configuration.with_example_description
|
9
|
+
@with_response_description = ::SwaggerAutogenerate.configuration.with_response_description
|
10
|
+
@security = ::SwaggerAutogenerate.configuration.security
|
11
|
+
@swagger_config = ::SwaggerAutogenerate.configuration.swagger_config
|
12
|
+
@response_status = ::SwaggerAutogenerate.configuration.response_status
|
14
13
|
@request = request
|
15
14
|
@response = response
|
16
15
|
@@paths = {}
|
17
16
|
end
|
18
17
|
|
19
18
|
def call
|
20
|
-
if ENV[
|
19
|
+
if ENV[swagger_environment_variable].present?
|
21
20
|
read_swagger_trace
|
22
21
|
write_swagger_trace
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
25
|
+
def self.swagger_environment_variable
|
26
|
+
::SwaggerAutogenerate.configuration.swagger_environment_variable
|
27
|
+
end
|
28
|
+
|
29
|
+
def swagger_environment_variable
|
30
|
+
SwaggerTrace.swagger_environment_variable
|
31
|
+
end
|
32
|
+
|
26
33
|
private
|
27
34
|
|
28
|
-
attr_reader :request, :response, :current_path, :yaml_file
|
35
|
+
attr_reader :request, :response, :current_path, :yaml_file, :configuration,
|
36
|
+
:with_config, :with_multiple_examples, :with_example_description,
|
37
|
+
:with_response_description, :security, :response_status
|
29
38
|
|
30
39
|
# main methods
|
31
40
|
|
@@ -69,7 +78,7 @@ module SwaggerAutogenerate
|
|
69
78
|
|
70
79
|
def create_file
|
71
80
|
File.open(swagger_location, 'w') do |file|
|
72
|
-
data =
|
81
|
+
data = with_config ? swagger_config : {}
|
73
82
|
data['paths'] = paths
|
74
83
|
organize_result(data['paths'])
|
75
84
|
data = data.to_hash
|
@@ -87,7 +96,7 @@ module SwaggerAutogenerate
|
|
87
96
|
|
88
97
|
return create_file if yaml_file.nil? || yaml_file['paths'].nil?
|
89
98
|
|
90
|
-
yaml_file.merge!(swagger_config) if
|
99
|
+
yaml_file.merge!(swagger_config) if with_config
|
91
100
|
|
92
101
|
apply_yaml_file_changes
|
93
102
|
organize_result(yaml_file['paths'])
|
@@ -185,7 +194,7 @@ module SwaggerAutogenerate
|
|
185
194
|
swagger_response = { 'file' => 'file/data' }
|
186
195
|
end
|
187
196
|
|
188
|
-
hash['description'] = response_description if
|
197
|
+
hash['description'] = response_description if with_response_description
|
189
198
|
hash['headers'] = {} # response.headers
|
190
199
|
hash['content'] = content_json_example(swagger_response)
|
191
200
|
|
@@ -301,13 +310,6 @@ module SwaggerAutogenerate
|
|
301
310
|
@@paths ||= {}
|
302
311
|
end
|
303
312
|
|
304
|
-
def security
|
305
|
-
[
|
306
|
-
'org_slug' => [],
|
307
|
-
'locale' => []
|
308
|
-
]
|
309
|
-
end
|
310
|
-
|
311
313
|
def controller_name
|
312
314
|
request.params['controller'].split('/').last.to_s
|
313
315
|
end
|
@@ -315,10 +317,10 @@ module SwaggerAutogenerate
|
|
315
317
|
def swagger_location
|
316
318
|
return @swagger_location if instance_variable_defined?(:@swagger_location)
|
317
319
|
|
318
|
-
if ENV[
|
319
|
-
@swagger_location = Rails.root.join(ENV.fetch(
|
320
|
+
if ENV[swagger_environment_variable].include?('.yaml') || ENV[swagger_environment_variable].include?('.yml')
|
321
|
+
@swagger_location = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
|
320
322
|
else
|
321
|
-
directory_path = Rails.root.join(ENV.fetch(
|
323
|
+
directory_path = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
|
322
324
|
FileUtils.mkdir_p(directory_path) unless File.directory?(directory_path)
|
323
325
|
@swagger_location = "#{directory_path}/#{tags.first}.yaml"
|
324
326
|
end
|
@@ -344,7 +346,7 @@ module SwaggerAutogenerate
|
|
344
346
|
}
|
345
347
|
}
|
346
348
|
}
|
347
|
-
hash['application/json']['examples']['example-0']['description'] = "payload => #{example_description}" if
|
349
|
+
hash['application/json']['examples']['example-0']['description'] = "payload => #{example_description}" if with_example_description && !example_description.empty?
|
348
350
|
|
349
351
|
hash
|
350
352
|
end
|
@@ -386,7 +388,7 @@ module SwaggerAutogenerate
|
|
386
388
|
unless old_examples.value?(current_example)
|
387
389
|
last_example = json_example_plus_one(old_examples.keys.last)
|
388
390
|
last_example ||= 'example-0'
|
389
|
-
last_example = 'example-0' unless
|
391
|
+
last_example = 'example-0' unless with_multiple_examples
|
390
392
|
yaml_file['paths'][current_path][request.method.downcase]['responses'][response.status.to_s]['content']['application/json']['examples'][last_example] = current_example
|
391
393
|
end
|
392
394
|
|
data/lib/swagger_autogenerate.rb
CHANGED
@@ -5,7 +5,7 @@ module SwaggerAutogenerate
|
|
5
5
|
require_relative 'swagger_autogenerate/swagger_trace.rb'
|
6
6
|
|
7
7
|
included do
|
8
|
-
if defined?(Rails) &&
|
8
|
+
if defined?(Rails) && ENV[SwaggerTrace.swagger_environment_variable].present?
|
9
9
|
def process_action(*args)
|
10
10
|
super
|
11
11
|
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_autogenerate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MohammedBuraiah
|
@@ -25,12 +25,14 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- lib/config/initializers/swagger_autogenerate.rb
|
27
27
|
- lib/swagger_autogenerate.rb
|
28
|
-
- lib/swagger_autogenerate/
|
28
|
+
- lib/swagger_autogenerate/configuration.rb
|
29
29
|
- lib/swagger_autogenerate/swagger_trace.rb
|
30
30
|
- lib/swagger_autogenerate/version.rb
|
31
31
|
- sig/swagger_autogenerate.rbs
|
32
32
|
- swagger_autogenerate-0.1.0.gem
|
33
33
|
- swagger_autogenerate-0.1.1.gem
|
34
|
+
- swagger_autogenerate-1.0.2.gem
|
35
|
+
- swagger_autogenerate-1.0.3.gem
|
34
36
|
- swagger_autogenerate.gemspec
|
35
37
|
homepage: https://github.com/MohammedBuraiah/swagger_autogenerate
|
36
38
|
licenses:
|