Class: GrapeOAS::ApiModelBuilders::RequestParamsSupport::SchemaEnhancer

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_oas/api_model_builders/request_params_support/schema_enhancer.rb

Overview

Applies enhancements (constraints, format, examples, etc.) to a schema.

Class Method Summary collapse

Class Method Details

.apply(schema, spec, doc) ⇒ Object

Applies all enhancements to a schema based on spec and documentation.

Parameters:

  • schema (ApiModel::Schema)

    the schema to enhance

  • spec (Hash)

    the parameter specification

  • doc (Hash)

    the documentation hash



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grape_oas/api_model_builders/request_params_support/schema_enhancer.rb', line 13

def self.apply(schema, spec, doc)
  nullable = extract_nullable(doc)

  schema.description ||= doc[:desc]
  # Preserve existing nullable: true (e.g., from [Type, Nil] optimization)
  schema.nullable = (schema.nullable || nullable) if schema.respond_to?(:nullable=)

  apply_additional_properties(schema, doc)
  apply_format_and_example(schema, doc)
  SchemaConstraints.apply(schema, doc)
  apply_values(schema, spec)
  apply_default(schema, spec, doc)
end

.extract_nullable(doc) ⇒ Boolean

Extracts nullable flag from a documentation hash.

Parameters:

  • doc (Hash)

    the documentation hash

Returns:

  • (Boolean)

    true if nullable



31
32
33
# File 'lib/grape_oas/api_model_builders/request_params_support/schema_enhancer.rb', line 31

def self.extract_nullable(doc)
  doc[:nullable] || (doc[:x].is_a?(Hash) && doc[:x][:nullable]) || false
end