Skip to content

Commit b85c129

Browse files
committed
Drop JSON schema definition methods from core entirely
Per review feedback: `elasticgraph-schema_definition` should not know about JSON schema at all, so `json_schema_version`, `enforce_json_schema_version`, and `json_schema_strictness` no longer exist on the core API (calling them without `elasticgraph-json_ingestion` raises `NoMethodError`). Test support and the doctest helper feature-detect the extension with `respond_to?`.
1 parent 8d554d6 commit b85c129

7 files changed

Lines changed: 12 additions & 102 deletions

File tree

config/site/support/doctest_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ module ElasticGraph
6666
)
6767

6868
# This is required in all JSON ingestion schemas, but we don't want to have to put it in all
69-
# our examples, so we set it here. (Without a JSON ingestion extension, JSON schema versioning
70-
# is not supported and there is no version to set.)
71-
@api.json_schema_version 1 if @api.supports_json_schema_versioning?
69+
# our examples, so we set it here. (Without a JSON ingestion extension, the
70+
# `json_schema_version` API does not exist and there is no version to set.)
71+
@api.json_schema_version 1 if @api.respond_to?(:json_schema_version)
7272

7373
@api.object_type "SomeIndexedTypeToEnsureQueryTypeHasFields" do |t|
7474
t.field "id", "ID"

elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/schema_definition/api_extension.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ def self.extended(api)
4545
end
4646
end
4747

48-
# Indicates that this extension implements JSON schema versioning.
49-
#
50-
# @return [Boolean] true
51-
# @api private
52-
def supports_json_schema_versioning?
53-
true
54-
end
55-
5648
# Defines the version number of the current JSON schema. Importantly, every time a change is made that impacts the JSON schema
5749
# artifact, the version number must be incremented to ensure that each different version of the JSON schema is identified by a unique
5850
# version number. The publisher will then include this version number in published events to identify the version of the schema it

elasticgraph-json_ingestion/sig/elastic_graph/json_ingestion/schema_definition/api_extension.rbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module ElasticGraph
22
module JSONIngestion
33
module SchemaDefinition
44
module APIExtension: ::ElasticGraph::SchemaDefinition::API
5-
def supports_json_schema_versioning?: () -> bool
65
def json_schema_version: (::Integer) -> void
76
def enforce_json_schema_version: (bool) -> void
87
def json_schema_strictness: (?allow_omitted_fields: bool, ?allow_extra_fields: bool) -> void

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -452,55 +452,6 @@ def results
452452
@results ||= @factory.new_results
453453
end
454454

