-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W-12689958: add Solace binding parsing
- Loading branch information
1 parent
6e82511
commit 82eb262
Showing
10 changed files
with
592 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...contract/internal/spec/async/parser/bindings/operation/SolaceOperationBindingParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package amf.apicontract.internal.spec.async.parser.bindings.operation | ||
|
||
import amf.apicontract.client.scala.model.domain.bindings.solace.{ | ||
SolaceOperationBinding, | ||
SolaceOperationDestination, | ||
SolaceOperationQueue, | ||
SolaceOperationTopic | ||
} | ||
import amf.apicontract.internal.metamodel.domain.bindings.{ | ||
SolaceOperationBindingModel, | ||
SolaceOperationDestinationModel, | ||
SolaceOperationQueueModel, | ||
SolaceOperationTopicModel | ||
} | ||
import amf.apicontract.internal.spec.async.parser.bindings.BindingParser | ||
import amf.apicontract.internal.spec.async.parser.context.AsyncWebApiContext | ||
import amf.core.client.scala.model.domain.AmfScalar | ||
import amf.core.internal.parser.domain.Annotations | ||
import org.yaml.model.{YMap, YMapEntry} | ||
import amf.core.internal.parser.YMapOps | ||
|
||
object SolaceOperationBindingParser extends BindingParser[SolaceOperationBinding] { | ||
override def parse(entry: YMapEntry, parent: String)(implicit ctx: AsyncWebApiContext): SolaceOperationBinding = { | ||
val binding = SolaceOperationBinding(Annotations(entry)) | ||
val map = entry.value.as[YMap] | ||
|
||
map.key("destinations").foreach { entry => | ||
val destinations = entry.value.as[Seq[YMap]].map(destinationMap => parseDestination(binding, destinationMap)) | ||
binding.setArrayWithoutId(SolaceOperationBindingModel.Destinations, destinations) | ||
} | ||
|
||
parseBindingVersion(binding, SolaceOperationBindingModel.BindingVersion, map) | ||
|
||
ctx.closedShape(binding, map, "SolaceOperationBinding") | ||
|
||
binding | ||
} | ||
|
||
private def parseDestination(binding: SolaceOperationBinding, map: YMap)(implicit | ||
ctx: AsyncWebApiContext | ||
): SolaceOperationDestination = { | ||
val destination = SolaceOperationDestination(Annotations()) | ||
map.key("destinationType", SolaceOperationDestinationModel.DestinationType in destination) | ||
|
||
map.key("deliveryMode") match { // todo validate that it can only be 'direct' or 'persistent' | ||
case Some(value) => Some(value).foreach(SolaceOperationDestinationModel.DeliveryMode in destination) | ||
case None => setDefaultValue(destination, SolaceOperationDestinationModel.DeliveryMode, AmfScalar("persistent")) | ||
} | ||
|
||
parseQueue(destination, map) | ||
parseTopic(destination, map) | ||
|
||
destination | ||
} | ||
|
||
private def parseQueue(destination: SolaceOperationDestination, map: YMap)(implicit ctx: AsyncWebApiContext): Unit = { | ||
map.key( | ||
"queue", | ||
{ entry => | ||
val queue = SolaceOperationQueue(Annotations(entry.value)) | ||
val queueMap = entry.value.as[YMap] | ||
|
||
queueMap.key("name", SolaceOperationQueueModel.Name in queue) | ||
|
||
queueMap.key("topicSubscriptions", SolaceOperationQueueModel.TopicSubscriptions in queue) | ||
|
||
queueMap.key("accessType", SolaceOperationQueueModel.AccessType in queue) | ||
queueMap.key("maxMsgSpoolSize", SolaceOperationQueueModel.MaxMsgSpoolSize in queue) | ||
queueMap.key("maxTtl", SolaceOperationQueueModel.MaxTtl in queue) | ||
|
||
ctx.closedShape(queue, queueMap, "SolaceOperationQueue") | ||
|
||
destination.setWithoutId(SolaceOperationDestinationModel.Queue, queue, Annotations(entry)) | ||
} | ||
) | ||
} | ||
|
||
private def parseTopic(destination: SolaceOperationDestination, map: YMap)(implicit ctx: AsyncWebApiContext): Unit = { | ||
map.key( | ||
"topic", | ||
{ entry => | ||
val topic = SolaceOperationTopic(Annotations(entry.value)) | ||
val topicMap = entry.value.as[YMap] | ||
|
||
topicMap.key("topicSubscriptions", SolaceOperationTopicModel.TopicSubscriptions in topic) | ||
|
||
ctx.closedShape(topic, topicMap, "SolaceOperationTopic") | ||
|
||
destination.setWithoutId(SolaceOperationDestinationModel.Topic, topic, Annotations(entry)) | ||
} | ||
) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...mf/apicontract/internal/spec/async/parser/bindings/server/SolaceServerBindingParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package amf.apicontract.internal.spec.async.parser.bindings.server | ||
|
||
import amf.apicontract.client.scala.model.domain.bindings.solace.SolaceServerBinding | ||
import amf.apicontract.internal.metamodel.domain.bindings.SolaceServerBindingModel | ||
import amf.apicontract.internal.spec.async.parser.bindings.BindingParser | ||
import amf.apicontract.internal.spec.async.parser.context.AsyncWebApiContext | ||
import amf.core.internal.parser.YMapOps | ||
import amf.core.internal.parser.domain.Annotations | ||
import org.yaml.model.{YMap, YMapEntry} | ||
|
||
object SolaceServerBindingParser extends BindingParser[SolaceServerBinding] { | ||
override def parse(entry: YMapEntry, parent: String)(implicit ctx: AsyncWebApiContext): SolaceServerBinding = { | ||
val binding = SolaceServerBinding(Annotations(entry)) | ||
val map = entry.value.as[YMap] | ||
|
||
map.key("msgVpn", SolaceServerBindingModel.MsgVpn in binding) | ||
|
||
parseBindingVersion(binding, SolaceServerBindingModel.BindingVersion, map) | ||
|
||
ctx.closedShape(binding, map, "SolaceServerBinding") | ||
|
||
binding | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 30 additions & 1 deletion
31
.../main/scala/amf/apicontract/internal/spec/async/parser/context/syntax/Async23Syntax.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
package amf.apicontract.internal.spec.async.parser.context.syntax | ||
|
||
import amf.apicontract.internal.spec.async.parser.bindings.Bindings.Solace | ||
import amf.shapes.internal.spec.common.parser.SpecSyntax | ||
|
||
object Async23Syntax extends SpecSyntax { | ||
override val nodes: Map[String, Set[String]] = Async22Syntax.nodes | ||
override val nodes: Map[String, Set[String]] = | ||
add( | ||
Async22Syntax.nodes, | ||
"bindings" -> Set(Solace), | ||
"SolaceServerBinding" -> Set( | ||
"msgVpn", | ||
"bindingVersion" | ||
), | ||
"SolaceOperationBinding" -> Set( | ||
"destinations", | ||
"bindingVersion" | ||
), | ||
"SolaceOperationDestination" -> Set( | ||
"destinationType", | ||
"deliveryMode", | ||
"queue", | ||
"topic" | ||
), | ||
"SolaceOperationQueue" -> Set( | ||
"name", | ||
"topicSubscriptions", | ||
"accessType", | ||
"maxMsgSpoolSize", | ||
"maxTtl" | ||
), | ||
"SolaceOperationTopic" -> Set( | ||
"topicSubscriptions" | ||
) | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
...i/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
asyncapi: 2.3.0 | ||
info: | ||
title: test solace binding | ||
version: 1.0.0 | ||
servers: | ||
theName: | ||
url: some.com | ||
protocol: solace | ||
bindings: | ||
solace: | ||
msgVpn: test | ||
bindingVersion: 1.2.3 | ||
thisKeyIsNotAllowed: should throw validation error | ||
channels: | ||
some-channel: | ||
publish: | ||
bindings: | ||
solace: | ||
bindingVersion: 0.3.0 | ||
destinations: | ||
- destinationType: queue | ||
queue: | ||
name: CreatedHREvents | ||
thisKeyIsNotAllowed: should throw validation error | ||
topicSubscriptions: | ||
- person/*/created | ||
- destinationType: topic | ||
topic: | ||
thisKeyIsNotAllowed: should throw validation error | ||
topicSubscriptions: | ||
- person/*/updated | ||
thisKeyIsNotAllowed: should throw validation error |
38 changes: 38 additions & 0 deletions
38
...cli/shared/src/test/resources/validations/reports/async20/solace-binding-extra-key.report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ModelId: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml | ||
Profile: | ||
Conforms: false | ||
Number of results: 4 | ||
|
||
Level: Violation | ||
|
||
- Constraint: http://a.ml/vocabularies/amf/parser#closed-shape | ||
Message: Property 'thisKeyIsNotAllowed' not supported in a ASYNC 2.3 SolaceServerBinding node | ||
Severity: Violation | ||
Target: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml#/async-api/server/some.com/server-bindings/bindings/solace-server | ||
Property: | ||
Range: [(13,8)-(14,0)] | ||
Location: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml | ||
|
||
- Constraint: http://a.ml/vocabularies/amf/parser#closed-shape | ||
Message: Property 'thisKeyIsNotAllowed' not supported in a ASYNC 2.3 SolaceOperationQueue node | ||
Severity: Violation | ||
Target: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml#/async-api/endpoint/some-channel/supportedOperation/publish/operation-bindings/bindings/solace-operation/destinations/solace-destination/solace-queue | ||
Property: | ||
Range: [(24,16)-(25,0)] | ||
Location: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml | ||
|
||
- Constraint: http://a.ml/vocabularies/amf/parser#closed-shape | ||
Message: Property 'thisKeyIsNotAllowed' not supported in a ASYNC 2.3 SolaceOperationTopic node | ||
Severity: Violation | ||
Target: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml#/async-api/endpoint/some-channel/supportedOperation/publish/operation-bindings/bindings/solace-operation/destinations/solace-destination_1/solace-topic | ||
Property: | ||
Range: [(29,16)-(30,0)] | ||
Location: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml | ||
|
||
- Constraint: http://a.ml/vocabularies/amf/parser#closed-shape | ||
Message: Property 'thisKeyIsNotAllowed' not supported in a ASYNC 2.3 SolaceOperationBinding node | ||
Severity: Violation | ||
Target: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml#/async-api/endpoint/some-channel/supportedOperation/publish/operation-bindings/bindings/solace-operation | ||
Property: | ||
Range: [(32,10)-(32,60)] | ||
Location: file://amf-cli/shared/src/test/resources/validations/async20/validations/solace-binding-extra-key.yaml |
Oops, something went wrong.