Skip to content

Commit ddf9363

Browse files
authored
Merge pull request #104 from apiaddicts/develop
Develop
2 parents 6848eea + dcf9412 commit ddf9363

9 files changed

Lines changed: 80 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.6] - 2026-05-05
9+
10+
### Fixed
11+
- External `$ref` tests no longer require outbound internet access. Fixtures
12+
are now served by a local HTTP server (`ExternalRefHttpServer`) on
13+
`http://localhost:18089`, started in `BaseCheckTest`. Affected tests:
14+
OAR031 (v2/v3), OAR094, OAR068, OAR086.
15+
816
## [1.3.5] - 2026-04-08
917

1018
### Fixed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
55
<artifactId>sonaropenapi-rules-community</artifactId>
6-
<version>1.3.5</version>
6+
<version>1.3.6</version>
77
<packaging>sonar-plugin</packaging>
88

99
<name>SonarQube OpenAPI Community Rules</name>

src/test/java/apiaddicts/sonar/openapi/BaseCheckTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import org.apiaddicts.apitools.dosonarapi.api.OpenApiCheck;
1010

11+
import apiaddicts.sonar.openapi.utils.ExternalRefHttpServer;
12+
1113
import java.util.Arrays;
1214
import java.util.HashSet;
1315
import java.util.List;
@@ -77,6 +79,7 @@ private void verify(String file, boolean isV2, boolean isV3, boolean isV31) {
7779

7880
@BeforeClass
7981
public static void beforeClass() {
82+
ExternalRefHttpServer.start();
8083
I18nContext.setLang("en");
8184
if (repository != null) return;
8285
OpenAPICustomRulesDefinition rulesDefinition = new OpenAPICustomRulesDefinition();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package apiaddicts.sonar.openapi.utils;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.net.InetSocketAddress;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
import java.nio.file.Paths;
9+
10+
import com.sun.net.httpserver.HttpExchange;
11+
import com.sun.net.httpserver.HttpServer;
12+
13+
public final class ExternalRefHttpServer {
14+
15+
public static final int PORT = 18089;
16+
public static final String BASE_URL = "http://localhost:" + PORT;
17+
18+
private static final Path FIXTURES = Paths.get("src", "test", "resources", "externalRef").toAbsolutePath().normalize();
19+
20+
private static HttpServer server;
21+
22+
private ExternalRefHttpServer() {
23+
}
24+
25+
public static synchronized void start() {
26+
if (server != null) {
27+
return;
28+
}
29+
try {
30+
HttpServer s = HttpServer.create(new InetSocketAddress("127.0.0.1", PORT), 0);
31+
s.createContext("/", ExternalRefHttpServer::handle);
32+
s.setExecutor(null);
33+
s.start();
34+
Runtime.getRuntime().addShutdownHook(new Thread(() -> s.stop(0)));
35+
server = s;
36+
} catch (IOException e) {
37+
throw new IllegalStateException("Could not start external ref HTTP server on port " + PORT, e);
38+
}
39+
}
40+
41+
private static void handle(HttpExchange exchange) throws IOException {
42+
try {
43+
String name = exchange.getRequestURI().getPath().replaceFirst("^/+", "");
44+
Path file = FIXTURES.resolve(name).normalize();
45+
if (!file.startsWith(FIXTURES) || !Files.isRegularFile(file)) {
46+
exchange.sendResponseHeaders(404, -1);
47+
return;
48+
}
49+
byte[] body = Files.readAllBytes(file);
50+
exchange.getResponseHeaders().set("Content-Type", "application/yaml; charset=utf-8");
51+
exchange.sendResponseHeaders(200, body.length);
52+
try (OutputStream os = exchange.getResponseBody()) {
53+
os.write(body);
54+
}
55+
} finally {
56+
exchange.close();
57+
}
58+
}
59+
}

src/test/resources/checks/v2/examples/OAR031/externalref.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ paths:
1818
$ref: '#/definitions/User'
1919
400:
2020
$ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}}
21-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR031.yaml#/components/responses/server_error_response
21+
http://localhost:18089/OAR031.yaml#/components/responses/server_error_response
2222
/users/{userId}:
2323
get:
2424
parameters:

