Skip to content

Commit

Permalink
Merge pull request #2020 from aml-org/W-16006973
Browse files Browse the repository at this point in the history
W-16006973: add avro-schema annotation on collections (items/values) parsing
  • Loading branch information
arielmirra committed Jul 12, 2024
2 parents bf80b12 + a1aaca0 commit af33b75
Show file tree
Hide file tree
Showing 14 changed files with 893 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ package amf.apicontract.internal.spec.avro.parser.domain

import amf.apicontract.internal.spec.avro.parser.context.AvroSchemaContext
import amf.shapes.client.scala.model.domain.AnyShape
import org.yaml.model.{YNode, YScalar}
import amf.shapes.internal.annotations.AVROSchemaType
import org.yaml.model.{YMap, YNode, YScalar}

case class AvroTextParser(node: YNode)(implicit ctx: AvroSchemaContext) extends AvroKeyExtractor {
def parse(): AnyShape = {
val `type` = node.as[YScalar].text
AvroTextTypeParser(`type`, None).parse()
node.value match {
case scalar: YScalar =>
val avroType = scalar.text
val parsedShape = AvroTextTypeParser(scalar.text, 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 @@ -222,6 +222,29 @@
{
"@value": "null"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null/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/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null/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/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "null"
}
]
}
]
}
]
},
{
Expand All @@ -237,6 +260,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#int"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/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/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/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/async-2.4-avro-valid.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "int"
}
]
}
]
}
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@
{
"@value": "null"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null/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-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null/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-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/nil/null"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "null"
}
]
}
]
}
]
},
{
Expand All @@ -237,6 +260,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#int"
}
],
"http://a.ml/vocabularies/document-source-maps#sources": [
{
"@id": "file://amf-cli/shared/src/test/resources/avro/tck/apis/valid/avro-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/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-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/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-components.yaml#/declares/msg/testMessage/payload/default/shape/Person/property/property/age/union/age/anyOf/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "int"
}
]
}
]
}
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@
{
"@value": "null"
}
],
"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/Person/property/property/age/union/age/anyOf/nil/null/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/Person/property/property/age/union/age/anyOf/nil/null/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/Person/property/property/age/union/age/anyOf/nil/null"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "null"
}
]
}
]
}
]
},
{
Expand All @@ -184,6 +207,29 @@
{
"@id": "http://www.w3.org/2001/XMLSchema#int"
}
],
"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/Person/property/property/age/union/age/anyOf/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/Person/property/property/age/union/age/anyOf/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/Person/property/property/age/union/age/anyOf/scalar/default-scalar"
}
],
"http://a.ml/vocabularies/document-source-maps#value": [
{
"@value": "int"
}
]
}
]
}
]
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "array",
"items": {
"type": "array",
"items": "string"
},
"default": []
}
Loading

0 comments on commit af33b75

Please sign in to comment.