Skip to content

Commit 577c8e6

Browse files
committed
Fix for issue 892
Warn message is missing when the path key doesn't start with slash
1 parent a566237 commit 577c8e6

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ public Paths getPaths(ObjectNode obj, String location, ParseResult result) {
524524
if (!pathValue.getNodeType().equals(JsonNodeType.OBJECT)) {
525525
result.invalidType(location, pathName, "object", pathValue);
526526
} else {
527+
if(!pathName.startsWith("/")){
528+
result.warning(location," Resource "+pathName+ " should start with /");
529+
}
527530
ObjectNode path = (ObjectNode) pathValue;
528531
PathItem pathObj = getPathItem(path,String.format("%s.'%s'", location,pathName), result);
529532
paths.put(pathName, pathObj);
@@ -2670,6 +2673,7 @@ protected static class ParseResult {
26702673
private Map<Location, JsonNode> unsupported = new LinkedHashMap<>();
26712674
private Map<Location, String> invalidType = new LinkedHashMap<>();
26722675
private List<Location> missing = new ArrayList<>();
2676+
private List<Location> warnings = new ArrayList<>();
26732677

26742678
public ParseResult() {
26752679
}
@@ -2686,6 +2690,10 @@ public void missing(String location, String key) {
26862690
missing.add(new Location(location, key));
26872691
}
26882692

2693+
public void warning(String location, String key) {
2694+
warnings.add(new Location(location, key));
2695+
}
2696+
26892697
public void invalidType(String location, String key, String expectedType, JsonNode value) {
26902698
invalidType.put(new Location(location, key), expectedType);
26912699
}
@@ -2715,6 +2723,11 @@ public List<String> getMessages() {
27152723
String message = "attribute " + location + l.key + " is missing";
27162724
messages.add(message);
27172725
}
2726+
for (Location l : warnings) {
2727+
String location = l.location.equals("") ? "" : l.location + ".";
2728+
String message = "attribute " + location +l.key;
2729+
messages.add(message);
2730+
}
27182731
for (Location l : unsupported.keySet()) {
27192732
String location = l.location.equals("") ? "" : l.location + ".";
27202733
String message = "attribute " + location + l.key + " is unsupported";

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public void testSimple() {
6464
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
6565
}
6666

67+
@Test
68+
public void testIssue892() {
69+
SwaggerParseResult result = new OpenAPIParser().readLocation("issue892-main.yaml", null, null);
70+
71+
assertEquals(result.getMessages().size(),1);
72+
assertNotNull(result.getOpenAPI());
73+
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
74+
}
75+
6776
@Test
6877
public void testIssue768() {
6978
ParseOptions options = new ParseOptions();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: 3.0.1
2+
info:
3+
title: ping test
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost:8000/'
7+
paths:
8+
some/ping:
9+
get:
10+
operationId: pingGet
11+
parameters:
12+
- name: i
13+
in: query
14+
description: Test
15+
required: true
16+
schema:
17+
$ref: './issue749-reference.yaml#/SomeId'
18+
responses:
19+
'201':
20+
description: OK
21+
components:
22+
schemas: {}

0 commit comments

Comments
 (0)