Skip to content

Commit 5a6ed9d

Browse files
authored
Merge pull request #574 from swagger-api/bugfix/resolving-references-options
Resolve References Options in Parser
2 parents bd0c7e5 + 50f8098 commit 5a6ed9d

File tree

2 files changed

+283
-248
lines changed

2 files changed

+283
-248
lines changed

modules/swagger-parser/src/main/java/io/swagger/parser/SwaggerParser.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ public SwaggerDeserializationResult readWithInfo(String location, List<Authoriza
2020
if (location == null) {
2121
return null;
2222
}
23-
location = location.replaceAll("\\\\","/");
23+
location = location.replaceAll("\\\\", "/");
2424
List<SwaggerParserExtension> parserExtensions = getExtensions();
2525
SwaggerDeserializationResult output;
2626

27-
if(auths == null) {
27+
if (auths == null) {
2828
auths = new ArrayList<AuthorizationValue>();
2929
}
3030

3131
output = new Swagger20Parser().readWithInfo(location, auths);
3232
if (output != null) {
33-
if(output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
34-
if(resolve) {
33+
if (output.getSwagger() != null && "2.0".equals(output.getSwagger().getSwagger())) {
34+
if (resolve) {
3535
output.setSwagger(new SwaggerResolver(output.getSwagger(), auths, location).resolve());
3636
}
3737
return output;
@@ -43,9 +43,9 @@ public SwaggerDeserializationResult readWithInfo(String location, List<Authoriza
4343
return output;
4444
}
4545
}
46-
if(output == null) {
46+
if (output == null) {
4747
output = new SwaggerDeserializationResult()
48-
.message("The swagger definition could not be read");
48+
.message("The swagger definition could not be read");
4949
}
5050
return output;
5151
}
@@ -58,7 +58,7 @@ public Swagger read(String location, List<AuthorizationValue> auths, boolean res
5858
if (location == null) {
5959
return null;
6060
}
61-
location = location.replaceAll("\\\\","/");
61+
location = location.replaceAll("\\\\", "/");
6262
Swagger output;
6363

6464
try {
@@ -87,7 +87,11 @@ public Swagger read(String location, List<AuthorizationValue> auths, boolean res
8787
}
8888

8989
public SwaggerDeserializationResult readWithInfo(String swaggerAsString) {
90-
if(swaggerAsString == null) {
90+
return readWithInfo(swaggerAsString, Boolean.TRUE);
91+
}
92+
93+
public SwaggerDeserializationResult readWithInfo(String swaggerAsString, boolean resolve) {
94+
if (swaggerAsString == null) {
9195
return new SwaggerDeserializationResult().message("empty or null swagger supplied");
9296
}
9397
try {
@@ -101,14 +105,14 @@ public SwaggerDeserializationResult readWithInfo(String swaggerAsString) {
101105

102106
SwaggerDeserializationResult result = new Swagger20Parser().readWithInfo(node);
103107
if (result != null) {
104-
result.setSwagger(new SwaggerResolver(result.getSwagger(), new ArrayList<AuthorizationValue>(), null).resolve());
105-
}
106-
else {
107-
result = new SwaggerDeserializationResult().message("Definition does not appear to be a valid Swagger format");
108+
if (resolve) {
109+
result.setSwagger(new SwaggerResolver(result.getSwagger(), new ArrayList<AuthorizationValue>(), null).resolve());
110+
}
111+
} else {
112+
result = new SwaggerDeserializationResult().message("Definition does not appear to be a valid Swagger format");
108113
}
109114
return result;
110-
}
111-
catch (Exception e) {
115+
} catch (Exception e) {
112116
return new SwaggerDeserializationResult().message("malformed or unreadable swagger supplied");
113117
}
114118
}
@@ -148,10 +152,9 @@ public Swagger read(JsonNode node, List<AuthorizationValue> authorizationValues,
148152
try {
149153
output = new Swagger20Parser().read(node);
150154
if (output != null) {
151-
if(resolve) {
155+
if (resolve) {
152156
return new SwaggerResolver(output, authorizationValues).resolve();
153-
}
154-
else {
157+
} else {
155158
return output;
156159
}
157160
}

0 commit comments

Comments
 (0)