
com.twilio.guardrail.ReadSwagger.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guardrail_2.12 Show documentation
Show all versions of guardrail_2.12 Show documentation
Principled code generation for Scala services from OpenAPI specifications
The newest version!
package com.twilio.guardrail
import scala.collection.JavaConverters._
import java.nio.file.Path
import java.util
import io.swagger.parser.OpenAPIParser
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.parser.core.models.ParseOptions
case class ReadSwagger[T](path: Path, next: OpenAPI => T)
object ReadSwagger {
def readSwagger[T](rs: ReadSwagger[Target[T]]): Target[T] =
if (rs.path.toFile.exists()) {
val opts = new ParseOptions()
opts.setResolve(true)
val result = new OpenAPIParser().readLocation(rs.path.toAbsolutePath.toString, new util.LinkedList(), opts)
Option(result.getMessages()).foreach(_.asScala.foreach(println))
Target
.fromOption(
Option(result.getOpenAPI),
UserError(s"Spec file ${rs.path} is incorrectly formatted.")
)
.flatMap(rs.next(_))
} else {
Target.raiseError(UserError(s"Spec file ${rs.path} does not exist."))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy