@@ -56,19 +56,15 @@ class JsonProcessor : OpenApiProcessor {
56
56
return
57
57
}
58
58
59
- if (! hasScheme (apiPath)) {
60
- apiPath = " file://${apiPath} "
61
- }
59
+ apiPath = toURL(apiPath).toString()
62
60
63
61
var targetDir: String? = options[" targetDir" ]?.toString()
64
62
if (targetDir == null ) {
65
63
println (" openapi-processor-json: missing targetDir!" )
66
64
return
67
65
}
68
66
69
- if (! hasScheme (targetDir)) {
70
- targetDir = " file://${targetDir} "
71
- }
67
+ targetDir = toURL(targetDir).toString()
72
68
73
69
val opts = ParseOptions ()
74
70
val result: SwaggerParseResult = OpenAPIV3Parser ()
@@ -83,12 +79,32 @@ class JsonProcessor : OpenApiProcessor {
83
79
targetPath.toFile().writeText(json)
84
80
}
85
81
86
- private fun hasScheme (path : String? ): Boolean {
87
- if (path == null ) {
88
- return false
82
+ /* *
83
+ * convert source to a valid URL.
84
+ *
85
+ * if the source is an url string it converts it to an URL
86
+ * if the source is not an URL it assumes a local path and prefixes it with file://(//) to
87
+ * create a valid URL.
88
+ *
89
+ * @param source source path or url
90
+ * @return an URL to the given source
91
+ */
92
+ private fun toURL (source : String ): URL {
93
+ try {
94
+ return URL (source)
95
+ } catch (ignore: Exception ) {
96
+ // catch
89
97
}
90
98
91
- return path.indexOf (" ://" ) > - 1
99
+ try {
100
+ return Paths .get(source)
101
+ .normalize ()
102
+ .toUri ()
103
+ .toURL ()
104
+ } catch (e: Exception ) {
105
+ throw e
106
+ }
92
107
}
93
108
109
+
94
110
}
0 commit comments