swagger_autogenerate 1.0.2 → 1.0.3

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: 0b52220aecae46c5818f0640a1ca979f59d38fba0720e2d5a35685fbb6c06bbd
4
- data.tar.gz: 995666a3bd4de256824656420231be0c38d564aa236a6bfca10659d1474908ff
3
+ metadata.gz: b3f7b9b67269b270dff6c7ec738c7b4ef8cafa149494c41e74671b0a193bc9d1
4
+ data.tar.gz: dadf1b845cb96e70f375a245d606b0b4a487b6a945e8ea2508bb102d9e0fbca3
5
5
  SHA512:
6
- metadata.gz: c966988c943c3d108a30fa1abc38cef2295679e8f02b2f1dd302a64eedca45d5c97f37ff2c30f7ca35c516b92fa797ea6a0670a25ef1c587cef97ab22433f569
7
- data.tar.gz: a6e6c285bdad27980d524f221c8ae5204e06a3ed222de805c2c5a6ebcda637c5e312712f395aa9247bae4002182fad5d264056c0b837a9a38c7ff5dd0d105d1c
6
+ metadata.gz: 261b31e5e7c4d02f72c3a60c0262d7034210685e690d66babc899c006886bcf4887380e8d0e58904eafa433552fc56f7ee4ac0ffe7c58c2654c2c9c216c2a3ac
7
+ data.tar.gz: 28034a707e1568ecf04a668427b186729ea92a9709e847d4db6a29d59a02fd866fd394ed6f10e3fa26e34b51d2438309fa4047f0acbf6b86a5e36cdb9aad7821
data/CHANGELOG.md CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  ## [0.1.1] - 2024-05-27
4
4
  ## [1.0.2] - 2024-05-31
5
+ ## [1.0.3] - 2024-05-31
6
+
5
7
  - Initial release
@@ -1,31 +1,40 @@
1
1
  require_relative 'swagger_public_methods'
2
+ require_relative 'configuration'
2
3
 
3
4
  module SwaggerAutogenerate
4
5
  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
6
  include SwaggerPublicMethods
12
7
 
13
8
  def initialize(request, response)
9
+ @with_config = ::SwaggerAutogenerate.configuration.with_config
10
+ @with_multiple_examples = ::SwaggerAutogenerate.configuration.with_multiple_examples
11
+ @with_example_description = ::SwaggerAutogenerate.configuration.with_example_description
12
+ @with_response_description = ::SwaggerAutogenerate.configuration.with_response_description
14
13
  @request = request
15
14
  @response = response
16
15
  @@paths = {}
17
16
  end
18
17
 
19
18
  def call
20
- if ENV[SWAGGER_ENVIRONMENT_VARIABLE].present?
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
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 = WITH_CONFIG ? swagger_config : {}
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 WITH_CONFIG
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 WITH_RESPONSE_DESCRIPTION
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
 
@@ -315,10 +324,10 @@ module SwaggerAutogenerate
315
324
  def swagger_location
316
325
  return @swagger_location if instance_variable_defined?(:@swagger_location)
317
326
 
318
- if ENV[SWAGGER_ENVIRONMENT_VARIABLE].include?('.yaml') || ENV[SWAGGER_ENVIRONMENT_VARIABLE].include?('.yml')
319
- @swagger_location = Rails.root.join(ENV.fetch(SWAGGER_ENVIRONMENT_VARIABLE, nil).to_s).to_s
327
+ if ENV[swagger_environment_variable].include?('.yaml') || ENV[swagger_environment_variable].include?('.yml')
328
+ @swagger_location = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
320
329
  else
321
- directory_path = Rails.root.join(ENV.fetch(SWAGGER_ENVIRONMENT_VARIABLE, nil).to_s).to_s
330
+ directory_path = Rails.root.join(ENV.fetch(swagger_environment_variable, nil).to_s).to_s
322
331
  FileUtils.mkdir_p(directory_path) unless File.directory?(directory_path)
323
332
  @swagger_location = "#{directory_path}/#{tags.first}.yaml"
324
333
  end
@@ -344,7 +353,7 @@ module SwaggerAutogenerate
344
353
  }
345
354
  }
346
355
  }
347
- hash['application/json']['examples']['example-0']['description'] = "payload => #{example_description}" if WITH_EXAMPLE_DESCRIPTION && !example_description.empty?
356
+ hash['application/json']['examples']['example-0']['description'] = "payload => #{example_description}" if with_example_description && !example_description.empty?
348
357
 
349
358
  hash
350
359
  end
@@ -386,7 +395,7 @@ module SwaggerAutogenerate
386
395
  unless old_examples.value?(current_example)
387
396
  last_example = json_example_plus_one(old_examples.keys.last)
388
397
  last_example ||= 'example-0'
389
- last_example = 'example-0' unless WITH_MULTIPLE_EXAMPLES
398
+ last_example = 'example-0' unless with_multiple_examples
390
399
  yaml_file['paths'][current_path][request.method.downcase]['responses'][response.status.to_s]['content']['application/json']['examples'][last_example] = current_example
391
400
  end
392
401
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwaggerAutogenerate
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
@@ -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) && Rails.env.test? && ENV[SwaggerTrace::SWAGGER_ENVIRONMENT_VARIABLE].present?
8
+ if defined?(Rails) && ENV[SwaggerTrace.swagger_environment_variable].present?
9
9
  def process_action(*args)
10
10
  super
11
11
 
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MohammedBuraiah
@@ -31,6 +31,7 @@ files:
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
34
35
  - swagger_autogenerate.gemspec
35
36
  homepage: https://github.com/MohammedBuraiah/swagger_autogenerate
36
37
  licenses: