swagger_docs_generator 0.2.0 → 0.3.0.pre.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/swagger_docs_generator/configuration/configuration.rb +14 -5
  3. data/lib/swagger_docs_generator/configuration/configuration_info.rb +4 -0
  4. data/lib/swagger_docs_generator/generator.rb +30 -47
  5. data/lib/swagger_docs_generator/info.rb +1 -1
  6. data/lib/swagger_docs_generator/metadata/controller.rb +3 -31
  7. data/lib/swagger_docs_generator/metadata/definition.rb +19 -10
  8. data/lib/swagger_docs_generator/metadata/jsons.rb +32 -0
  9. data/lib/swagger_docs_generator/metadata/metadata.rb +11 -1
  10. data/lib/swagger_docs_generator/parser/action.rb +15 -7
  11. data/lib/swagger_docs_generator/parser/actions/parameters/body.rb +31 -0
  12. data/lib/swagger_docs_generator/parser/actions/parameters/form.rb +20 -0
  13. data/lib/swagger_docs_generator/parser/actions/parameters/header.rb +27 -0
  14. data/lib/swagger_docs_generator/parser/actions/parameters/path.rb +27 -0
  15. data/lib/swagger_docs_generator/parser/actions/parameters/query.rb +28 -0
  16. data/lib/swagger_docs_generator/parser/actions/parameters.rb +31 -57
  17. data/lib/swagger_docs_generator/parser/actions/response.rb +3 -59
  18. data/lib/swagger_docs_generator/parser/actions/schema.rb +4 -0
  19. data/lib/swagger_docs_generator/parser/controller.rb +7 -7
  20. data/lib/swagger_docs_generator/parser/definition.rb +9 -7
  21. data/lib/swagger_docs_generator/parser/model.rb +0 -3
  22. data/lib/swagger_docs_generator/parser/parser.rb +12 -11
  23. data/lib/swagger_docs_generator.rb +6 -0
  24. data/lib/tasks/swagger.rake +6 -5
  25. data/spec/spec_helper.rb +1 -0
  26. data/spec/support/examples/parameters.rb +154 -0
  27. data/spec/swagger_docs_generator/configuration/configuration_customize_spec.rb +6 -6
  28. data/spec/swagger_docs_generator/configuration/configuration_default_spec.rb +8 -3
  29. data/spec/swagger_docs_generator/parser/parameters/param_body_spec.rb +62 -0
  30. data/spec/swagger_docs_generator/parser/parameters/param_form_spec.rb +52 -0
  31. data/spec/swagger_docs_generator/parser/parameters/param_header_spec.rb +62 -0
  32. data/spec/swagger_docs_generator/parser/parameters/param_path_spec.rb +62 -0
  33. data/spec/swagger_docs_generator/parser/parameters/param_query_spec.rb +62 -0
  34. metadata +18 -9
  35. data/lib/swagger_docs_generator/metadata/path.rb +0 -24
  36. data/lib/swagger_docs_generator/metadata/tag.rb +0 -24
  37. data/spec/swagger_docs_generator/metadata/controller_spec.rb +0 -18
  38. /data/lib/swagger_docs_generator/{parser/models → models}/active_record.rb +0 -0
  39. /data/lib/swagger_docs_generator/{parser/models → models}/mongo.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46d2c397e8fe3a149b506e49911b3d683d1a79d9
4
- data.tar.gz: be8306cee8bc3607fbb48b064150234aa5b4fad3
3
+ metadata.gz: b051b9f9b3126e0dfde300b94560f20a5960cbfd
4
+ data.tar.gz: 9cb75ad8328e271617bbb2a0bfa5f5b1b5971588
5
5
  SHA512:
6
- metadata.gz: c4eb8d811e9a3c2f511219a8fa8dd064f12671988301b1f066e12fdfb11886d4a0b79e086ae0c3c4a9294c0f85ce27e2f44ca59acd24b35d1f7c9473cabb9dc1
7
- data.tar.gz: 4976b9e2392805348b93bf5bed8f06d1bdba469ccf6c017ad7612adb6de0f3c757d67bba6c0c7de7f9920810ab0639f47b7383bdd7b3ba793273e5802147cc22
6
+ metadata.gz: 2f8aef3acd286a908de1e73a170f9f67c8dd9ef2f401d17c77580014bf84a28ff0777181202437064b547c1c19271ad3671c2f014055b9c8261023954b5e579d
7
+ data.tar.gz: d7c2943197818158acf799cfd96e11cd0feeff52254171a72d5fde516c70003cd18f2177c4602bc6cf55037eccdc751b30b93d70ca2a4ad4b274d9abb43a7f5b
@@ -18,18 +18,15 @@ module SwaggerDocsGenerator
18
18
  # @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
