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

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

Instance Method Summary collapse

Instance Method Details

#component_nameObject



76
77
78
# File 'lib/openapi_ruby/components/base.rb', line 76

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

#component_scopes(*scopes) ⇒ Object



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

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



53
54
55
56
57
# File 'lib/openapi_ruby/components/base.rb', line 53

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

#inherited(subclass) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/openapi_ruby/components/base.rb', line 26

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



100
101
102
103
104
105
# File 'lib/openapi_ruby/components/base.rb', line 100

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

  build_permit_list(properties)
end

#registry_keyObject



80
81
82
83
84
85
86
# File 'lib/openapi_ruby/components/base.rb', line 80

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

#schema(definition = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/openapi_ruby/components/base.rb', line 37

def schema(definition = nil)
  if definition
    stringified = deep_stringify(definition)
    self._schema_definition = deep_merge_with_array_concat(_schema_definition, stringified)
  end
  _schema_definition
end

#schema_hidden(value = true) ⇒ Object



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

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

#shared_componentObject



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

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

#skip_key_transformation(value = true) ⇒ Object



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

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

#to_openapiObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/openapi_ruby/components/base.rb', line 88

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

#transform_enum_key(key) ⇒ Object



71
72
73
74
# File 'lib/openapi_ruby/components/base.rb', line 71

def transform_enum_key(key)
  key = ActiveSupport::Inflector.underscore(key.to_s)
  key.parameterize(separator: "_").upcase
end