Skip to content

Commit

Permalink
W-16006973: add avro schema ann. to collection members
Browse files Browse the repository at this point in the history
  • Loading branch information
arielmirra committed Jul 16, 2024
1 parent 3bfcc0a commit be9c755
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext
import amf.core.internal.parser.YMapOps
import amf.shapes.client.scala.model.domain.AnyShape
import org.yaml.model.{YMap, YMapEntry}
import amf.shapes.internal.annotations.AVROSchemaType
import org.yaml.model.YScalar

abstract class AvroCollectionShapeParser[T <: AnyShape](map: YMap, membersKey: String)(implicit ctx: AvroSchemaContext)
extends AvroComplexShapeParser(map) {
Expand All @@ -20,5 +22,14 @@ abstract class AvroCollectionShapeParser[T <: AnyShape](map: YMap, membersKey: S
shape
}

protected def parseMembers(e: YMapEntry): AnyShape = AvroTextTypeParser(e.value.as[String], None).parse()
protected def parseMembers(e: YMapEntry): AnyShape = {
e.value.value match {
case scalar: YScalar =>
val avroType = scalar.text
val parsedShape = AvroTextTypeParser(avroType, None).parse()
parsedShape.annotations += AVROSchemaType(avroType)
parsedShape
case map: YMap => new AvroShapeParser(map).parse().getOrElse(AnyShape())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#long"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/all-types.json#/shape/AllTypes/property/property/default-property_2/shape/default-node/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/upanddown/cycle/avro/valid/all-types.json#/shape/AllTypes/property/property/default-property_2/shape/default-node/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/upanddown/cycle/avro/valid/all-types.json#/shape/AllTypes/property/property/default-property_2/shape/default-node/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "long"
}
]
}
]
}
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#long"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/map.json#/shape/default-node/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/upanddown/cycle/avro/valid/map.json#/shape/default-node/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/upanddown/cycle/avro/valid/map.json#/shape/default-node/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "long"
}
]
}
]
}
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#long"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/map/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/map/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/map/shape/default-node/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "long"
}
]
}
]
}
]
}
],
Expand Down Expand Up @@ -458,13 +481,76 @@
],
"http://www.w3.org/ns/shacl#additionalPropertiesSchema": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/scalar/default-scalar",
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/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://www.w3.org/ns/shacl#additionalPropertiesSchema": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/shape/default-node/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "long"
}
]
}
]
}
]
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/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/upanddown/cycle/avro/valid/nested-schema.json#/shape/TestRecordWithMapsAndArrays/property/property/nested_map/shape/default-node/shape/default-node"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "map"
}
]
}
]
}
]
}
],
Expand Down

0 comments on commit be9c755

Please sign in to comment.