19
19
  class Configuration
20
20
  # Accessors with default value
21
- attr_accessor :swagger, :cleanning, :base_controller, :base_path
21
+ attr_accessor :swagger, :cleanning, :base_path
22
22
 
23
23
  # Accessors without default value
24
24
  attr_accessor :schemes, :consumes, :produces, :host, :external_docs,
25
- :security, :definitions
26
- # :external_docs, :security_definitions, :security
27
- # :paths, :tags, :host
25
+ :security, :definitions, :doc_class, :doc_folder
28
26
 
29
27
  # Initalize default value (and requried) for json swagger file
30
28
  def initialize
31
29
  @swagger = '2.0'
32
- @base_controller = ''
33
30
  @base_path = '/'
34
31
  @cleanning = true
35
32
  end
@@ -43,5 +40,17 @@ module SwaggerDocsGenerator
43
40
  def config
44
41
  @config ||= Configuration.new
45
42
  end
43
+
44
+ def file_base
45
+ File.join(@config.doc_folder, @config.doc_class)
46
+ end
47
+
48
+ def file_docs
49
+ Dir[File.join(@config.doc_folder, '*.rb')]
50
+ end
51
+
52
+ def temporary_folder
53
+ Rails.root.join('tmp', SwaggerDocsGenerator::GEM)
54
+ end
46
55
  end
47
56
  end
@@ -26,5 +26,9 @@ module SwaggerDocsGenerator
26
26
  def info
27
27
  @info ||= ConfigurationInfo.new
28
28
  end
29
+
30
+ def version_ruby
31
+ @info.version.humanize
32
+ end
29
33
  end
30
34
  end
@@ -11,30 +11,44 @@ module SwaggerDocsGenerator
11
11
  attr_reader :swagger_file
12
12
 
13
13
  def initialize
14
- @hash = {}
15
14
  @file = 'swagger.json'
16
- @swagger_file = File.join(path, @file)
17
- @version = File.join(path, SwaggerDocsGenerator.configure_info.version)
18
- create_version_folder
15
+ @swagger_file = File.join(Dir.pwd, 'public', @file)
16
+ @temp = FileUtils.mkdir_p(SwaggerDocsGenerator.temporary_folder)
17
+ end
18
+
19
+ # Import documentation file
20
+ def import_documentations
21
+ require SwaggerDocsGenerator.file_base
22
+ SwaggerDocsGenerator.file_docs.each { |rb| require rb }
19
23
  end
20
24
 
21
25
  # Open or create a swagger.json file
22
26
  def generate_swagger_file
23
27
  delete_file_before
24
- File.open(@swagger_file, 'a+') { |file| file.puts agregate_metadata }
28
+ File.open(@swagger_file, 'a+') do |file|
29
+ # file.puts write_in_swagger_file.to_json
30
+ file.puts JSON.pretty_generate write_in_swagger_file
31
+ end
25
32
  end
26
33
 
27
34
  # Delete files temporary
28
35
  def delete_temporary_files
29
- FileUtils.remove_dir(@version) if SwaggerDocsGenerator.configure.cleanning
36
+ FileUtils.rm_rf(@temp[0]) if SwaggerDocsGenerator.configure.cleanning
30
37
  end
31
38
 
32
39
  def info_swagger_file
33
- create_info_text(@swagger_file)
40
+ "#{prefix_info} #{@swagger_file}"
34
41
  end
35
42
 
36
43
  def info_swagger_temporary
37
- create_info_text(@version)
44
+ "#{prefix_info} #{SwaggerDocsGenerator.temporary_folder}"
45
+ end
46
+
47
+ def info_controller_parser
48
+ klasses = "#{SwaggerDocsGenerator.version_ruby}::BaseDoc".constantize
49
+ klasses.subclasses.each do |controller|
50
+ yield("#{prefix_info} [Controller] #{controller::CONTROLLER}")
51
+ end
38
52
  end
