Class: GrapeOAS::Introspectors::EntityIntrospectorSupport::PropertyExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb

Overview

Utility class for extracting properties from entity documentation hashes. All methods are stateless and can be called directly on the class.

Class Method Summary collapse

Class Method Details

.apply_entity_level_properties(schema, doc) ⇒ Object

Applies entity-level properties to a schema.

Parameters:

  • schema (ApiModel::Schema)

    the schema to modify

  • doc (Hash)

    the entity documentation hash



41
42
43
44
45
46
47
48
49
# File 'lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb', line 41

def apply_entity_level_properties(schema, doc)
  schema.additional_properties = doc[:additional_properties] if doc.key?(:additional_properties)
  schema.unevaluated_properties = doc[:unevaluated_properties] if doc.key?(:unevaluated_properties)

  defs = doc[:defs] || doc[:$defs]
  schema.defs = defs if defs.is_a?(Hash)
rescue NoMethodError
  # Silently handle errors when schema doesn't respond to setters
end

.extract_description(hash) ⇒ String?

Extracts description from a documentation hash.

Parameters:

  • hash (Hash)

    the documentation hash

Returns:

  • (String, nil)

    the description value



14
15
16
17
# File 'lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb', line 14

def extract_description(hash)
  desc = hash[:description] || hash[:desc]
  desc.is_a?(String) ? desc : nil
end

.extract_merge_flag(exposure, doc, opts) ⇒ Boolean?

Extracts merge flag from exposure options and documentation.

Parameters:

  • exposure

    the entity exposure

  • doc (Hash)

    the documentation hash

  • opts (Hash)

    the options hash

Returns:

  • (Boolean, nil)

    true if this is a merge exposure



33
34
35
# File 'lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb', line 33

def extract_merge_flag(exposure, doc, opts)
  opts[:merge] || doc[:merge] || (exposure.respond_to?(:for_merge) && exposure.for_merge)
end

.extract_nullable(doc) ⇒ Boolean

Extracts nullable flag from a documentation hash.

Parameters:

  • doc (Hash)

    the documentation hash

Returns:

  • (Boolean)

    true if nullable



23
24
25
# File 'lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb', line 23

def extract_nullable(doc)
  doc[:nullable] || doc["nullable"] || false
end