Class: Apipie::Generator::Swagger::ParamDescription::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/param_description/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(param_description, in_schema:, controller_method:) ⇒ Builder

Returns a new instance of Builder.

Parameters:



5
6
7
8
9
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 5

def initialize(param_description, in_schema:, controller_method:)
  @param_description = param_description
  @in_schema = in_schema
  @controller_method = controller_method
end

Instance Method Details

#to_swaggerHash

Returns:

  • (Hash)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 47

def to_swagger
  definition = {}

  definition.merge!(@name.to_hash) if @name.present?
  definition.merge!(@type.to_hash) if @type.present?
  definition.merge!(@in.to_hash) if @in.present?

  definition.merge!(for_default)
  definition.merge!(for_required)
  definition.merge!(@description.to_hash) if @description.present?

  warn_optional_without_default_value(definition)

  definition
end

#with_description(language:) ⇒ Object

Parameters:

  • language (String)


20
21
22
23
24
25
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 20

def with_description(language:)
  @description = Apipie::Generator::Swagger::ParamDescription::Description.
    new(@param_description, language: language)

  self
end

#with_in(http_method:, default_in_value: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 35

def with_in(http_method:, default_in_value: nil)
  @in = Apipie::Generator::Swagger::ParamDescription::In.new(
    @param_description,
    in_schema: @in_schema,
    default_in_value: default_in_value,
    http_method: http_method
  )

  self
end

#with_name(prefix: nil) ⇒ Object

Parameters:

  • prefix (String, nil) (defaults to: nil)


12
13
14
15
16
17
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 12

def with_name(prefix: nil)
  @name = Apipie::Generator::Swagger::ParamDescription::Name.
    new(@param_description, prefixed_by: prefix)

  self
end

#with_type(with_null:) ⇒ Object

Parameters:

  • with_null (TrueClass, FalseClass)


28
29
30
31
32
33
# File 'lib/apipie/generator/swagger/param_description/builder.rb', line 28

def with_type(with_null:)
  @type = Apipie::Generator::Swagger::ParamDescription::Type.
    new(@param_description, with_null: with_null, controller_method: @controller_method)

  self
end