39
53
 
40
54
  private
@@ -45,50 +59,19 @@ module SwaggerDocsGenerator
45
59
  '->'
46
60
  end
47
61
 
48
- def create_info_text(message)
49
- "#{prefix_info} #{message}"
50
- end
51
-
52
- # :reek:UtilityFunction
53
- def path
54
- File.join(Dir.pwd, '/public')
55
- end
56
-
57
62
  def delete_file_before
58
63
  File.delete(@swagger_file) if File.exist?(@swagger_file)
59
64
  end
60
65
 
61
- def create_version_folder
62
- FileUtils.mkdir_p(@version) unless File.directory?(@version)
63
- end
64
-
66
+ # :reek:UtilityFunction
65
67
  def write_in_swagger_file
66
- write_in_swagger_file_configurations
67
- write_in_swagger_file_controllers
68
- write_in_swagger_file_models
69
- end
70
-
71
- def write_in_swagger_file_configurations
72
- @hash.merge!(MetadataConfiguration.new.construct_swagger_file)
73
- @hash.merge!(MetadataInfo.new.construct_swagger_file)
74
- end
75
-
76
- def write_in_swagger_file_controllers
77
- @hash.merge!(MetadataPath.new.construct_swagger_file)
78
- @hash.merge!(MetadataTag.new.construct_swagger_file)
79
- end
80
-
81
- def write_in_swagger_file_models
82
- @hash.merge!(MetadataDefinition.new.construct_swagger_file)
83
- end
84
-
85
- def agregate_metadata
86
- case defined?(Rails) && Rails.env
87
- when 'production' || 'test'
88
- write_in_swagger_file.to_json
89
- else
90
- JSON.pretty_generate write_in_swagger_file
91
- end
68
+ # Parse option to this gem
69
+ hash = MetadataConfiguration.new.construct_swagger_file
70
+ hash.merge!(MetadataInfo.new.construct_swagger_file)
71
+ # Parse temporary file (controller - actions)
72
+ hash.merge!(MetadataJsons.new.construct_swagger_file)
73
+ # Parse Model
74
+ hash.merge!(MetadataDefinition.new.construct_swagger_file)
92
75
  end
93
76
  end
94
77
  end
@@ -5,7 +5,7 @@ module SwaggerDocsGenerator
5
5
  # Name to gem
6
6
  GEM = 'swagger_docs_generator'
7
7
  # Version to gem
8
- VERSION = '0.2.0'
8
+ VERSION = '0.3.0'
9
9
  # Authors contributed to gem
10
10
  AUTHORS = ['VAILLANT Jeremy'].freeze
11
11
  # Email to ahuthors
@@ -6,40 +6,12 @@ module SwaggerDocsGenerator
6
6
  # @abstract
7
7
  # Abstract class for metadata provide to controlloer in Rails application
8
8
  class MetadataController < Metadata
9
- def initialize
10
- @file_path = File.join(Dir.pwd, 'public',
11
- SwaggerDocsGenerator.configure_info.version)
12
- @conf = SwaggerDocsGenerator.configure.base_controller
13
- @controllers = case @conf
14
- when String then string_controller
15
- when Array then array_controller
16
- when Class then class_controller
17
- end
18
- end
19
-
20
9
  private
21
10
 
22
- attr_accessor :controllers, :file_path
23
-
24
- # :reek:UtilityFunction
25
- def string_controller
26
- ApplicationController.subclasses
27
- end
28
-
29
- def array_controller
30
- array = []
31
- @conf.map { |controller| array |= search_subclasses(controller) }
32
- array
33
- end
34
-
35
- def class_controller
36
- search_subclasses(@conf.subclasses)
37
- end
38
-
39
11
  # :reek:UtilityFunction
40
- def search_subclasses(controller)
41
- ctrl = controller.subclasses
42
- ctrl.count.zero? ? [controller] : ctrl
12
+ def temporary_file(controller)
13
+ File.join(SwaggerDocsGenerator.temporary_folder,
14
+ "#{controller.controller_name}.json")
43
15
  end
44
16
  end
45
17
  end
@@ -8,7 +8,7 @@ module SwaggerDocsGenerator
8
8
  # Generate metadata for block definition in swagger file