src/test/resources/checks/v3/examples/OAR031/externalref.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ paths:
2424
$ref: '#/components/schemas/User'
2525
'400':
2626
$ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}}
27-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR031.yaml#/components/responses/server_error_response
27+
http://localhost:18089/OAR031.yaml#/components/responses/server_error_response
2828
/users/{userId}:
2929
get:
3030
summary: Get a user by ID
@@ -48,7 +48,7 @@ paths:
4848
$ref: '#/components/schemas/User'
4949
'400':
5050
$ref: >- # Noncompliant {{OAR031: Responses must have one or more examples defined}}
51-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR031.yaml#/components/responses/server_error_response
51+
http://localhost:18089/OAR031.yaml#/components/responses/server_error_response
5252
components:
5353
schemas:
5454
User:

src/test/resources/checks/v3/examples/OAR094/externalref.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ paths:
3636
application/json:
3737
schema:
3838
$ref: >- # Noncompliant {{OAR094: It is recommended to use examples instead of example as some tools like microcks use this section of the definition}}
39-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR094.yaml#/components/schemas/Pet
39+
http://localhost:18089/OAR094.yaml#/components/schemas/Pet
4040
'400':
4141
description: Bad Request.
4242
headers:
@@ -48,7 +48,7 @@ paths:
4848
application/json:
4949
schema:
5050
$ref: >- # Noncompliant {{OAR094: It is recommended to use examples instead of example as some tools like microcks use this section of the definition}}
51-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR094.yaml#/components/schemas/ErrorMessage
51+
http://localhost:18089/OAR094.yaml#/components/schemas/ErrorMessage
5252
example: # Noncompliant {{OAR094: It is recommended to use examples instead of example as some tools like microcks use this section of the definition}}
5353
error:
5454
status: '400'

src/test/resources/checks/v3/format/OAR068/externalref.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ paths:
3636
application/json:
3737
schema: # Noncompliant {{OAR068: RequestBody and Responses schema property names must be compliant with the PascalCase naming convention}}
3838
$ref: >-
39-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR068.yaml#/components/schemas/datosUsuario
39+
http://localhost:18089/OAR068.yaml#/components/schemas/datosUsuario
4040
'400':
4141
description: Bad Request.
4242
headers:
@@ -48,7 +48,7 @@ paths:
4848
application/json:
4949
schema: # Noncompliant {{OAR068: RequestBody and Responses schema property names must be compliant with the PascalCase naming convention}}
5050
$ref: >-
51-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR086.yaml#/components/schemas/ErrorMessage
51+
http://localhost:18089/OAR086.yaml#/components/schemas/ErrorMessage
5252
example:
5353
error:
5454
status: '400'

src/test/resources/checks/v3/format/OAR086/external-refexample.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ paths:
3636
application/json:
3737
schema:
3838
$ref: >- # Noncompliant {{OAR086: Descriptions must begin with a capital letter, end with a period and not be empty}}
39-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR086.yaml#/components/schemas/datosUsuario
39+
http://localhost:18089/OAR086.yaml#/components/schemas/datosUsuario
4040
'400':
4141
description: Bad Request.
4242
headers:
@@ -48,7 +48,7 @@ paths:
4848
application/json:
4949
schema:
5050
$ref: >- # Noncompliant {{OAR086: Descriptions must begin with a capital letter, end with a period and not be empty}}
51-
https://raw.githubusercontent.com/apiaddicts/sonaropenapi-rules/refs/heads/master/src/test/resources/externalRef/OAR086.yaml#/components/schemas/ErrorMessage
51+
http://localhost:18089/OAR086.yaml#/components/schemas/ErrorMessage
5252
example:
5353
error:
5454
status: '400'

0 commit comments

Comments
 (0)