refactor: to smaller methods that make modifications possible
@@ -64,17 +64,36 @@ public class InlineModelResolver {
openAPI.setComponents(new Components());
}
Map<String, Schema> models = openAPI.getComponents().getSchemas();
+ flattenPaths(paths);
+ flattenDefinitions(models);
+ }
- if (paths != null) {
+ private void flattenPaths(Map<String, PathItem> paths)
+ {
+ if (paths == null) {
+ return;
+ }
for (String pathname : paths.keySet()) {
PathItem path = paths.get(pathname);
for (Operation operation : path.readOperations()) {
- RequestBody body = operation.getRequestBody();
+ flattenBody(pathname, operation.getRequestBody());
+ flattenParams(pathname, operation.getParameters());
+ flattenResponses(pathname, operation.getResponses());
+ }
+ }
+ }
- if (body != null) {
- if (body.getContent() != null) {
+ private void flattenBody(String pathname, RequestBody body)
+ {
+ if (body == null) {
+ return;
+ }
Map<String,MediaType> content = body.getContent();
+ if (content == null)
+ {
+ return;
+ }
for(String key: content.keySet()) {
if (content.get(key) != null) {
MediaType mediaType = content.get(key);
@@ -124,9 +143,12 @@ public class InlineModelResolver {
}
}
}
+
+ private void flattenParams(String pathname, List<Parameter> parameters)
+ {
+ if (parameters == null){
+ return;
}
- List<Parameter> parameters = operation.getParameters();
- if (parameters != null){
for (Parameter parameter : parameters) {
if (parameter.getSchema() != null) {
Schema model = parameter.getSchema();
@@ -174,8 +196,12 @@ public class InlineModelResolver {
}
}
}
- Map<String, ApiResponse> responses = operation.getResponses();
- if (responses != null) {
+
+ private void flattenResponses(String pathname, Map<String, ApiResponse> responses)
+ {
+ if (responses == null) {
+ return;
+ }
for (String key : responses.keySet()) {
ApiResponse response = responses.get(key);
if (response.getContent() != null) {
@@ -229,12 +255,12 @@ public class InlineModelResolver {
}
}
}
- }
- }
- }
- // definitions
- if (models != null) {
+ private void flattenDefinitions(Map<String, Schema> models)
+ {
+ if (models == null) {
+ return;
+ }
List<String> modelNames = new ArrayList<String>(models.keySet());
for (String modelName : modelNames) {
Schema model = models.get(modelName);
@@ -299,7 +325,6 @@ public class InlineModelResolver {
}
}
}
- }
private void flattenArraySchema(Schema inner, String key, String pathname, ArraySchema ap) {
if (inner.getProperties() != null && inner.getProperties().size() > 0) {
