From ad793dfb0e87801522baef8b1c0551327c359dda Mon Sep 17 00:00:00 2001 From: arielmirra Date: Mon, 29 Jul 2024 16:19:51 -0300 Subject: [PATCH 1/2] W-16346159: add semantic avro annotations --- .../parser/document/AvroDocumentParser.scala | 4 +- .../parser/domain/AvroArrayShapeParser.scala | 8 +- .../domain/AvroComplexShapeParser.scala | 18 +++- .../avro/parser/domain/AvroEnumParser.scala | 13 ++- .../parser/domain/AvroFixedShapeParser.scala | 12 ++- .../parser/domain/AvroTextTypeParser.scala | 6 +- .../parser/domain/AvroUnionShapeParser.scala | 6 +- .../parser/annotations/all-types-avro.json | 96 +++++++++++++++++++ .../parser/SourceMapsAnnotationsTest.scala | 9 +- 9 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 amf-cli/shared/src/test/resources/parser/annotations/all-types-avro.json diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/document/AvroDocumentParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/document/AvroDocumentParser.scala index adff976fe2..9fcc6c4e03 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/document/AvroDocumentParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/document/AvroDocumentParser.scala @@ -4,7 +4,7 @@ import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext import amf.apicontract.internal.spec.avro.parser.domain.AvroShapeParser import amf.core.client.scala.model.document.BaseUnitProcessingData import amf.core.client.scala.parse.document.SyamlParsedDocument -import amf.core.internal.metamodel.document.DocumentModel +import amf.core.internal.metamodel.document.{DocumentModel, FragmentModel} import amf.core.internal.parser.domain.Annotations import amf.core.internal.parser.{Root, YMapOps} import amf.core.internal.remote.Spec @@ -24,7 +24,7 @@ class AvroDocumentParser(root: Root)(implicit ctx: AvroSchemaContext) extends Qu map.key("namespace", (DocumentModel.Package in doc).allowingAnnotations) val parsedShape = parseType(map) - parsedShape.foreach(shape => doc.withEncodes(shape)) + parsedShape.foreach(shape => doc.setWithoutId(FragmentModel.Encodes, shape, Annotations.inferred())) doc } diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroArrayShapeParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroArrayShapeParser.scala index d53ffb4dca..82c3235403 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroArrayShapeParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroArrayShapeParser.scala @@ -1,12 +1,16 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext +import amf.core.internal.parser.domain.Annotations import amf.shapes.client.scala.model.domain.{AnyShape, ArrayShape} +import amf.shapes.internal.domain.metamodel.ArrayShapeModel import org.yaml.model.{YMap, YMapEntry} case class AvroArrayShapeParser(map: YMap)(implicit ctx: AvroSchemaContext) extends AvroCollectionShapeParser[ArrayShape](map, "items") { - override val shape: ArrayShape = ArrayShape(map) - override def setMembers(anyShape: AnyShape): Unit = shape.withItems(anyShape) + override val shape: ArrayShape = ArrayShape(map) + override def setMembers(anyShape: AnyShape): Unit = + shape.setWithoutId(ArrayShapeModel.Items, anyShape, Annotations.inferred()) + override def parseMembers(e: YMapEntry): AnyShape = AvroTextParser(e.value).parse() override def parseSpecificFields(): Unit = {} diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroComplexShapeParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroComplexShapeParser.scala index adfa0e396a..9f65422362 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroComplexShapeParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroComplexShapeParser.scala @@ -1,9 +1,9 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext -import amf.core.client.scala.model.domain.Shape +import amf.core.client.scala.model.domain.{AmfArray, ArrayNode, DataNode, Shape} import amf.core.internal.datanode.DataNodeParser -import amf.core.internal.metamodel.domain.ShapeModel +import amf.core.internal.metamodel.domain.{ArrayNodeModel, ShapeModel} import amf.core.internal.parser.YMapOps import amf.core.internal.parser.domain.Annotations import amf.shapes.client.scala.model.domain.AnyShape @@ -41,8 +41,18 @@ abstract class AvroComplexShapeParser(map: YMap)(implicit ctx: AvroSchemaContext map.key( "default", entry => { - val dataNode = DataNodeParser(entry.value).parse() - shape.set(ShapeModel.Default, dataNode, Annotations(entry)) + val dataNode: DataNode = DataNodeParser(entry.value).parse() + dataNode match { + // todo: by default the DataNodeParser returns ArrayNodes without annotations (we should add them in amf-core?) + case arrayNode: ArrayNode => + arrayNode.setWithoutId( + ArrayNodeModel.Member, + AmfArray(arrayNode.members, Annotations.inferred()), + Annotations.inferred() + ) + shape.set(ShapeModel.Default, arrayNode, Annotations(entry)) + case node => shape.set(ShapeModel.Default, node, Annotations(entry)) + } } ) } diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroEnumParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroEnumParser.scala index da8cbcc00b..18de6a1aa4 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroEnumParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroEnumParser.scala @@ -1,9 +1,10 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext +import amf.core.client.scala.model.domain.{AmfArray, AmfScalar, ScalarNode} +import amf.core.internal.metamodel.domain.ScalarNodeModel.Value import amf.core.client.scala.model.DataType -import amf.core.client.scala.model.domain.{AmfArray, ScalarNode} -import amf.core.internal.metamodel.domain.ShapeModel +import amf.core.internal.metamodel.domain.{ScalarNodeModel, ShapeModel} import amf.core.internal.parser.domain.Annotations import amf.core.internal.parser.{YMapOps, YScalarYRead} import amf.shapes.client.scala.model.domain.AnyShape @@ -31,5 +32,11 @@ class AvroEnumParser(map: YMap)(implicit ctx: AvroSchemaContext) extends AvroTex symbols.nodes.map(buildDataNode) } - private def buildDataNode(symbol: YNode) = ScalarNode(symbol.as[YScalar].text, Some(DataType.String), symbol) + private def buildDataNode(symbol: YNode): ScalarNode = { + val enum = symbol.as[YScalar].text + val ann = Annotations(symbol) + ScalarNode(ann) + .set(Value, AmfScalar(enum, ann), Annotations.inferred()) + .set(ScalarNodeModel.DataType, AmfScalar(DataType.String, Annotations.inferred()), Annotations.inferred()) + } } diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroFixedShapeParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroFixedShapeParser.scala index e25a0169d3..56341e5cf4 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroFixedShapeParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroFixedShapeParser.scala @@ -1,16 +1,22 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext +import amf.core.client.scala.model.domain.AmfScalar import amf.core.client.scala.vocabulary.Namespace.Xsd import amf.core.internal.parser.YMapOps import amf.core.internal.parser.domain.Annotations import amf.shapes.client.scala.model.domain.{AnyShape, ScalarShape} -import amf.shapes.internal.domain.metamodel.AnyShapeModel +import amf.shapes.internal.domain.metamodel.{AnyShapeModel, ScalarShapeModel} import org.yaml.model.YMap case class AvroFixedShapeParser(map: YMap)(implicit ctx: AvroSchemaContext) extends AvroComplexShapeParser(map) { - override val shape: AnyShape = - ScalarShape(Annotations(map)).withDataType(Xsd.base + "fixed", Annotations(map.entries.head)) + override val shape: AnyShape = { + ScalarShape(Annotations(map)).setWithoutId( + ScalarShapeModel.DataType, + AmfScalar(Xsd.base + "fixed", Annotations.inferred()), + Annotations.inferred() + ) + } override def parseSpecificFields(): Unit = { map.key("size", (AnyShapeModel.Size in shape).allowingAnnotations) diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroTextTypeParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroTextTypeParser.scala index e23d7cf658..28ea98376e 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroTextTypeParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroTextTypeParser.scala @@ -2,8 +2,10 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext import amf.core.client.scala.model.DataType +import amf.core.client.scala.model.domain.AmfScalar import amf.core.internal.parser.domain.Annotations import amf.shapes.client.scala.model.domain.{AnyShape, NilShape, NodeShape, ScalarShape} +import amf.shapes.internal.domain.metamodel.ScalarShapeModel import org.yaml.model.YMap /** parses primitive avro types such as null, boolean, int, long, float, double, bytes, string */ @@ -21,9 +23,9 @@ case class AvroTextTypeParser(`type`: String, maybeMap: Option[YMap])(implicit override lazy val shape: ScalarShape = ScalarShape(annotations) override def parse(): AnyShape = `type` match { - case "null" => NilShape(annotations).withName(`type`) + case "null" => NilShape(annotations).withName(`type`, typeAnnotations) case s if avroPrimitiveTypes.contains(s) => - shape.withDataType(DataType(`type`), typeAnnotations) + shape.setWithoutId(ScalarShapeModel.DataType, AmfScalar(DataType(`type`), annotations), typeAnnotations) case _ if ctx.globalSpace.contains(`type`) => val originalShape = ctx.globalSpace(`type`).asInstanceOf[NodeShape] originalShape.link(`type`, originalShape.annotations) diff --git a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroUnionShapeParser.scala b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroUnionShapeParser.scala index f13bbb5033..5d3ce1726a 100644 --- a/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroUnionShapeParser.scala +++ b/amf-api-contract/shared/src/main/scala/amf/apicontract/internal/spec/avro/parser/domain/AvroUnionShapeParser.scala @@ -1,16 +1,18 @@ package amf.apicontract.internal.spec.avro.parser.domain import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext +import amf.core.client.scala.model.domain.AmfArray import amf.core.internal.parser.domain.Annotations import amf.shapes.client.scala.model.domain.UnionShape +import amf.shapes.internal.domain.metamodel.UnionShapeModel import org.yaml.model.{YMap, YNode} case class AvroUnionShapeParser(members: Seq[YNode], node: YNode)(implicit ctx: AvroSchemaContext) extends AvroComplexShapeParser(node.as[YMap]) { - override val shape: UnionShape = UnionShape(node).withName("union") + override val shape: UnionShape = UnionShape(node).withSynthesizeName("union") override def parseSpecificFields(): Unit = { val parsedMembers = members.map(node => AvroTextParser(node).parse()) - shape.withAnyOf(parsedMembers, Annotations(node)) + shape.setWithoutId(UnionShapeModel.AnyOf, AmfArray(parsedMembers, Annotations(node)), Annotations(node)) } } diff --git a/amf-cli/shared/src/test/resources/parser/annotations/all-types-avro.json b/amf-cli/shared/src/test/resources/parser/annotations/all-types-avro.json new file mode 100644 index 0000000000..33cee81f92 --- /dev/null +++ b/amf-cli/shared/src/test/resources/parser/annotations/all-types-avro.json @@ -0,0 +1,96 @@ +{ + "type": "record", + "name": "AllTypes", + "namespace": "root", + "aliases": [ + "EveryTypeInTheSameSchema" + ], + "doc": "this schema contains every possible type you can declare in avro inside it's fields", + "fields": [ + { + "name": "boolean-primitive-type", + "doc": "this is a documentation for the boolean primitive type", + "type": "boolean", + "default": false + }, + { + "name": "int-primitive-type", + "doc": "this is a documentation for the int primitive type", + "type": "int", + "default": 123 + }, + { + "name": "long-primitive-type", + "doc": "this is a documentation for the long primitive type", + "type": "long", + "default": 123 + }, + { + "name": "float-primitive-type", + "doc": "this is a documentation for the float primitive type", + "type": "float", + "default": 1.0 + }, + { + "name": "double-primitive-type", + "doc": "this is a documentation for the double primitive type", + "type": "double", + "default": 1.0 + }, + { + "name": "bytes-primitive-type", + "doc": "this is a documentation for the bytes primitive type", + "type": "bytes", + "default": "\u00FF" + }, + { + "name": "string-primitive-type", + "doc": "this is a documentation for the string primitive type", + "type": "string", + "default": "foo" + }, + { + "name": "union", + "doc": "this is a documentation for the union type with recursive element", + "type": [ + "null", + "LongList" + ], + "default": null + }, + { + "type": "array", + "items": "long", + "default": [] + }, + { + "type": "array", + "items": { + "type": "array", + "items": "string" + }, + "default": [] + }, + { + "type": "enum", + "name": "Suit", + "symbols": [ + "SPADES", + "HEARTS", + "DIAMONDS", + "CLUBS" + ], + "default": "SPADES" + }, + { + "type": "fixed", + "size": 16, + "name": "md5" + }, + { + "type": "map", + "values": "long", + "default": {} + } + ] +} diff --git a/amf-cli/shared/src/test/scala/amf/parser/SourceMapsAnnotationsTest.scala b/amf-cli/shared/src/test/scala/amf/parser/SourceMapsAnnotationsTest.scala index 975e725132..4945fb2fa0 100644 --- a/amf-cli/shared/src/test/scala/amf/parser/SourceMapsAnnotationsTest.scala +++ b/amf-cli/shared/src/test/scala/amf/parser/SourceMapsAnnotationsTest.scala @@ -1,7 +1,6 @@ package amf.parser -import amf.apicontract.client.scala.{AMFConfiguration, APIConfiguration} -import amf.core.client.scala.config.RenderOptions +import amf.apicontract.client.scala.{AMFConfiguration, APIConfiguration, AvroConfiguration} import amf.core.client.scala.model.document.BaseUnit import amf.core.client.scala.model.domain.{AmfArray, AmfElement, AmfObject} import amf.core.client.scala.parse.AMFParser @@ -9,7 +8,6 @@ import amf.core.internal.annotations._ import amf.core.internal.metamodel.Field import amf.core.internal.metamodel.document.DocumentModel import amf.core.internal.parser.domain.{Annotations, FieldEntry} -import amf.core.internal.remote._ import amf.core.internal.unsafe.PlatformSecrets import amf.graphql.client.scala.GraphQLConfiguration import amf.graphqlfederation.client.scala.GraphQLFederationConfiguration @@ -18,7 +16,6 @@ import org.mulesoft.common.client.lexical.PositionRange import org.scalatest.Assertion import org.scalatest.funsuite.AsyncFunSuite -import scala.collection.GenTraversableOnce import scala.concurrent.{ExecutionContext, Future} /** iterates the BaseUnit checking if both field and value have the SourceAST or a VirtualNode annotation. The value may @@ -81,6 +78,10 @@ class SourceMapsAnnotationsTest extends AsyncFunSuite with PlatformSecrets { runTest("federation.graphql", Some(GraphQLFederationConfiguration.GraphQLFederation())) } + test("Test AVRO annotations") { + runTest("all-types-avro.json", Some(AvroConfiguration.Avro())) + } + private def parse(file: String, config: Option[AMFConfiguration] = None): Future[BaseUnit] = { val url = s"file://$directory$file" val configuration = config.getOrElse(APIConfiguration.API()) From 7d571f8e42f4bf87fa1913bf82fd245bc5e3ed2b Mon Sep 17 00:00:00 2001 From: arielmirra Date: Mon, 29 Jul 2024 16:42:36 -0300 Subject: [PATCH 2/2] W-16346159: add more examples to async-avro api --- .../avro/tck/apis/valid/avro-inline.jsonld | 317 +++++++++++++++++- .../avro/tck/apis/valid/avro-inline.yaml | 13 +- .../avro/AsyncAvroValidTCKParsingTest.scala | 4 + 3 files changed, 324 insertions(+), 10 deletions(-) diff --git a/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.jsonld b/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.jsonld index e22d54972e..0fe5094455 100644 --- a/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.jsonld +++ b/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.jsonld @@ -981,31 +981,41 @@ ] }, { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/scalar/default-scalar", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/shape/default-node", "@type": [ - "http://a.ml/vocabularies/shapes#ScalarShape", + "http://www.w3.org/ns/shacl#NodeShape", "http://a.ml/vocabularies/shapes#AnyShape", "http://www.w3.org/ns/shacl#Shape", "http://a.ml/vocabularies/shapes#Shape", "http://a.ml/vocabularies/document#DomainElement" ], + "http://a.ml/vocabularies/document#link-target": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes" + } + ], + "http://a.ml/vocabularies/document#link-label": [ + { + "@value": "AllTypes" + } + ], "http://a.ml/vocabularies/document-source-maps#sources": [ { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/scalar/default-scalar/source-map", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/shape/default-node/source-map", "@type": [ "http://a.ml/vocabularies/document-source-maps#SourceMap" ], "http://a.ml/vocabularies/document-source-maps#avro-schema": [ { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/scalar/default-scalar/source-map/avro-schema/element_0", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/shape/default-node/source-map/avro-schema/element_0", "http://a.ml/vocabularies/document-source-maps#element": [ { - "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/scalar/default-scalar" + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/union/union/union/anyOf/shape/default-node" } ], "http://a.ml/vocabularies/document-source-maps#value": [ { - "@value": "LongList" + "@value": "AllTypes" } ] } @@ -1568,7 +1578,7 @@ ], "http://www.w3.org/2000/01/rdf-schema#_2": [ { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_3", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_4", "@type": [ "http://a.ml/vocabularies/data#Scalar", "http://a.ml/vocabularies/data#Node", @@ -1588,7 +1598,7 @@ ], "http://www.w3.org/2000/01/rdf-schema#_3": [ { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_4", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_5", "@type": [ "http://a.ml/vocabularies/data#Scalar", "http://a.ml/vocabularies/data#Node", @@ -1608,7 +1618,7 @@ ], "http://www.w3.org/2000/01/rdf-schema#_4": [ { - "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_5", + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/Suit/scalar/Suit/in/data-node_6", "@type": [ "http://a.ml/vocabularies/data#Scalar", "http://a.ml/vocabularies/data#Node", @@ -1969,6 +1979,295 @@ ] } ] + }, + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name", + "@type": [ + "http://www.w3.org/ns/shacl#PropertyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://a.ml/vocabularies/shapes#range": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array", + "@type": [ + "http://a.ml/vocabularies/shapes#ArrayShape", + "http://a.ml/vocabularies/shapes#AnyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://a.ml/vocabularies/shapes#items": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/scalar/default-scalar", + "@type": [ + "http://a.ml/vocabularies/shapes#ScalarShape", + "http://a.ml/vocabularies/shapes#AnyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://www.w3.org/ns/shacl#datatype": [ + { + "@id": "http://www.w3.org/2001/XMLSchema#long" + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/scalar/default-scalar/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/scalar/default-scalar/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/scalar/default-scalar" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "long" + } + ] + } + ] + } + ] + } + ], + "http://www.w3.org/ns/shacl#defaultValue": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/array_1", + "@type": [ + "http://a.ml/vocabularies/data#Array", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq", + "http://a.ml/vocabularies/data#Node", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://www.w3.org/2000/01/rdf-schema#member": [], + "http://a.ml/vocabularies/core#name": [ + { + "@value": "array_1" + } + ] + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array/default-array" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + } + ] + } + ] + } + ], + "http://a.ml/vocabularies/shapes#serializationOrder": [ + { + "@value": 1 + } + ], + "http://www.w3.org/ns/shacl#name": [ + { + "@value": "this is the field name" + } + ], + "http://a.ml/vocabularies/core#description": [ + { + "@value": "this is the field doc" + } + ], + "http://www.w3.org/ns/shacl#defaultValue": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/array_1", + "@type": [ + "http://a.ml/vocabularies/data#Array", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq", + "http://a.ml/vocabularies/data#Node", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://www.w3.org/2000/01/rdf-schema#member": [], + "http://a.ml/vocabularies/core#name": [ + { + "@value": "array_1" + } + ] + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/source-map/avro-schema/element_1", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + }, + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/this%20is%20the%20field%20name/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "http://a.ml/vocabularies/shapes#range" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + } + ] + } + ] + }, + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3", + "@type": [ + "http://www.w3.org/ns/shacl#PropertyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://a.ml/vocabularies/shapes#range": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array", + "@type": [ + "http://a.ml/vocabularies/shapes#ArrayShape", + "http://a.ml/vocabularies/shapes#AnyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://a.ml/vocabularies/shapes#items": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/scalar/default-scalar", + "@type": [ + "http://a.ml/vocabularies/shapes#ScalarShape", + "http://a.ml/vocabularies/shapes#AnyShape", + "http://www.w3.org/ns/shacl#Shape", + "http://a.ml/vocabularies/shapes#Shape", + "http://a.ml/vocabularies/document#DomainElement" + ], + "http://www.w3.org/ns/shacl#datatype": [ + { + "@id": "http://www.w3.org/2001/XMLSchema#string" + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/scalar/default-scalar/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/scalar/default-scalar/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/scalar/default-scalar" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "string" + } + ] + } + ] + } + ] + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/array/default-array" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + } + ] + } + ] + } + ], + "http://a.ml/vocabularies/document-source-maps#sources": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/source-map", + "@type": [ + "http://a.ml/vocabularies/document-source-maps#SourceMap" + ], + "http://a.ml/vocabularies/document-source-maps#avro-schema": [ + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/source-map/avro-schema/element_1", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + }, + { + "@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml#/async-api/endpoint/mychannel/supportedOperation/publish/expects/request/payload/default/shape/AllTypes/property/property/default-property_3/source-map/avro-schema/element_0", + "http://a.ml/vocabularies/document-source-maps#element": [ + { + "@value": "http://a.ml/vocabularies/shapes#range" + } + ], + "http://a.ml/vocabularies/document-source-maps#value": [ + { + "@value": "array" + } + ] + } + ] + } + ] } ], "http://www.w3.org/ns/shacl#name": [ diff --git a/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml b/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml index b4871f80a2..56d70132a3 100644 --- a/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml +++ b/amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-inline.yaml @@ -48,7 +48,7 @@ channels: doc: this is a documentation for the union type with recursive element type: - null - - LongList + - AllTypes default: null - type: array items: long @@ -72,3 +72,14 @@ channels: - type: map values: long default: {} + - name: this is the field name # an array doesn't have name/order/aliases fields, they belong to the record field + doc: this is the field doc + order: ascending # this maps to a numeric value in the model (-1/0/1 for descending, ignore, ascending) + aliases: + - this is a field alias + type: array + items: long + default: [] + - type: # type field can be a string declaring the type (like all the rest) or an object with a schema (like here) + type: array + items: string diff --git a/amf-cli/shared/src/test/scala/amf/avro/AsyncAvroValidTCKParsingTest.scala b/amf-cli/shared/src/test/scala/amf/avro/AsyncAvroValidTCKParsingTest.scala index 85d84bbb54..b5926093dd 100644 --- a/amf-cli/shared/src/test/scala/amf/avro/AsyncAvroValidTCKParsingTest.scala +++ b/amf-cli/shared/src/test/scala/amf/avro/AsyncAvroValidTCKParsingTest.scala @@ -19,4 +19,8 @@ class AsyncAvroValidTCKParsingTest extends AsyncAvroCycleTest { } } + test("test async with an AVRO Schema parsing") { + cycle("avro-inline.yaml", "avro-inline.jsonld", Async20YamlHint, AmfJsonHint) + } + }