diff --git a/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/JsonLDObjectElementParser.scala b/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/JsonLDObjectElementParser.scala index c04131dbe2..95e6222a2f 100644 --- a/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/JsonLDObjectElementParser.scala +++ b/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/JsonLDObjectElementParser.scala @@ -31,7 +31,10 @@ case class JsonLDObjectElementParser( override def foldLeft( current: JsonLDObjectElementBuilder, other: JsonLDObjectElementBuilder - ): JsonLDObjectElementBuilder = current.merge(other)(ctx) + ): JsonLDObjectElementBuilder = { + val result = current.merge(other)(ctx) + result + } override def findClassTerm(ctx: SemanticContext): Seq[String] = { val terms = super.findClassTerm(ctx).map(ctx.expand) diff --git a/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/builder/JsonLDObjectElementBuilder.scala b/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/builder/JsonLDObjectElementBuilder.scala index 0433174f86..72f61e62c9 100644 --- a/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/builder/JsonLDObjectElementBuilder.scala +++ b/amf-shapes/shared/src/main/scala/amf/shapes/internal/spec/jsonldschema/parser/builder/JsonLDObjectElementBuilder.scala @@ -42,7 +42,8 @@ class JsonLDObjectElementBuilder(location: SourceLocation, key: String, base: St addClassTerms(other) other.properties.foreach { case (_, builder) => - if (!hasBeenParsedWithSameSemantics(builder) && isSubSchemaSemanticDefinition(builder)) { + // TODO: this logic needs revisiting and renaming, hard to understand + if (isSubSchemaSemanticDefinition(builder)) { val current = properties(builder.key) val merged = mergeProperties(current, builder) remove(current) @@ -61,10 +62,6 @@ class JsonLDObjectElementBuilder(location: SourceLocation, key: String, base: St properties.contains(builder.key) && !builder.hasTermWithDefaultBase } - private def hasBeenParsedWithSameSemantics(property: JsonLDPropertyBuilder) = { - termIndex.getOrElse(property.term, List.empty).contains(property) - } - private def addClassTerms(other: JsonLDObjectElementBuilder): Unit = { other.classTerms.foreach { t => if (!classTerms.contains(t)) classTerms.prepend(t) } } diff --git a/amf-shapes/shared/src/test/resources/jsonld-schema/instances/results/semantics/class-term-addition-in-inner-property.json.jsonld b/amf-shapes/shared/src/test/resources/jsonld-schema/instances/results/semantics/class-term-addition-in-inner-property.json.jsonld new file mode 100644 index 0000000000..736d1ca799 --- /dev/null +++ b/amf-shapes/shared/src/test/resources/jsonld-schema/instances/results/semantics/class-term-addition-in-inner-property.json.jsonld @@ -0,0 +1,51 @@ +{ + "@graph": [ + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/BaseUnitProcessingData", + "@type": [ + "http://a.ml/vocabularies/document#BaseUnitProcessingData" + ], + "http://a.ml/vocabularies/document#transformed": false + }, + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/", + "@type": [ + "http://a.ml/vocabularies/core#encodes", + "http://a.ml/vocabularies/document#JsonLDObject" + ], + "http://prefix.com#d": [ + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/d/0" + } + ] + }, + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/d/0", + "@type": [ + "http://prefix.com#D", + "http://a.ml/vocabularies/core#d/0", + "http://a.ml/vocabularies/document#JsonLDObject" + ], + "http://prefix.com#e": "something" + }, + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json", + "@type": [ + "http://a.ml/vocabularies/document#JsonLDInstanceDocument", + "http://a.ml/vocabularies/document#Document", + "http://a.ml/vocabularies/document#Fragment", + "http://a.ml/vocabularies/document#Module", + "http://a.ml/vocabularies/document#Unit" + ], + "http://a.ml/vocabularies/document#encodes": [ + { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/encodes/" + } + ], + "http://a.ml/vocabularies/document#root": true, + "http://a.ml/vocabularies/document#processingData": { + "@id": "file://amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json#/BaseUnitProcessingData" + } + } + ] +} diff --git a/amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json b/amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json new file mode 100644 index 0000000000..ed33a935b4 --- /dev/null +++ b/amf-shapes/shared/src/test/resources/jsonld-schema/instances/semantics/class-term-addition-in-inner-property.json @@ -0,0 +1,7 @@ +{ + "d": [ + { + "e": "something" + } + ] +} diff --git a/amf-shapes/shared/src/test/resources/jsonld-schema/schemas/semantics/class-term-addition-in-inner-property.json b/amf-shapes/shared/src/test/resources/jsonld-schema/schemas/semantics/class-term-addition-in-inner-property.json new file mode 100644 index 0000000000..0577563051 --- /dev/null +++ b/amf-shapes/shared/src/test/resources/jsonld-schema/schemas/semantics/class-term-addition-in-inner-property.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema", + "@context": { + "prefix": "http://prefix.com#", + "d": "prefix:d" + }, + "properties": {}, + "if": {}, + "then": { + "properties": { + "d": { + "type": "array", + "items": { + "$ref": "#/definitions/D" + } + } + } + }, + "definitions": { + "D": { + "@context": { + "prefix": "http://prefix.com#", + "@type": "prefix:D", + "e": "prefix:e" + }, + "properties": { + "e": { + "type": "string" + } + } + } + } +} \ No newline at end of file