Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,15 @@ class JsonProcessor : OpenApiProcessor {
return
}

if (!hasScheme (apiPath)) {
apiPath = "file://${apiPath}"
}
apiPath = toURL(apiPath).toString()

var targetDir: String? = options["targetDir"]?.toString()
if (targetDir == null) {
println("openapi-processor-json: missing targetDir!")
return
}

if (!hasScheme (targetDir)) {
targetDir = "file://${targetDir}"
}
targetDir = toURL(targetDir).toString()

val opts = ParseOptions()
val result: SwaggerParseResult = OpenAPIV3Parser()
Expand All @@ -83,12 +79,32 @@ class JsonProcessor : OpenApiProcessor {
targetPath.toFile().writeText(json)
}

private fun hasScheme(path: String?): Boolean {
if (path == null) {
return false
/**
* convert source to a valid URL.
*
* if the source is an url string it converts it to an URL
* if the source is not an URL it assumes a local path and prefixes it with file://(//) to
* create a valid URL.
*
* @param source source path or url
* @return an URL to the given source
*/
private fun toURL(source: String): URL {
try {
return URL(source)
} catch (ignore: Exception) {
// catch
}

return path.indexOf ("://") > -1
try {
return Paths.get(source)
.normalize ()
.toUri ()
.toURL ()
} catch (e: Exception) {
throw e
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class JsonProcessorSpec extends Specification {
if (e != a) {
printUnifiedDiff(new File(expJson), new File(targetPath))
}
e == a

e.replace('\r', '') == a.replace('\r', '')
}

private void printUnifiedDiff (File expected, File generated) {
Expand Down