Skip to content

Commit 383f0d6

Browse files
authored
Merge pull request #894 from saileshsingh/bugFix2
Fix for issue 892
2 parents 0541677 + 35c1593 commit 383f0d6

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
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);
@@ -2682,6 +2685,7 @@ protected static class ParseResult {
26822685
private Map<Location, JsonNode> unsupported = new LinkedHashMap<>();
26832686
private Map<Location, String> invalidType = new LinkedHashMap<>();
26842687
private List<Location> missing = new ArrayList<>();
2688+
private List<Location> warnings = new ArrayList<>();
26852689
private List<Location> unique = new ArrayList<>();
26862690
private List<Location> uniqueTags = new ArrayList<>();
26872691

@@ -2699,9 +2703,14 @@ public void extra(String location, String key, JsonNode value) {
26992703
public void missing(String location, String key) {
27002704
missing.add(new Location(location, key));
27012705
}
2702-
2706+
2707+
public void warning(String location, String key) {
2708+
warnings.add(new Location(location, key));
2709+
}
2710+
27032711
public void unique(String location, String key) {
27042712
unique.add(new Location(location, key));
2713+
27052714
}
27062715

27072716
public void uniqueTags(String location, String key) {uniqueTags.add(new Location(location,key));}
@@ -2735,6 +2744,11 @@ public List<String> getMessages() {
27352744
String message = "attribute " + location + l.key + " is missing";
27362745
messages.add(message);
27372746
}
2747+
for (Location l : warnings) {
2748+
String location = l.location.equals("") ? "" : l.location + ".";
2749+
String message = "attribute " + location +l.key;
2750+
messages.add(message);
2751+
}
27382752
for (Location l : unsupported.keySet()) {
27392753
String location = l.location.equals("") ? "" : l.location + ".";
27402754
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
@@ -75,6 +75,15 @@ public void testIssue887() {
7575
assertEquals(result.getMessages().get(0), "attribute tags.sample is repeated");
7676
}
7777

78+
@Test
79+
public void testIssue892() {
80+
SwaggerParseResult result = new OpenAPIParser().readLocation("issue892-main.yaml", null, null);
81+
82+
assertEquals(result.getMessages().size(),1);
83+
assertNotNull(result.getOpenAPI());
84+
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
85+
}
86+
7887
@Test
7988
public void testIssue768() {
8089
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)