Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-13925199 Publish 5.4.8 #665

Merged
merged 8 commits into from
Feb 7, 2024
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ val ivyLocal = Resolver.file("ivy", file(Path.userHome.absolutePath + "/.ivy2/lo

name := "amf-core"
ThisBuild / scalaVersion := "2.12.15"
ThisBuild / version := "5.4.7"
ThisBuild / version := "5.4.8"

publish := {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package amf.core.client.scala.traversal.iterator
import amf.core.client.scala.model.document.FieldsFilter
import amf.core.client.scala.model.domain.{AmfArray, AmfElement, AmfObject, DomainElement}

import scala.collection.mutable
import scala.annotation.tailrec

case class DomainElementIterator private (var buffer: List[AmfElement], visited: VisitedCollector) extends AmfIterator {
case class DomainElementIterator private (
var buffer: List[AmfElement],
visited: VisitedCollector,
fieldsFilter: FieldsFilter
) extends AmfIterator {

override def hasNext: Boolean = buffer.nonEmpty

Expand All @@ -14,6 +19,7 @@ case class DomainElementIterator private (var buffer: List[AmfElement], visited:
current
}

@tailrec
private def advance(): Unit = {
if (buffer.nonEmpty) {
val current = buffer.head
Expand All @@ -23,16 +29,7 @@ case class DomainElementIterator private (var buffer: List[AmfElement], visited:
} else {
current match {
case obj: AmfObject =>
val elements = obj.fields.fields().map(_.element).toList
visited += obj
obj match {
case domain: DomainElement =>
buffer = domain :: elements ++ buffer
// advance finishes here because a non visited domain element was found
case _ =>
buffer = elements ++ buffer
advance()
}
advanceObject(obj)
case arr: AmfArray =>
buffer = arr.values.toList ++ buffer
advance()
Expand All @@ -43,12 +40,36 @@ case class DomainElementIterator private (var buffer: List[AmfElement], visited:
}
}

private def advanceObject(obj: AmfObject): Unit = {
val elements = fieldsFilter.filter(obj.fields)
visited += obj
obj match {
case domain: DomainElement =>
buffer = domain :: elements ++ buffer
// advance finishes here because a non visited domain element was found
case _ =>
buffer = elements ++ buffer
advance()
}
}
}

object DomainElementIterator {
def apply(
elements: List[AmfElement],
visited: VisitedCollector = IdCollector()
): DomainElementIterator = {
val iterator = new DomainElementIterator(elements, visited, FieldsFilter.All)
iterator.advance()
iterator
}

def apply(elements: List[AmfElement], visited: VisitedCollector = IdCollector()): DomainElementIterator = {
val iterator = new DomainElementIterator(elements, visited)
def withFilter(
elements: List[AmfElement],
visited: VisitedCollector = IdCollector(),
fieldsFilter: FieldsFilter = FieldsFilter.Local
): DomainElementIterator = {
val iterator = new DomainElementIterator(elements, visited, fieldsFilter)
iterator.advance()
iterator
}
Expand Down
54 changes: 54 additions & 0 deletions shared/src/main/scala/amf/core/internal/remote/Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ object Spec {
case Oas30.id => Some(Oas30)
case AwsOas30.id => Some(AwsOas30)
case AsyncApi20.id => Some(AsyncApi20)
case AsyncApi21.id => Some(AsyncApi21)
case AsyncApi22.id => Some(AsyncApi22)
case AsyncApi23.id => Some(AsyncApi23)
case AsyncApi24.id => Some(AsyncApi24)
case AsyncApi25.id => Some(AsyncApi25)
case AsyncApi26.id => Some(AsyncApi26)
case Amf.id => Some(Amf)
case Payload.id => Some(Payload)
case Aml.id => Some(Aml)
Expand All @@ -39,6 +45,12 @@ object Spec {
@JSExport val OAS30: Spec = Oas30
@JSExport val AWS_OAS30: Spec = AwsOas30
@JSExport val ASYNC20: Spec = AsyncApi20
@JSExport val ASYNC21: Spec = AsyncApi21
@JSExport val ASYNC22: Spec = AsyncApi22
@JSExport val ASYNC23: Spec = AsyncApi23
@JSExport val ASYNC24: Spec = AsyncApi24
@JSExport val ASYNC25: Spec = AsyncApi25
@JSExport val ASYNC26: Spec = AsyncApi26
@JSExport val AMF: Spec = Amf
@JSExport val PAYLOAD: Spec = Payload
@JSExport val AML: Spec = Aml
Expand Down Expand Up @@ -146,6 +158,48 @@ private[amf] case object AsyncApi20 extends Async {

}

private[amf] case object AsyncApi21 extends Async {
override def version: String = "2.1"

override val mediaType: String = `application/yaml`

}

private[amf] case object AsyncApi22 extends Async {
override def version: String = "2.2"

override val mediaType: String = `application/yaml`

}

private[amf] case object AsyncApi23 extends Async {
override def version: String = "2.3"

override val mediaType: String = `application/yaml`

}

private[amf] case object AsyncApi24 extends Async {
override def version: String = "2.4"

override val mediaType: String = `application/yaml`

}

private[amf] case object AsyncApi25 extends Async {
override def version: String = "2.5"

override val mediaType: String = `application/yaml`

}

private[amf] case object AsyncApi26 extends Async {
override def version: String = "2.6"

override val mediaType: String = `application/yaml`

}

private[amf] case object Amf extends Spec {
override val id: String = "AMF Graph"

Expand Down