Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 585fb42

Browse files
committed
improve path creation
1 parent 13a89d7 commit 585fb42

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.support
7+
8+
import java.net.URI
9+
import java.nio.file.Paths
10+
11+
/**
12+
* convert a source string to a valid URI.
13+
*
14+
* if the source is an uri string it converts it to a URI. If the source has no scheme it assumes
15+
* a local path and adds the file scheme (i.e. file:).
16+
*
17+
* @param source source path or url
18+
* @return a URI to the given source
19+
*/
20+
fun toURI(source: String): URI {
21+
try {
22+
val uri = URI(source)
23+
if (uri.scheme != null) {
24+
return uri
25+
}
26+
27+
// no scheme, assume file path
28+
return Paths.get(source)
29+
.normalize()
30+
.toAbsolutePath()
31+
.toUri()
32+
} catch (e: Exception) {
33+
throw e
34+
}
35+
}

src/main/kotlin/io/openapiprocessor/core/writer/java/ApiWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import io.openapiprocessor.core.model.Api
1212
import io.openapiprocessor.core.model.Interface
1313
import io.openapiprocessor.core.model.datatypes.InterfaceDataType
1414
import io.openapiprocessor.core.model.datatypes.StringEnumDataType
15-
import io.openapiprocessor.core.support.toURL
1615
import io.openapiprocessor.core.model.datatypes.ModelDataType
16+
import io.openapiprocessor.core.support.toURI
1717
import java.io.BufferedWriter
1818
import java.io.StringWriter
1919
import java.io.Writer
@@ -151,7 +151,7 @@ class ApiWriter(
151151
val root = options.targetDir
152152
val pkg = listOf(root, apiPkg).joinToString("/")
153153

154-
val target = Paths.get (toURL(pkg).toURI())
154+
val target = Paths.get (toURI(pkg))
155155
Files.createDirectories(target)
156156
return target
157157
}

0 commit comments

Comments
 (0)