Skip to content

Commit

Permalink
Merge 601661a into df81043
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Mar 21, 2023
2 parents df81043 + 601661a commit eb2ac05
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 24 deletions.
14 changes: 1 addition & 13 deletions lib/jsi/metaschema_node.rb
Expand Up @@ -75,6 +75,7 @@ def initialize(
our_bootstrap_schemas.each do |bootstrap_schema|
if bootstrap_schema.jsi_ptr == metaschema_root_ptr
# this is described by the metaschema, i.e. this is a schema
extend Schema
schema_implementation_modules.each do |schema_implementation_module|
extend schema_implementation_module
end
Expand Down Expand Up @@ -112,19 +113,6 @@ def initialize(
@jsi_schemas.each do |schema|
extend schema.jsi_schema_module
end

# workarounds
begin # draft 4 boolean schema workaround
# in draft 4, boolean schemas are not described in the root, but on anyOf schemas on
# properties/additionalProperties and properties/additionalItems.
# these still describe schemas, despite not being described by the metaschema.
addtlPropsanyOf = metaschema_root_ptr["properties"]["additionalProperties"]["anyOf"]
addtlItemsanyOf = metaschema_root_ptr["properties"]["additionalItems"]["anyOf"]

if !jsi_ptr.root? && [addtlPropsanyOf, addtlItemsanyOf].include?(jsi_ptr.parent)
describes_schema!(schema_implementation_modules)
end
end
end

# Set of modules to apply to schemas which are instances of (described by) the metaschema
Expand Down
1 change: 1 addition & 0 deletions lib/jsi/metaschema_node/bootstrap_schema.rb
Expand Up @@ -17,6 +17,7 @@ class MetaschemaNode::BootstrapSchema
include Util::Memoize
include Util::FingerprintHash
include Schema::SchemaAncestorNode
include Schema

class << self
def inspect
Expand Down
10 changes: 4 additions & 6 deletions lib/jsi/schema.rb
Expand Up @@ -425,19 +425,15 @@ def describes_schema?

# indicates that this schema describes a schema.
# this schema is extended with {DescribesSchema} and its {#jsi_schema_module} is extended
# with {SchemaModule::DescribesSchemaModule}, and the JSI Schema Module will include the given modules.
# with {SchemaModule::DescribesSchemaModule}, and the JSI Schema Module will include
# JSI::Schema and the given modules.
#
# @param schema_implementation_modules [Enumerable<Module>] modules which implement the functionality of
# the schema to extend schemas described by this schema.
# this must include JSI::Schema (usually indirectly).
# @return [void]
def describes_schema!(schema_implementation_modules, objectspace: false)
schema_implementation_modules = Util.ensure_module_set(schema_implementation_modules)

unless schema_implementation_modules.any? { |mod| mod <= Schema }
raise(ArgumentError, "schema_implementation_modules for a schema must include #{Schema}")
end

if describes_schema?
# this schema, or one equal to it, has already had describes_schema! called on it.
# this is to be avoided, but is not particularly a problem.
Expand All @@ -446,11 +442,13 @@ def describes_schema!(schema_implementation_modules, objectspace: false)
raise(ArgumentError, "this schema already describes a schema with different schema_implementation_modules")
end
else
jsi_schema_module.include(Schema)
schema_implementation_modules.each do |mod|
jsi_schema_module.include(mod)
end
if objectspace
ObjectSpace.each_object(jsi_schema_module) do |schema|
schema.extend(Schema)
schema_implementation_modules.each do |mod|
schema.extend(mod)
end
Expand Down
1 change: 0 additions & 1 deletion lib/jsi/schema/draft04.rb
Expand Up @@ -3,7 +3,6 @@
module JSI
module Schema
module Draft04
include Schema
include OldId
include IdWithAnchor
include IntegerDisallows0Fraction
Expand Down
1 change: 0 additions & 1 deletion lib/jsi/schema/draft06.rb
Expand Up @@ -3,7 +3,6 @@
module JSI
module Schema
module Draft06
include Schema
include BigMoneyId
include IdWithAnchor
include IntegerAllows0Fraction
Expand Down
1 change: 0 additions & 1 deletion lib/jsi/schema/draft07.rb
Expand Up @@ -3,7 +3,6 @@
module JSI
module Schema
module Draft07
include Schema
include BigMoneyId
include IdWithAnchor
include IntegerAllows0Fraction
Expand Down
1 change: 0 additions & 1 deletion lib/jsi/simple_wrap.rb
Expand Up @@ -2,7 +2,6 @@

module JSI
simple_wrap_implementation = Module.new do
include Schema
include Schema::Application::ChildApplication
include Schema::Application::InplaceApplication
include Schema::Validation::Core
Expand Down
10 changes: 10 additions & 0 deletions lib/schemas/json-schema.org/draft-04/schema.rb
Expand Up @@ -6,6 +6,16 @@ module JSI
schema_implementation_modules: [JSI::Schema::Draft04],
).jsi_schema_module

# in draft 4, boolean schemas are not described in the root, but on anyOf schemas on
# properties/additionalProperties and properties/additionalItems.
# these still describe schemas, despite not being described by the metaschema.
also_describe_schemas =
JSONSchemaOrgDraft04.schema["properties"]["additionalProperties"]["anyOf"] +
JSONSchemaOrgDraft04.schema["properties"]["additionalItems"]["anyOf"]
also_describe_schemas.each do |schema|
schema.describes_schema!([JSI::Schema::Draft04])
end

# the JSI schema module for `http://json-schema.org/draft-04/schema`
module JSONSchemaOrgDraft04
# @!parse extend JSI::DescribesSchemaModule
Expand Down
1 change: 0 additions & 1 deletion test/metaschema_node_test.rb
Expand Up @@ -3,7 +3,6 @@
describe JSI::MetaschemaNode do
let(:schema_implementation_modules) do
[
JSI::Schema,
JSI::Schema::Application::Draft06,
]
end
Expand Down

0 comments on commit eb2ac05

Please sign in to comment.