Skip to content

Commit bc13155

Browse files
committed
refactoring
1 parent 84b3443 commit bc13155

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

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

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.swagger.v3.parser.util;
22

3+
import io.swagger.v3.oas.models.Components;
34
import io.swagger.v3.oas.models.OpenAPI;
45
import io.swagger.v3.oas.models.Operation;
56
import io.swagger.v3.oas.models.PathItem;
7+
import io.swagger.v3.oas.models.Paths;
68
import io.swagger.v3.oas.models.callbacks.Callback;
79
import io.swagger.v3.oas.models.examples.Example;
810
import io.swagger.v3.oas.models.headers.Header;
@@ -57,50 +59,51 @@ public ResolverFully(boolean aggregateCombinators) {
5759
private Map<String, Schema> resolvedProperties = new HashMap<>();
5860

5961
public void resolveFully(OpenAPI openAPI) {
60-
if (openAPI.getComponents() != null && openAPI.getComponents().getRequestBodies() != null) {
61-
requestBodies = openAPI.getComponents().getRequestBodies();
62+
Components components = openAPI.getComponents();
63+
if (components != null && components.getRequestBodies() != null) {
64+
requestBodies = components.getRequestBodies();
6265
if (requestBodies == null) {
6366
requestBodies = new HashMap<>();
6467
}
6568
}
6669

67-
if (openAPI.getComponents() != null && openAPI.getComponents().getSchemas() != null) {
68-
schemas = openAPI.getComponents().getSchemas();
70+
if (components != null && components.getSchemas() != null) {
71+
schemas = components.getSchemas();
6972
if (schemas == null) {
7073
schemas = new HashMap<>();
7174
}
7275
}
7376

74-
if (openAPI.getComponents() != null && openAPI.getComponents().getExamples() != null) {
75-
examples = openAPI.getComponents().getExamples();
77+
if (components != null && components.getExamples() != null) {
78+
examples = components.getExamples();
7679
if (examples == null) {
7780
examples = new HashMap<>();
7881
}
7982
}
8083

81-
if (openAPI.getComponents() != null && openAPI.getComponents().getHeaders() != null) {
82-
headers = openAPI.getComponents().getHeaders();
84+
if (components != null && components.getHeaders() != null) {
85+
headers = components.getHeaders();
8386
if (headers == null) {
8487
headers = new HashMap<>();
8588
}
8689
}
8790

88-
if (openAPI.getComponents() != null && openAPI.getComponents().getParameters() != null) {
89-
parameters = openAPI.getComponents().getParameters();
91+
if (components != null && components.getParameters() != null) {
92+
parameters = components.getParameters();
9093
if (parameters == null) {
9194
parameters = new HashMap<>();
9295
}
9396
}
94-
if (openAPI.getComponents() != null && openAPI.getComponents().getLinks() != null) {
95-
links = openAPI.getComponents().getLinks();
97+
if (components != null && components.getLinks() != null) {
98+
links = components.getLinks();
9699
if (links == null) {
97100
links = new HashMap<>();
98101
}
99102
}
100-
101-
if(openAPI.getPaths() != null) {
102-
for (String pathname : openAPI.getPaths().keySet()) {
103-
PathItem pathItem = openAPI.getPaths().get(pathname);
103+
Paths paths = openAPI.getPaths();
104+
if(paths != null) {
105+
for (String pathname : paths.keySet()) {
106+
PathItem pathItem = paths.get(pathname);
104107
resolvePath(pathItem);
105108
}
106109
}
@@ -278,7 +281,6 @@ public Schema resolveSchema(Schema schema) {
278281
// if we make it without a resolution loop, we can update the reference
279282
resolvedModels.put(ref, model);
280283

281-
282284
return model;
283285

284286
}else {
@@ -289,15 +291,7 @@ public Schema resolveSchema(Schema schema) {
289291
if(schema instanceof ArraySchema) {
290292
ArraySchema arrayModel = (ArraySchema) schema;
291293
if(arrayModel.getItems().get$ref() != null) {
292-
String ref= arrayModel.getItems().get$ref();
293-
ref = ref.substring(ref.lastIndexOf("/") + 1);
294-
if (resolvedModels.get(ref) == null) {
295-
arrayModel.setItems(resolveSchema(arrayModel.getItems()));
296-
}else{
297-
arrayModel.setItems(resolvedModels.get(ref));
298-
//validar que tan profundo estoy en la recursion para cortar con la asignacion de propiedades.
299-
arrayModel.getItems().set$ref(arrayModel.getItems().get$ref());
300-
}
294+
arrayModel.setItems(resolveSchema(arrayModel.getItems()));
301295
} else {
302296
arrayModel.setItems(arrayModel.getItems());
303297
}

0 commit comments

Comments
 (0)