Class: Serega::SeregaPlugins::OpenAPI::OpenAPIConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/openapi/lib/openapi_config.rb

Overview

OpenAPI plugin config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serializer_class, opts) ⇒ OpenAPIConfig

Returns a new instance of OpenAPIConfig.



12
13
14
15
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 12

def initialize(serializer_class, opts)
  @serializer_class = serializer_class
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



10
11
12
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 10

def opts
  @opts
end

#serializer_classObject (readonly)

Returns the value of attribute serializer_class.



10
11
12
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 10

def serializer_class
  @serializer_class
end

Instance Method Details

#properties(new_properties = FROZEN_EMPTY_HASH) ⇒ Hash

Saves new properties

Parameters:

  • new_properties (Hash) (defaults to: FROZEN_EMPTY_HASH)

    new properties

Returns:

  • (Hash)

    OpenAPI properties



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 24

def properties(new_properties = FROZEN_EMPTY_HASH)
  properties = opts[:properties]
  return properties if new_properties.empty?

  new_properties = SeregaUtils::EnumDeepDup.call(new_properties)
  symbolize_keys!(new_properties)

  new_properties.each do |attribute_name, new_attribute_properties|
    check_attribute_exists(attribute_name)
    check_properties_is_a_hash(attribute_name, new_attribute_properties)

    properties[attribute_name] = symbolize_keys!(new_attribute_properties)
  end
end

#ref_builder#call

Returns builder of ‘$ref` attribute.

Returns:

  • (#call)

    builder of ‘$ref` attribute



42
43
44
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 42

def ref_builder
  opts[:ref_builder]
end

#ref_builder=(builder) ⇒ Object

Sets new $ref option builder

Parameters:

  • builder (#call)

    Callable object that accepts serializer_class and constructs $ref option string

Returns:

  • Specified new builder

Raises:



53
54
55
56
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 53

def ref_builder=(builder)
  raise SeregaError, "ref_builder must respond to #call" unless builder.respond_to?(:call)
  opts[:ref_builder] = builder
end

#schema_name_builder#call

Returns builder of schema name.

Returns:

  • (#call)

    builder of schema name



61
62
63
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 61

def schema_name_builder
  opts[:schema_name_builder]
end

#schema_name_builder=(builder) ⇒ Object

Sets new schema_name_builder

Parameters:

  • builder (#call)

    Callable object that accepts serializer_class and constructs schema name to use in schemas list and in $ref option

Returns:

  • Specified new builder

Raises:



73
74
75
76
# File 'lib/serega/plugins/openapi/lib/openapi_config.rb', line 73

def schema_name_builder=(builder)
  raise SeregaError, "schema_name_builder must respond to #call" unless builder.respond_to?(:call)
  opts[:schema_name_builder] = builder
end