Module: OpenapiRuby::Components::Base::ClassMethods

Defined in:
lib/openapi_ruby/components/base.rb

Instance Method Summary collapse

Instance Method Details

#component_nameObject



61
62
63
# File 'lib/openapi_ruby/components/base.rb', line 61

def component_name
  (name || "Anonymous").demodulize
end

#component_scopes(*scopes) ⇒ Object



49
50
51
52
53
54
# File 'lib/openapi_ruby/components/base.rb', line 49

def component_scopes(*scopes)
  Registry.instance.unregister(self)
  self._component_scopes = scopes.flatten.map(&:to_sym)
  self._component_scopes_explicitly_set = true
  Registry.instance.register(self)
end

#component_type(type) ⇒ Object



43
44
45
46
47
# File 'lib/openapi_ruby/components/base.rb', line 43

def component_type(type)
  Registry.instance.unregister(self)
  self._component_type = type.to_sym
  Registry.instance.register(self)
end

#inherited(subclass) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/openapi_ruby/components/base.rb', line 19

def inherited(subclass)
  super
  subclass._schema_definition = _schema_definition.deep_dup
  subclass._schema_hidden = false
  subclass._skip_key_transformation = _skip_key_transformation
  subclass._component_type = _component_type
  subclass._component_scopes = _component_scopes.dup
  subclass._component_scopes_explicitly_set = _component_scopes_explicitly_set
  Registry.instance.register(subclass) if subclass.name
end

#permitted_paramsObject



85
86
87
88
89
90
# File 'lib/openapi_ruby/components/base.rb', line 85

def permitted_params
  properties = _schema_definition["properties"]
  return [] unless properties

  build_permit_list(properties)
end

#registry_keyObject



65
66
67
68
69
70
71
# File 'lib/openapi_ruby/components/base.rb', line 65

def registry_key
  if _component_scopes.empty?
    component_name
  else
    "#{_component_scopes.sort.join("_")}:#{component_name}"
  end
end

#schema(definition = nil) ⇒ Object



30
31
32
33
# File 'lib/openapi_ruby/components/base.rb', line 30

def schema(definition = nil)
  self._schema_definition = _schema_definition.deep_merge(deep_stringify(definition)) if definition
  _schema_definition
end

#schema_hidden(value = true) ⇒ Object



35
36
37
# File 'lib/openapi_ruby/components/base.rb', line 35

def schema_hidden(value = true)
  self._schema_hidden = value
end

#shared_componentObject



56
57
58
59
# File 'lib/openapi_ruby/components/base.rb', line 56

def shared_component
  self._component_scopes = []
  self._component_scopes_explicitly_set = true
end

#skip_key_transformation(value = true) ⇒ Object



39
40
41
# File 'lib/openapi_ruby/components/base.rb', line 39

def skip_key_transformation(value = true)
  self._skip_key_transformation = value
end

#to_openapiObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/openapi_ruby/components/base.rb', line 73

def to_openapi
  definition = _schema_definition.deep_dup

  definition["title"] ||= component_name if _component_type == :schemas

  if should_transform_keys?
    KeyTransformer.camelize_keys(definition)
  else
    definition
  end
end