Class: ElasticGraph::JSONIngestion::SchemaDefinition::Indexing::Field Private

Inherits:
SchemaDefinition::Indexing::Field show all
Defined in:
elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps an indexing field with JSON schema generation behavior.

Constant Summary collapse

JSON_SCHEMA_OVERRIDES_BY_MAPPING_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Note:

We don't handle integer here because it's the default numeric type (handled by our definition of the Int scalar type).

Note:

Likewise, we don't handle long here because a custom scalar type must be used for that since GraphQL's Int type can't handle long values.

JSON schema overrides that automatically apply to specific mapping types so that the JSON schema validation will reject values which cannot be indexed into fields of a specific mapping type.

{
  "byte" => {"minimum" => -(2**7), "maximum" => (2**7) - 1},
  "short" => {"minimum" => -(2**15), "maximum" => (2**15) - 1},
  "keyword" => {"maxLength" => DEFAULT_MAX_KEYWORD_LENGTH},
  "text" => {"maxLength" => DEFAULT_MAX_TEXT_LENGTH}
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SchemaDefinition::Indexing::Field

#mapping, normalized_mapping_hash_for

Constructor Details

#initialize(field, json_schema_layers:, json_schema_customizations:, doc_comment:) ⇒ Field

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Field.

Parameters:

  • field (ElasticGraph::SchemaDefinition::Indexing::Field)

    the indexing field to wrap

  • json_schema_layers (Array<Symbol>)

    JSON schema wrapper layers from the field type reference

  • json_schema_customizations (Hash<Symbol, Object>)

    user-defined JSON schema customizations

  • doc_comment (String, nil)

    documentation for the field



51
52
53
54
55
56
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 51

def initialize(field, json_schema_layers:, json_schema_customizations:, doc_comment:)
  super(field)
  @json_schema_layers = json_schema_layers
  @json_schema_customizations = json_schema_customizations
  @doc_comment = doc_comment
end

Instance Attribute Details

#doc_commentString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns documentation for the field.

Returns:

  • (String, nil)

    documentation for the field



32
33
34
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 32

def doc_comment
  @doc_comment
end

#json_schema_customizationsHash<Symbol, Object> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns user-defined JSON schema customizations.

Returns:

  • (Hash<Symbol, Object>)

    user-defined JSON schema customizations



29
30
31
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 29

def json_schema_customizations
  @json_schema_customizations
end

#json_schema_layersArray<Symbol> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns JSON schema wrapper layers from the field type reference.

Returns:

  • (Array<Symbol>)

    JSON schema wrapper layers from the field type reference



26
27
28
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 26

def json_schema_layers
  @json_schema_layers
end

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares fields, including JSON schema metadata tracked by this wrapper.

Parameters:

  • other (Object)

    the object to compare against

Returns:

  • (Boolean)

    true when the field and JSON schema metadata match



84
85
86
87
88
89
90
91
92
93
94
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 84

def ==(other)
  case other
  when Field
    __getobj__ == other.__getobj__ &&
      json_schema_layers == other.json_schema_layers &&
      json_schema_customizations == other.json_schema_customizations &&
      doc_comment == other.doc_comment
  else
    super
  end
end

#eql?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


96
97
98
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 96

def eql?(other)
  self == other
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a hash code based on the wrapped field and JSON schema metadata.

Returns:

  • (Integer)

    the hash code



103
104
105
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 103

def hash
  [__getobj__, json_schema_layers, json_schema_customizations, doc_comment].hash
end

#json_schemaHash<String, Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the JSON schema definition for this field.

Returns:

  • (Hash<String, Object>)

    the JSON schema hash



61
62
63
64
65
66
67
68
69
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 61

def json_schema
  @json_schema ||=
    json_schema_layers
      .reverse # resolve layers from innermost to outermost wrappings
      .reduce(inner_json_schema) { |acc, layer| process_layer(layer, acc) }
      .merge(outer_json_schema_customizations)
      .merge({"description" => doc_comment}.compact)
      .then { |hash| Support::HashUtil.stringify_keys(hash) }
end

#json_schema_metadataJSONSchemaFieldMetadata

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns metadata about this field for inclusion in the JSON schema.

Returns:



72
73
74
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 72

def 
  JSONSchemaFieldMetadata.new(type: type.name, name_in_index: name_in_index)
end

#nullable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


76
77
78
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/indexing/field.rb', line 76

def nullable?
  json_schema_layers.include?(:nullable)
end