9
9
  #
10
10
  # @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitions-object
11
- class MetadataDefinition < MetadataController
11
+ class MetadataDefinition < Metadata
12
12
  def initialize
13
13
  super
14
14
  @model = nil
@@ -24,20 +24,19 @@ module SwaggerDocsGenerator
24
24
  find_models.merge!(find_in_controller)
25
25
  end
26
26
 
27
- # :reek:NilCheck
28
27
  def find_models
29
28
  hash = {}
30
- controllers.each do |controller|
31
- data = each_controller(controller)
32
- hash.merge!(data) unless data.nil?
29
+ all_class_documentation.each do |controller|
30
+ data = each_controller(controller::CONTROLLER)
31
+ hash.merge!(data) unless data.empty?
33
32
  end
34
33
  hash
35
34
  end
36
35
 
37
36
  def find_in_controller
38
37
  hash = {}
39
- controllers.each do |controller|
40
- file = File.join(file_path, "#{controller.controller_name}.json")
38
+ all_class_documentation.each do |controller|
39
+ file = temporary_file(controller::CONTROLLER)
41
40
  hash.merge!(read_file(file)) if File.exist?(file)
42
41
  end
43
42
  hash
@@ -49,11 +48,15 @@ module SwaggerDocsGenerator
49
48
  json.key?('definitions') ? json['definitions'] : {}
50
49
  end
51
50
 
52
- def each_controller(controller)
53
- @model = Model.new(controller)
51
+ def each_controller(model_name)
52
+ read_model(model_name) || {}
53
+ end
54
+
55
+ def read_model(model_name)
56
+ @model = Model.new(model_name)
54
57
  contruct_hash
55
58
  rescue NameError => message
56
- puts "Error model name : #{message.name}"
59
+ puts "-> [Model] #{message.name} -- doesn't exist"
57
60
  end
58
61
 
59
62
  def contruct_hash
@@ -64,5 +67,11 @@ module SwaggerDocsGenerator
64
67
  }
65
68
  }
66
69
  end
70
+
71
+ # :reek:UtilityFunction
72
+ def temporary_file(controller)
73
+ File.join(SwaggerDocsGenerator.temporary_folder,
74
+ "#{controller.controller_name}.json")
75
+ end
67
76
  end
68
77
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SwaggerDocsGenerator
4
+ # Parse temporary json files
5
+ class MetadataJsons
6
+ def initialize
7
+ @paths = { paths: {} }
8
+ @tags_array = []
9
+ end
10
+
11
+ def construct_swagger_file
12
+ hash = {}
13
+ files_tmp.each do |file|
14
+ @paths[:paths].merge!(read_part_json(file, 'paths'))
15
+ @tags_array.push read_part_json(file, 'tags')
16
+ end
17
+ hash.merge(@paths).merge(tags: @tags_array)
18
+ end
19
+
20
+ private
21
+
22
+ # :reek:UtilityFunction
23
+ def files_tmp
24
+ Dir[Rails.root.join(SwaggerDocsGenerator.temporary_folder, '*.json')]
25
+ end
26
+
27
+ # :reek:UtilityFunction
28
+ def read_part_json(file, key)
29
+ JSON.parse(File.read(file))[key]
30
+ end
31
+ end
32
+ end
@@ -24,10 +24,20 @@ module SwaggerDocsGenerator
24
24
 
25
25
  private
26
26
 
27
+ # :reek:UtilityFunction
28
+ def base_class_documentation
29
+ "#{SwaggerDocsGenerator.version_ruby}::BaseDoc".constantize
30
+ end
31
+
32
+ def all_class_documentation
33
+ base_class_documentation.subclasses
34
+ end
35
+
27
36
  attr_reader :config
28
37
  end
29
38
  end
30
39
 
31
40
  require 'swagger_docs_generator/metadata/configuration'
32
41
  require 'swagger_docs_generator/metadata/info'
33
- require 'swagger_docs_generator/metadata/controller'
42
+ require 'swagger_docs_generator/metadata/jsons'
43
+ require 'swagger_docs_generator/metadata/definition'
@@ -2,12 +2,19 @@
2
2
 
3
3
  require 'swagger_docs_generator/parser/actions/actions'
