Skip to content

Commit 639bafb

Browse files
mma5997frantuma
authored andcommitted
Added a parseOption for keeping up with backward compatibility
Added 2 parseOptions considering the current behaviour when resolve set to true - 1> resolveRequestBody - default is false 2> resolveResponses - default is true These 2 options will be applicable only when resolve is true.
1 parent 81e79e2 commit 639bafb

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ modules/swagger-parser/src/test/resources/relative-file-references/yaml
1212
**/test-output/*
1313
dependency-reduced-pom.xml
1414
*.pyc
15+
/bin/

modules/swagger-parser-core/src/main/java/io/swagger/v3/parser/core/models/ParseOptions.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public class ParseOptions {
1212
private boolean validateExternalRefs = false;
1313
private boolean validateInternalRefs = true;
1414
private boolean legacyYamlDeserialization = false;
15-
15+
private boolean resolveRequestBody = false;
16+
private boolean resolveResponses = true;
17+
1618
public boolean isResolve() {
1719
return resolve;
1820
}
@@ -36,6 +38,30 @@ public boolean isResolveFully() {
3638
public void setResolveFully(boolean resolveFully) {
3739
this.resolveFully = resolveFully;
3840
}
41+
42+
public boolean isResolveRequestBody() {
43+
return resolveRequestBody;
44+
}
45+
46+
/**
47+
* If set to true, will help resolving the requestBody as inline, provided resolve is also set to true.
48+
* Default is false because of the existing behaviour.
49+
*/
50+
public void setResolveRequestBody(boolean resolveRequestBody) {
51+
this.resolveRequestBody = resolveRequestBody;
52+
}
53+
54+
public boolean isResolveResponses() {
55+
return resolveResponses;
56+
}
57+
58+
/**
59+
* If set to true, will help resolving the responses as inline, provided resolve is also set to true.
60+
* Default is true because of the existing behaviour.
61+
*/
62+
public void setResolveResponses(boolean resolveResponses) {
63+
this.resolveResponses = resolveResponses;
64+
}
3965

4066
public boolean isFlatten() { return flatten; }
4167

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/ResolverCache.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ public class ResolverCache {
6868
private Map<String, String> externalFileCache = new HashMap<>();
6969
private List<String> referencedModelKeys = new ArrayList<>();
7070
private Set<String> resolveValidationMessages;
71-
7271
private final ParseOptions parseOptions;
7372

7473

75-
/*
74+
/*
7675
a map that stores original external references, and their associated renamed references
7776
*/
7877
private Map<String, String> renameCache = new HashMap<>();
@@ -394,4 +393,8 @@ public Map<String, String> getExternalFileCache() {
394393
public Map<String, String> getRenameCache() {
395394
return Collections.unmodifiableMap(renameCache);
396395
}
396+
397+
public ParseOptions getParseOptions() {
398+
return parseOptions;
399+
}
397400
}

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/OperationProcessor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public OperationProcessor(ResolverCache cache, OpenAPI openAPI) {
3131
this.responseProcessor = new ResponseProcessor(cache,openAPI);
3232
this.requestBodyProcessor = new RequestBodyProcessor(cache,openAPI);
3333
this.externalRefProcessor = new ExternalRefProcessor(cache, openAPI);
34-
3534
this.cache = cache;
3635
}
3736

@@ -42,8 +41,8 @@ public void processOperation(Operation operation) {
4241
}
4342
RequestBody requestBody = operation.getRequestBody();
4443
if(requestBody != null) {
45-
//This part allows paser to put requestBody schema inline without the resolveFully option set to true
46-
if (requestBody.get$ref() != null) {
44+
//This part allows paser to put requestBody inline without the resolveFully option set to true
45+
if (requestBody.get$ref() != null && cache != null && cache.getParseOptions() != null && cache.getParseOptions().isResolveRequestBody()) {
4746
requestBodyProcessor.processRequestBody(requestBody);
4847
RefFormat refFormat = computeRefFormat(requestBody.get$ref());
4948
RequestBody resolvedRequestBody = cache.loadRef(requestBody.get$ref(), refFormat, RequestBody.class);
@@ -62,8 +61,8 @@ public void processOperation(Operation operation) {
6261
for (String responseCode : responses.keySet()) {
6362
ApiResponse response = responses.get(responseCode);
6463
if(response != null) {
65-
//This part allows parser to put response schema inline without the resolveFully option set to true
66-
if (response.get$ref() != null) {
64+
//This part allows parser to put response inline without the resolveFully option set to true
65+
if (response.get$ref() != null && cache != null && cache.getParseOptions() != null && cache.getParseOptions().isResolveResponses()) {
6766

6867
responseProcessor.processResponse(response);
6968

0 commit comments

Comments
 (0)