diff --git a/modules/compiler-core/src-2/internals/ExtensionsPlatform.scala b/modules/compiler-core/src-2/internals/ExtensionsPlatform.scala new file mode 100644 index 0000000..50c3e0f --- /dev/null +++ b/modules/compiler-core/src-2/internals/ExtensionsPlatform.scala @@ -0,0 +1,35 @@ +/* Copyright 2022 Disney Streaming + * + * Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://disneystreaming.github.io/TOST-1.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smithytranslate.compiler +package internals + +import scala.language.reflectiveCalls +import scala.jdk.CollectionConverters._ + +trait ExtensionsPlatform { + // Using reflective calls because openapi does not seem to have a common interface + // that exposes the presence of extensions. + type HasExtensions = { def getExtensions(): java.util.Map[String, Any] } + object HasExtensions { + def unsafeFrom(s: Any): HasExtensions = s.asInstanceOf[HasExtensions] + } + + def getExtensions(s: HasExtensions) = + Option(s) + .flatMap(s => Option(s.getExtensions())) + .map(_.asScala) + .filterNot(_.isEmpty) +} diff --git a/modules/compiler-core/src-3/internals/ExtensionsPlatform.scala b/modules/compiler-core/src-3/internals/ExtensionsPlatform.scala new file mode 100644 index 0000000..39c819a --- /dev/null +++ b/modules/compiler-core/src-3/internals/ExtensionsPlatform.scala @@ -0,0 +1,36 @@ +/* Copyright 2022 Disney Streaming + * + * Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://disneystreaming.github.io/TOST-1.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smithytranslate.compiler +package internals + +import scala.language.reflectiveCalls +import scala.jdk.CollectionConverters._ +import reflect.Selectable.reflectiveSelectable + +trait ExtensionsPlatform { + // Using reflective calls because openapi does not seem to have a common interface + // that exposes the presence of extensions. + type HasExtensions = { def getExtensions(): java.util.Map[String, Any] } + object HasExtensions { + def unsafeFrom(s: Any): HasExtensions = s.asInstanceOf[HasExtensions] + } + + def getExtensions(s: HasExtensions) = + Option(s) + .flatMap(s => Option(s.getExtensions())) + .map(_.asScala) + .filterNot(_.isEmpty) +} diff --git a/modules/compiler-core/src/internals/GetExtensions.scala b/modules/compiler-core/src/internals/GetExtensions.scala index 310c661..d0c7484 100644 --- a/modules/compiler-core/src/internals/GetExtensions.scala +++ b/modules/compiler-core/src/internals/GetExtensions.scala @@ -18,27 +18,16 @@ package internals import software.amazon.smithy.model.node.Node import scala.jdk.CollectionConverters._ -import scala.language.reflectiveCalls import smithytranslate.compiler.internals._ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.{node => jackson} import java.time.format.DateTimeFormatter import java.time.ZoneId -private[compiler] object GetExtensions { - - // Using reflective calls because openapi does not seem to have a common interface - // that exposes the presence of extensions. - type HasExtensions = { def getExtensions(): java.util.Map[String, Any] } - object HasExtensions { - def unsafeFrom(s: Any): HasExtensions = s.asInstanceOf[HasExtensions] - } +private[compiler] object GetExtensions extends ExtensionsPlatform { def from(s: HasExtensions): List[Hint] = - Option(s) - .flatMap(s => Option(s.getExtensions())) - .map(_.asScala) - .filterNot(_.isEmpty) + getExtensions(s) .map[Hint] { ext => val nodeMap = ext.map { case (k, v) => (k, anyToNode(v))