Class: Gitlab::GrapeOpenapi::SchemaRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/schema_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemaRegistry

Returns a new instance of SchemaRegistry.



8
9
10
# File 'lib/gitlab/grape_openapi/schema_registry.rb', line 8

def initialize
  @schemas = {}
end

Instance Attribute Details

#schemasObject (readonly)

Returns the value of attribute schemas.



6
7
8
# File 'lib/gitlab/grape_openapi/schema_registry.rb', line 6

def schemas
  @schemas
end

Instance Method Details

#normalize_entity_class(entity_class) ⇒ Object



21
22
23
# File 'lib/gitlab/grape_openapi/schema_registry.rb', line 21

def normalize_entity_class(entity_class)
  entity_class.name.delete(':')
end

#register(entity_class, schema) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/gitlab/grape_openapi/schema_registry.rb', line 12

def register(entity_class, schema)
  normalized_name = normalize_entity_class(entity_class)
  return normalized_name if @schemas.key?(normalized_name)
  return normalized_name unless schema.is_a?(Models::Schema)

  @schemas[normalized_name] = schema
  normalized_name
end