4
4
 
5
+ # :reek:UtilityFunction
6
+ # :reek:InstanceVariableAssumption
7
+ # :reek:TooManyInstanceVariables
8
+ # :reek:TooManyStatements
9
+
10
+ # rubocop:disable Metrics/AbcSize
11
+ # rubocop:disable Metrics/CyclomaticComplexity
5
12
  module SwaggerDocsGenerator
6
13
  # # Parse action in controller classe to Rails application. It's adding
7
14
  # paths to swagger docs file.
8
15
  class ParserAction < Parser
9
16
  def initialize(action, &block)
10
- super(binding.of_callers[1].klass::CONTROLLER)
17
+ super(binding.of_callers[1].klass)
11
18
  @action = action
12
19
  @parameter = []
13
20
  @response = {}
@@ -15,9 +22,8 @@ module SwaggerDocsGenerator
15
22
  end
16
23
 
17
24
  def adding_path
18
- json = JSON.parse(File.read(controller_file))
19
- File.open(controller_file, 'w') do |file|
20
- # json['paths'].merge!(construct_routes(json))
25
+ json = JSON.parse(File.read(temporary_file))
26
+ File.open(temporary_file, 'w') do |file|
21
27
  path_exist(json, construct_routes)
22
28
  file.puts(JSON.pretty_generate(json))
23
29
  end
@@ -54,7 +60,7 @@ module SwaggerDocsGenerator
54
60
  element.merge!(deprecated: @deprecated) if @deprecated.present?
55
61
  element.merge!(produces: @produce) if @produce.present?
56
62
  element.merge!(responses: @response)
57
- element.merge!(tags: @tag || default_tag)
63
+ element.merge!(tags: write_tag)
58
64
  end
59
65
 
60
66
  def route
@@ -65,8 +71,8 @@ module SwaggerDocsGenerator
65
71
  { @route => { @verb => construct_path }.merge!(patch: construct_path) }
66
72
  end
67
73
 
68
- def default_tag
69
- [controller_name]
74
+ def write_tag
75
+ [@tag_name]
70
76
  end
71
77
 
72
78
  def summary(text)
@@ -100,3 +106,5 @@ module SwaggerDocsGenerator
100
106
  end
101
107
  end
102
108
  end
