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

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

Instance Method Summary collapse

Instance Method Details

#component_nameObject



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

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

#component_scopes(*scopes) ⇒ Object



47
48
49
# File 'lib/openapi_ruby/components/base.rb', line 47

def component_scopes(*scopes)
  self._component_scopes = scopes.flatten.map(&:to_sym)
end

#component_type(type) ⇒ Object



41
42
43
44
45
# File 'lib/openapi_ruby/components/base.rb', line 41

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

#inherited(subclass) ⇒ Object



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

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
  Registry.instance.register(subclass) if subclass.name
end

#permitted_paramsObject



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

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

  build_permit_list(properties)
end

#schema(definition = nil) ⇒ Object



28
29
30
31
# File 'lib/openapi_ruby/components/base.rb', line 28

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

#schema_hidden(value = true) ⇒ Object



33
34
35
# File 'lib/openapi_ruby/components/base.rb', line 33

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

#skip_key_transformation(value = true) ⇒ Object



37
38
39
# File 'lib/openapi_ruby/components/base.rb', line 37

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

#to_openapiObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/openapi_ruby/components/base.rb', line 55

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