forked from loafle/openapi-generator-original
added error handling
This commit is contained in:
parent
84e17c7707
commit
852eb0bf49
@ -31,16 +31,25 @@ object ApiExtractor extends RemoteUrl {
|
|||||||
implicit val formats = SwaggerSerializers.formats
|
implicit val formats = SwaggerSerializers.formats
|
||||||
|
|
||||||
def fetchApiListings(basePath: String, apis: List[ApiListingReference], apiKey: Option[String] = None): List[ApiListing] = {
|
def fetchApiListings(basePath: String, apis: List[ApiListingReference], apiKey: Option[String] = None): List[ApiListing] = {
|
||||||
for (api <- apis) yield {
|
(for (api <- apis) yield {
|
||||||
val json = basePath.startsWith("http") match {
|
try{
|
||||||
case true => {
|
val json = basePath.startsWith("http") match {
|
||||||
println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")))
|
case true => {
|
||||||
urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))
|
println("calling: " + ((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json")))
|
||||||
}
|
urlToString((basePath + api.path + apiKey.getOrElse("")).replaceAll(".\\{format\\}", ".json"))
|
||||||
case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
|
}
|
||||||
}
|
case false => Source.fromFile((basePath + api.path).replaceAll(".\\{format\\}", ".json")).mkString
|
||||||
parse(json).extract[ApiListing]
|
}
|
||||||
}
|
Some(parse(json).extract[ApiListing])
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
case e:java.io.FileNotFoundException => {
|
||||||
|
println("WARNING! Unable to read API " + basePath + api.path)
|
||||||
|
None
|
||||||
|
}
|
||||||
|
case _ => None
|
||||||
|
}
|
||||||
|
}).flatten.toList
|
||||||
}
|
}
|
||||||
|
|
||||||
def extractApiOperations(basePath: String, references: List[ApiListingReference], apiKey: Option[String] = None) = {
|
def extractApiOperations(basePath: String, references: List[ApiListingReference], apiKey: Option[String] = None) = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user