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

Commit 0b8c446

Browse files
authored
Merge pull request #13 from openapi-processor/build-matrix
windows fixes
2 parents 9feb8f5 + 477e795 commit 0b8c446

File tree

7 files changed

+138
-34
lines changed

7 files changed

+138
-34
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ on:
1010
jobs:
1111
build:
1212

13-
runs-on: ubuntu-latest
13+
# runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest, windows-latest]
1418

1519
steps:
1620
- uses: actions/checkout@v1
@@ -19,7 +23,7 @@ jobs:
1923
with:
2024
java-version: 11.0.2
2125
- name: build
22-
run: ./gradlew build --stacktrace
26+
run: ./gradlew build --refresh-dependencies --stacktrace
2327
- name: archive artifacts
2428
uses: actions/upload-artifact@v1
2529
if: success()

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ dependencies {
112112
}
113113

114114
testImplementation "io.openapiprocessor:openapi-processor-api:$processorApiVersion"
115-
testImplementation ('io.openapiprocessor:openapi-processor-test:1.0.0') {
115+
testImplementation ('io.openapiprocessor:openapi-processor-test:1.0.1') {
116116
exclude group: 'com.google.guava'
117117
}
118118

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2020 the original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.hauner.openapi.core.misc
18+
19+
import java.nio.file.Paths
20+
21+
/**
22+
* helper to convert a source url/path to an URL.
23+
*
24+
* @author Martin Hauner
25+
*/
26+
class URL {
27+
28+
/**
29+
* convert source to a valid URL.
30+
*
31+
* if the source is an url string it converts it to an URL
32+
* if the source is not an URL it assumes a local path and prefixes it with file://(//) to
33+
* create a valid URL.
34+
*
35+
* @param source source path or url
36+
* @return an URL to the given source
37+
*/
38+
static java.net.URL toURL (String source) {
39+
try {
40+
return new java.net.URL (source)
41+
} catch (Exception ignore) {
42+
// catch
43+
}
44+
45+
try {
46+
Paths.get (source)
47+
.normalize ()
48+
.toUri ()
49+
.toURL ()
50+
} catch (Exception e) {
51+
throw e
52+
}
53+
}
54+
55+
}

src/main/groovy/com/github/hauner/openapi/core/parser/openapi4j/Parser.groovy

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import org.openapi4j.parser.OpenApi3Parser
2222
import org.openapi4j.parser.model.v3.OpenApi3
2323
import org.openapi4j.parser.validation.v3.OpenApi3Validator
2424

25+
import static com.github.hauner.openapi.core.misc.URL.toURL
26+
2527
/**
2628
* openapi4j parser.
2729
*
@@ -30,12 +32,8 @@ import org.openapi4j.parser.validation.v3.OpenApi3Validator
3032
class Parser {
3133

3234
ParserOpenApi parse (String apiPath) {
33-
if (!hasScheme (apiPath)) {
34-
apiPath = "file:${apiPath}"
35-
}
36-
3735
OpenApi3 api = new OpenApi3Parser ()
38-
.parse (new URL (apiPath), true)
36+
.parse (toURL (apiPath), true)
3937

4038
ValidationResults results = OpenApi3Validator
4139
.instance ()
@@ -44,8 +42,4 @@ class Parser {
4442
new OpenApi (api, results)
4543
}
4644

47-
static boolean hasScheme (String path) {
48-
path.indexOf (":") > -1
49-
}
50-
5145
}

src/main/groovy/com/github/hauner/openapi/core/parser/swagger/Parser.groovy

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import io.swagger.v3.parser.OpenAPIV3Parser
2121
import io.swagger.v3.parser.core.models.ParseOptions
2222
import io.swagger.v3.parser.core.models.SwaggerParseResult
2323

24+
import static com.github.hauner.openapi.core.misc.URL.toURL
25+
2426
/**
2527
* swagger parser.
2628
*
@@ -42,26 +44,21 @@ class Parser {
4244
}
4345

4446
private static String preparePath (String path) {
45-
// the swagger parser works with http(s) & file protocols only.
47+
// the swagger parser only works with http(s) & file protocols.
48+
4649
// If it is something different (or nothing) it tries to find the given path as-is on the
4750
// file system. If that fails it tries to load the path as resource.
4851

4952
if (isResource (path)) {
50-
// strip resource: (only used by tests) to load it from resources
51-
path.substring (SCHEME_RESOURCE.size ())
52-
} else if (hasScheme (path)) {
53-
"file:${path}"
54-
} else {
55-
path
53+
// strip resource: (only used by tests) to load test files from the resources
54+
return path.substring (SCHEME_RESOURCE.size ())
5655
}
56+
57+
toURL (path).toString ()
5758
}
5859

5960
static boolean isResource (String path) {
6061
path.startsWith (SCHEME_RESOURCE)
6162
}
6263

63-
static boolean hasScheme (String path) {
64-
path.indexOf (":") > -1
65-
}
66-
6764
}

src/main/groovy/com/github/hauner/openapi/core/writer/java/ApiWriter.groovy

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import groovy.util.logging.Slf4j
2828
import java.nio.file.Files
2929
import java.nio.file.Path
3030

31+
import static com.github.hauner.openapi.core.misc.URL.toURL
32+
3133
/**
3234
* Root writer for the generated api files.
3335
*
@@ -127,9 +129,9 @@ class ApiWriter {
127129
}
128130

129131
private void createTargetFolders () {
130-
def rootPkg = options.packageName.replace ('.', File.separator)
131-
def apiPkg = [rootPkg, 'api'].join (File.separator)
132-
def modelPkg = [rootPkg, 'model'].join (File.separator)
132+
def rootPkg = options.packageName.replace ('.', '/')
133+
def apiPkg = [rootPkg, 'api'].join ('/')
134+
def modelPkg = [rootPkg, 'model'].join ('/')
133135
log.debug ('creating target folders: {}', rootPkg)
134136

135137
apiFolder = createTargetPackage (apiPkg)
@@ -141,17 +143,11 @@ class ApiWriter {
141143

142144
private Path createTargetPackage (String apiPkg) {
143145
String root = options.targetDir
144-
if (!hasScheme (root)) {
145-
root = "file://${root}"
146-
}
146+
String pkg = [root, apiPkg].join ('/')
147147

148-
def target = Path.of (new URL ([root, apiPkg].join ('/')).toURI ())
148+
def target = Path.of (toURL(pkg).toURI ())
149149
Files.createDirectories (target)
150150
target
151151
}
152152

153-
private boolean hasScheme (String source) {
154-
source.indexOf ("://") > -1
155-
}
156-
157153
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2020 the original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.openapiprocessor.core.misc
18+
19+
import spock.lang.IgnoreIf
20+
import spock.lang.Requires
21+
import spock.lang.Specification
22+
import spock.lang.Unroll
23+
24+
25+
import static com.github.hauner.openapi.core.misc.URL.toURL
26+
27+
class PathSpec extends Specification {
28+
29+
@Unroll
30+
@Requires({ os.windows })
31+
void "convert source to url on windows" () {
32+
def resultUrl = toURL (source)
33+
34+
expect:
35+
resultUrl.toString () == url
36+
37+
where:
38+
source | url
39+
"file:////C:/somewhere/openapi-processor-samples/samples" | "file:////C:/somewhere/openapi-processor-samples/samples"
40+
"C:\\somewhere\\openapi-processor-samples\\samples" | "file:/C:/somewhere/openapi-processor-samples/samples"
41+
}
42+
43+
@Unroll
44+
@IgnoreIf({ os.windows })
45+
void "convert source to url on unix (#source)" () {
46+
def resultUrl = toURL (source)
47+
48+
expect:
49+
resultUrl.toString () == url
50+
51+
where:
52+
source | url
53+
"file:///somewhere/openapi-processor-samples/samples" | "file:/somewhere/openapi-processor-samples/samples"
54+
"https:///somewhere/openapi-processor-samples/samples" | "https:/somewhere/openapi-processor-samples/samples"
55+
"/somewhere/openapi-processor-samples/samples" | "file:/somewhere/openapi-processor-samples/samples"
56+
}
57+
58+
}

0 commit comments

Comments
 (0)