109
+ # rubocop:enable Metrics/AbcSize
110
+ # rubocop:enable Metrics/CyclomaticComplexity
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:InstanceVariableAssumption
4
+ # :reek:NilCheck
5
+
6
+ module SwaggerDocsGenerator
7
+ module Actions
8
+ # Write parameter type :body
9
+ class Body < Parameter
10
+ def to_hash
11
+ {
12
+ in: :body,
13
+ name: @name.nil? ? 'body' : @name,
14
+ description: @description.nil? ? '' : @description,
15
+ required: @required.nil? ? true : @required,
16
+ schema: { '$ref': @schema.nil? ? '' : format_name }
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def schema(text)
23
+ @schema = text
24
+ end
25
+
26
+ def format_name
27
+ "#/definitions/#{@schema.tr(' ', '_').camelize}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:InstanceVariableAssumption
4
+ # :reek:NilCheck
5
+
6
+ module SwaggerDocsGenerator
7
+ module Actions
8
+ # Write parameter type :form
9
+ class Form < Parameter
10
+ def to_hash
11
+ {
12
+ in: :form,
13
+ name: @name.nil? ? 'form' : @name,
14
+ description: @description.nil? ? '' : @description,
15
+ required: @required.nil? ? true : @required
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:InstanceVariableAssumption
4
+ # :reek:NilCheck
5
+
6
+ module SwaggerDocsGenerator
7
+ module Actions
8
+ # Write parameter type :header
9
+ class Header < Parameter
10
+ def to_hash
11
+ {
12
+ in: :header,
13
+ name: @name.nil? ? 'header' : @name,
14
+ description: @description.nil? ? '' : @description,
15
+ required: @required.nil? ? true : @required,
16
+ type: @type.nil? ? '' : @type
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def type(text)
23
+ @type = text
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:InstanceVariableAssumption
4
+ # :reek:NilCheck
5
+
6
+ module SwaggerDocsGenerator
7
+ module Actions
8
+ # Write parameter type :path
9
+ class Path < Parameter
10
+ def to_hash
11
+ {
12
+ in: :path,
13
+ name: @name.nil? ? 'path' : @name,
14
+ description: @description.nil? ? '' : @description,
15
+ required: @required.nil? ? true : @required,
16
+ type: @type.nil? ? '' : @type
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def type(text)
23
+ @type = text
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:InstanceVariableAssumption
4
+ # :reek:NilCheck
5
+
6
+ module SwaggerDocsGenerator
7
+ module Actions
8
+ # Write parameter type :query
9
+ class Query < Parameter
10
+ def to_hash
11
+ {
12
+ in: :query,
13
+ name: @name.nil? ? 'query' : @name,
14
+ description: @description.nil? ? '' : @description,
15
+ required: @required.nil? ? true : @required,
16
+ type: @type.nil? ? 'array' : @type,
17
+ items: { type: 'string' }
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def type(text)
24
+ @type = text
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # :reek:UtilityFunction
4
+ # :reek:InstanceVariableAssumption
5
+ # :reek:TooManyInstanceVariables
6
+ # :reek:DuplicateMethodCall
7
+ # :reek:TooManyStatements
8
+
4
9
  module SwaggerDocsGenerator
5
10
  module Actions
6
11
  # # Test :parameters
@@ -8,88 +13,57 @@ module SwaggerDocsGenerator
8
13
  # Complete parameters field for action
9
14
  class Parameter
10
15
  def initialize(&block)
16
+ @param = nil
11
17
  instance_eval(&block) if block_given?
12
18
  end
13
19
 
14
20
  def to_hash
15
- case @in
16
- when :path then path_hash
17
- when :header then header_hash
18
- when :query then query_hash
19
- when :body then body_hash
20
- when :form then form_hash
21
- end
21
+ @param.to_hash
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def path(data)
27
- @in = :path
28
- @name = data[0]
29
- @description = data[1]
30
- @type = data[2]
31
- @required = data[3]
26
+ def name(text)
27
+ @name = text
32
28
  end
33
29
 
34
- def path_hash
35
- {
36
- name: @name,
37
- in: @in,
38
- description: @description,
39
- required: @required,
40
- type: @type
41
- }
30
+ def description(text)
31
+ @description = text
42
32
  end
43
33
 
44
- def header(data)
45
- @in = :header
46
- @name = data[0]
47
- @description = data[1]
48
- @type = data[2]
49
- @required = data[3]
50
- @enum = data[4]
34
+ def required(text)
35
+ @required = text
51
36
  end
52
37
 
53
- def header_hash
54
- {
55
- name: @name,
56
- in: @in,
57
- description: @description,
58
- required: @required,
59
- type: @type,
60
- enum: @enum
61
- }
38
+ def body(&block)
39
+ @param = Body.new(&block)
62
40
  end
63
41
 
64
- def query(data)
65
- @in = :query
42
+ def form(&block)
43
+ @param = Form.new(&block)
66
44
  end
67
45
 
68
- alias query_hash path_hash
69
-
70
- def body(data)
71
- @in = :body
72
- @name = data[1]
73
- @description = data[0]
74
- @definition = data[1]
46
+ def header(&block)
47
+ @param = Header.new(&block)
75
48
  end
76
49
 
77
- def body_hash
78
- {
79
- name: @name,
80
- in: @in,
81
- description: @description,
82
- required: true,
83
- schema: { type: :object, items: { '$ref': @definition.tr(' ', '_').camelize } }
84
- }
50
+ def path(&block)
51
+ @param = Path.new(&block)
85
52
  end
86
53
 
87
- def form(data)
88
- @in = :form
54
+ def query(&block)
55
+ @param = Query.new(&block)
89
56
  end
90
57
 
91
- def form_hash
58
+ def test_value(value, default)
59
+ value.empty? ? default : value
92
60
  end
93
61
  end
94
62
  end
95
63
  end
64
+
65
+ require 'swagger_docs_generator/parser/actions/parameters/body'
66
+ require 'swagger_docs_generator/parser/actions/parameters/form'
67
+ require 'swagger_docs_generator/parser/actions/parameters/header'
68
+ require 'swagger_docs_generator/parser/actions/parameters/path'
69
+ require 'swagger_docs_generator/parser/actions/parameters/query'