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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Build with Maven
env:
MAVEN_OPTS: -Dhttps.protocols=TLSv1.2 -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true -Dmaven.wagon.http.retryHandler.count=10
run: mvn --batch-mode --errors --update-snapshots package --file pom.xml
run: mvn --batch-mode --errors --update-snapshots verify --file pom.xml
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,15 @@ public JsonValue buildRouteJson(final OpenAPI spec, final File specFile,
routeName, specFile.getName(), condition, baseUri != null ? baseUri : "<none>",
failOnResponseViolation, mockMode);

// Normalise the platform path separator to '/': this path is embedded in an EL
// read('...') string literal, where a Windows backslash (D:\...) is parsed as an
// (invalid) escape sequence. Forward slashes are accepted by read()/File on every OS.
final String absolutePath = specFile.getAbsolutePath();
final String specPath = absolutePath == null ? null : absolutePath.replace(File.separatorChar, '/');

// ----- heap: OpenApiValidationFilter entry -----
final Map<String, Object> validatorConfig = new LinkedHashMap<>();
validatorConfig.put("spec", "${read('" + specFile.getAbsolutePath() + "')}");
validatorConfig.put("spec", "${read('" + specPath + "')}");
validatorConfig.put("failOnResponseViolation", failOnResponseViolation);

final Map<String, Object> validatorHeapObject = new LinkedHashMap<>();
Expand All @@ -125,7 +131,7 @@ public JsonValue buildRouteJson(final OpenAPI spec, final File specFile,
if (mockMode) {
// ----- heap: OpenApiMockResponseHandler entry -----
final Map<String, Object> mockConfig = new LinkedHashMap<>();
mockConfig.put("spec", "${read('" + specFile.getAbsolutePath() + "')}");
mockConfig.put("spec", "${read('" + specPath + "')}");

final Map<String, Object> mockHeapObject = new LinkedHashMap<>();
mockHeapObject.put("name", MOCK_HANDLER_HEAP_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public void buildRouteJson_validatorHeapObjectHasAbsoluteSpecFilePath() throws I
.orElseThrow(() -> new AssertionError("No OpenApiValidationFilter in heap"));

final java.util.Map<?, ?> config = (java.util.Map<?, ?>) validatorEntry.get("config");
assertThat(config.get("spec").toString()).contains(spec.getAbsolutePath());
// OpenApiRouteBuilder normalises the platform separator to '/' for the read() literal.
assertThat(config.get("spec").toString()).contains(spec.getAbsolutePath().replace(File.separatorChar, '/'));
}

@Test
Expand Down Expand Up @@ -342,7 +343,8 @@ public void buildRouteJson_mockMode_mockHandlerConfigContainsSpecPath() throws I
.orElseThrow(() -> new AssertionError("No OpenApiMockResponseHandler in heap"));

final java.util.Map<?, ?> config = (java.util.Map<?, ?>) mockEntry.get("config");
assertThat(config.get("spec").toString()).contains(spec.getAbsolutePath());
// OpenApiRouteBuilder normalises the platform separator to '/' for the read() literal.
assertThat(config.get("spec").toString()).contains(spec.getAbsolutePath().replace(File.separatorChar, '/'));
}


Expand Down
2 changes: 1 addition & 1 deletion openig-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>integration-test</phase>
<id>integration-test</id>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void testMockRoute_petCollection() throws IOException {
.atMost(30, SECONDS)
.until(() -> routeAvailable(ROUTE_ID));

// GET /v2/pet/findByStatus?status=available → 200 JSON array
// GET /v2.1/pet/findByStatus?status=available → 200 JSON array
final String body = RestAssured
.given()
.when()
.get("/v2/pet/findByStatus?status=available")
.get("/v2.1/pet/findByStatus?status=available")
.then()
.statusCode(200)
.contentType("application/json")
Expand All @@ -99,7 +99,7 @@ public void testMockRoute_petCollection() throws IOException {
// Parse and assert array contents
@SuppressWarnings("unchecked")
final List<Map<String, Object>> pets =
RestAssured.given().when().get("/v2/pet/findByStatus?status=available")
RestAssured.given().when().get("/v2.1/pet/findByStatus?status=available")
.jsonPath().getList("$");

assertThat(pets).isNotEmpty();
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testMockRoute_petCollection() throws IOException {
.until(() -> !routeAvailable(ROUTE_ID));

RestAssured.given().when()
.get("/v2/pet/findByStatus?status=available")
.get("/v2.1/pet/findByStatus?status=available")
.then()
.statusCode(404);
}
Expand Down Expand Up @@ -161,10 +161,10 @@ public void testMockRoute_singlePet() throws IOException {
.atMost(30, SECONDS)
.until(() -> routeAvailable("petstore-mock-single"));

// GET /v2/pet/{petId} → single object
// GET /v2.1/pet/{petId} → single object
@SuppressWarnings("unchecked")
final Map<String, Object> pet =
RestAssured.given().when().get("/v2/pet/42")
RestAssured.given().when().get("/v2.1/pet/42")
.then()
.statusCode(200)
.contentType("application/json")
Expand Down Expand Up @@ -216,6 +216,8 @@ private static String getSpecFilePath() throws IOException {
Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
}
tmp.toFile().deleteOnExit();
return tmp.toAbsolutePath().toString();
// Use forward slashes: the path is substituted into the route JSON and an EL read('...')
// expression, where a Windows backslash path (C:\...) is an invalid JSON/EL escape.
return tmp.toAbsolutePath().toString().replace('\\', '/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public void testSwaggerRoute() throws IOException {
@Test
public void testCustomRoute() throws IOException {
String testConfigPath = getTestConfigPath();
String openApiSpec = this.getClass().getClassLoader().getResource("routes/petstore.yaml").getPath();
// Use forward slashes: the path is substituted into the route JSON and an EL read('...')
// expression, where a Windows backslash path (D:\...) is an invalid JSON/EL escape.
String openApiSpec = this.getClass().getClassLoader().getResource("routes/petstore.yaml").getPath().replace('\\', '/');
String routeContents = IOUtils.resourceToString("routes/01-find-pet.json", StandardCharsets.UTF_8, this.getClass().getClassLoader())
.replace("$$SWAGGER_FILE$$", openApiSpec);
Path destination = Path.of(testConfigPath, "config", "routes", "01-find-pet.json");
Expand Down
4 changes: 2 additions & 2 deletions openig-war/src/test/resources/routes/01-find-pet.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swagger-petstore-test",
"condition": "${(matches(request.uri.path, '^/v2/pet/findByStatus$') && matches(request.method, '^GET$'))}",
"baseURI": "http://localhost:8090/v2",
"condition": "${(matches(request.uri.path, '^/v2.1/pet/findByStatus$') && matches(request.method, '^GET$'))}",
"baseURI": "http://localhost:8090/v2.1",
"heap": [
{
"name": "OpenApiValidator",
Expand Down
2 changes: 1 addition & 1 deletion openig-war/src/test/resources/routes/petstore-mock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "petstore-mock",
"condition": "${matches(request.uri.path, '^/v2/')}",
"condition": "${matches(request.uri.path, '^/v2.1/')}",
"heap": [
{
"name": "PetstoreMock",
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<argLine>${java.surefire.options}</argLine>
</configuration>
</plugin>

<plugin>
Expand Down
Loading