Class: Gitlab::GrapeOpenapi::RequestBodyRegistry
- Inherits:
-
Object
- Object
- Gitlab::GrapeOpenapi::RequestBodyRegistry
- Defined in:
- lib/gitlab/grape_openapi/request_body_registry.rb
Constant Summary collapse
- SCHEMA_PATH_PREFIX =
'#/components/schemas/'
Instance Attribute Summary collapse
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#initialize ⇒ RequestBodyRegistry
constructor
A new instance of RequestBodyRegistry.
- #register(schema) ⇒ Object
Constructor Details
#initialize ⇒ RequestBodyRegistry
Returns a new instance of RequestBodyRegistry.
12 13 14 15 |
# File 'lib/gitlab/grape_openapi/request_body_registry.rb', line 12 def initialize @schemas = {} @schema_hashes = {} end |
Instance Attribute Details
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
10 11 12 |
# File 'lib/gitlab/grape_openapi/request_body_registry.rb', line 10 def schemas @schemas end |
Instance Method Details
#register(schema) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gitlab/grape_openapi/request_body_registry.rb', line 17 def register(schema) return nil if schema.blank? schema_hash = compute_hash(schema) if @schema_hashes.key?(schema_hash) existing_name = @schema_hashes[schema_hash] return { '$ref' => "#{SCHEMA_PATH_PREFIX}#{existing_name}" } end name = "RequestBody_#{short_hash(schema_hash)}" @schemas[name] = schema @schema_hashes[schema_hash] = name { '$ref' => "#{SCHEMA_PATH_PREFIX}#{name}" } end |