455-
# Indicates whether a schema definition extension that implements JSON schema versioning (such as
456-
# `elasticgraph-json_ingestion`) has been loaded onto this API instance.
457-
#
458-
# @return [Boolean] `false` unless an extension overrides this
459-
# @api private
460-
def supports_json_schema_versioning?
461-
false
462-
end
463-
464-
# Defines the version number of the current JSON schema.
465-
#
466-
# JSON schema generation is provided by an ingestion extension rather than by ElasticGraph core, so this
467-
# raises an error directing you to `ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension` (from the
468-
# `elasticgraph-json_ingestion` gem), which overrides this with real behavior.
469-
#
470-
# @param version [Integer] current version number of the JSON schema artifact
471-
# @return [void]
472-
# @raise [Errors::SchemaError] unless an extension that implements JSON schema generation is loaded
473-
def json_schema_version(version)
474-
raise_json_schema_definition_not_supported_error(:json_schema_version)
475-
end
476-
477-
# Configures whether the JSON schema version is required to be incremented when the JSON schemas artifact changes.
478-
#
479-
# JSON schema generation is provided by an ingestion extension rather than by ElasticGraph core, so this
480-
# raises an error directing you to `ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension` (from the
481-
# `elasticgraph-json_ingestion` gem), which overrides this with real behavior.
482-
#
483-
# @param value [Boolean] whether JSON schema version bumps should be enforced
484-
# @return [void]
485-
# @raise [Errors::SchemaError] unless an extension that implements JSON schema generation is loaded
486-
def enforce_json_schema_version(value)
487-
raise_json_schema_definition_not_supported_error(:enforce_json_schema_version)
488-
end
489-
490-
# Defines the strictness of the generated JSON schema validation.
491-
#
492-
# JSON schema generation is provided by an ingestion extension rather than by ElasticGraph core, so this
493-
# raises an error directing you to `ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension` (from the
494-
# `elasticgraph-json_ingestion` gem), which overrides this with real behavior.
495-
#
496-
# @param allow_omitted_fields [Boolean] whether nullable fields can be omitted from indexing events
497-
# @param allow_extra_fields [Boolean] whether extra fields can be included in indexing events
498-
# @return [void]
499-
# @raise [Errors::SchemaError] unless an extension that implements JSON schema generation is loaded
500-
def json_schema_strictness(allow_omitted_fields: false, allow_extra_fields: true)
501-
raise_json_schema_definition_not_supported_error(:json_schema_strictness)
502-
end
503-
504455
# Registers a customization callback that will be applied to every built-in type automatically provided by ElasticGraph. Provides
505456
# an opportunity to customize the built-in types (e.g. to add directives to them or whatever).
506457
#
@@ -547,15 +498,6 @@ def as_active_instance
547498
ensure
548499
::Thread.current[:ElasticGraph_SchemaDefinition_API_instance] = old_value
549500
end
550-
551-
private
552-
553-
def raise_json_schema_definition_not_supported_error(method_name)
554-
raise Errors::SchemaError,
555-
"`#{method_name}` is not supported because no loaded schema definition extension implements JSON schema generation. " \
556-
"To use it, add `elasticgraph-json_ingestion` to your bundle and include " \
557-
"`ElasticGraph::JSONIngestion::SchemaDefinition::APIExtension` in your configured `extension_modules`."
558-
end
559501
end
560502
end
561503
end

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/test_support.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,23 @@ def define_schema_with_schema_elements(
7575

7676
yield api if block_given?
7777

78-
# Set the json_schema_version to the provided value, if needed. JSON schema versioning is only
79-
# available when an extension that implements JSON schema generation (such as
78+
# Set the json_schema_version to the provided value, if needed. The `json_schema_version` API only
79+
# exists when an extension that implements JSON schema generation (such as
8080
# `elasticgraph-json_ingestion`) is loaded; without one there is no JSON schema version to set.
81-
if !json_schema_version.nil? && api.supports_json_schema_versioning?
82-
state = api.state # : untyped
83-
api.json_schema_version(json_schema_version) if state.json_schema_version.nil?
81+
if !json_schema_version.nil? && api.respond_to?(:json_schema_version)
82+
versioned_api = api # : untyped
83+
versioned_api.json_schema_version(json_schema_version) if versioned_api.state.json_schema_version.nil?
8484
end
8585

8686
# :nocov: -- the else branch and code past this aren't used by tests in elasticgraph-schema_definition.
8787
return api.results unless reload_schema_artifacts
8888

8989
# Reloading the schema artifacts takes extra time that we don't usually want to spend (so it's opt-in)
9090
# but it can be useful in some cases because there is a bit of extra pruning/validation that it applies.
91-
api.enforce_json_schema_version false if api.supports_json_schema_versioning?
91+
if api.respond_to?(:enforce_json_schema_version)
92+
versioned_api = api # : untyped
93+
versioned_api.enforce_json_schema_version false
94+
end
9295
tmp_dir = ::Dir.mktmpdir
9396
artifacts_manager = api.factory.new_schema_artifact_manager(
9497
schema_definition_results: api.results,

elasticgraph-schema_definition/sig/elastic_graph/schema_definition/api.rbs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ module ElasticGraph
6565
?output: io
6666
) -> void
6767

68-
def json_schema_strictness: (?allow_omitted_fields: bool, ?allow_extra_fields: bool) -> void
6968
def raw_sdl: (::String) -> void
7069
def object_type: (::String) { (SchemaElements::ObjectType) -> void } -> void
7170
def namespace_type: (::String) ?{ (SchemaElements::NamespaceType) -> void } -> void
@@ -77,17 +76,10 @@ module ElasticGraph
7776
def as_active_instance: { () -> void } -> void
7877
@results: Results?
7978
def results: () -> Results
80-
def supports_json_schema_versioning?: () -> bool
81-
def json_schema_version: (::Integer) -> void
82-
def enforce_json_schema_version: (bool) -> void
8379
def register_graphql_extension: (::Module, defined_at: ::String, **untyped) -> void
8480
def register_graphql_resolver: (::Symbol, ::Class, defined_at: ::String, ?built_in: bool, **untyped) -> void
8581
def on_built_in_types: () { (SchemaElements::graphQLType) -> void } -> void
8682
def on_root_query_type: () { (SchemaElements::ObjectType) -> void } -> void
87-
88-
private
89-
90-
def raise_json_schema_definition_not_supported_error: (::Symbol) -> bot
9183
end
9284
end
9385
end

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/graphql_schema/define_schema_spec.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,6 @@ module SchemaDefinition
5454
}.to raise_error Errors::SchemaError, a_string_including("Let ElasticGraph load")
5555
end
5656

57-
it "raises a clear error when JSON schema definition APIs are used without an extension that implements them" do
58-
api = API.new(schema_elements, true)
59-
60-
expect(api.supports_json_schema_versioning?).to be false
61-
62-
expect {
63-
api.json_schema_version 1
64-
}.to raise_error Errors::SchemaError, a_string_including("`json_schema_version` is not supported", "elasticgraph-json_ingestion")
65-
66-
expect {
67-
api.enforce_json_schema_version false
68-
}.to raise_error Errors::SchemaError, a_string_including("`enforce_json_schema_version` is not supported", "elasticgraph-json_ingestion")
69-
70-
expect {
71-
api.json_schema_strictness allow_omitted_fields: true
72-
}.to raise_error Errors::SchemaError, a_string_including("`json_schema_strictness` is not supported", "elasticgraph-json_ingestion")
73-
end
74-
7557
it "does not leak the active API instance, even when an error occurs" do
7658
api = API.new(schema_elements, true)
7759

0 commit comments

Comments
 (0)