Repository: swagger-api/swagger-parser
Pull request #1563 (2021-05-12 14:23:56)

Bug/1562 path body
expressive 'body' schemas that make them much easier to map mentally to the related path.

https://github.com/swagger-api/swagger-parser/issues/1562


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
index 7d02c7c2..cd97f892 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/InlineModelResolver.java
@@ -64,241 +64,267 @@ public class InlineModelResolver {
             openAPI.setComponents(new Components());
         }
         Map<String, Schema> models = openAPI.getComponents().getSchemas();
+        flattenPaths(paths);
+        flattenDefinitions(models);
+    }
 
-        if (paths != null) {
-            for (String pathname : paths.keySet()) {
-                PathItem path = paths.get(pathname);
-
-                for (Operation operation : path.readOperations()) {
-                    RequestBody body = operation.getRequestBody();
-
-                    if (body != null) {
-                        if (body.getContent() != null) {
-                            Map<String,MediaType> content = body.getContent();
-                            for(String key: content.keySet()) {
-                                if (content.get(key) != null) {
-                                    MediaType mediaType = content.get(key);
-                                    if (mediaType.getSchema() != null) {
-                                        Schema model = mediaType.getSchema();
-                                        if (model.getProperties() != null && model.getProperties().size() > 0) {
-                                            flattenProperties(model.getProperties(), pathname);
-                                            String modelName = resolveModelName(model.getTitle(), "body");
-                                            mediaType.setSchema(new Schema().$ref(modelName));
-                                            addGenerated(modelName, model);
-                                            openAPI.getComponents().addSchemas(modelName, model);
-                                        } else if (model instanceof ComposedSchema) {
-                                            flattenComposedSchema(model, pathname);
-                                            if (model.get$ref() == null) {
-                                                String modelName = resolveModelName(model.getTitle(), "body");
-                                                mediaType.setSchema(this.makeRefProperty(modelName, model));
-                                                addGenerated(modelName, model);
-                                                openAPI.getComponents().addSchemas(modelName, model);
-                                            }
-                                        } else if (model instanceof ArraySchema) {
-                                            ArraySchema am = (ArraySchema) model;
-                                            Schema inner = am.getItems();
-                                            if (isObjectSchema(inner)) {
-                                                if (inner.getProperties() != null && inner.getProperties().size() > 0) {
-                                                    flattenProperties(inner.getProperties(), pathname);
-                                                    String modelName = resolveModelName(inner.getTitle(), "body");
-                                                    String existing = matchGenerated(inner);
-                                                    if (existing != null) {
-                                                        am.setItems(new Schema().$ref(existing));
-                                                    } else {
-                                                        am.setItems(new Schema().$ref(modelName));
-                                                        addGenerated(modelName, inner);
-                                                        openAPI.getComponents().addSchemas(modelName, inner);
-                                                    }
-                                                }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
-                                                    flattenComposedSchema(inner,key);
-                                                    if (inner.get$ref() == null) {
-                                                        String modelName = resolveModelName(inner.getTitle(), "inline_body_items_" + key + "_" + pathname);
-                                                        am.setItems(this.makeRefProperty(modelName, inner));
-                                                        addGenerated(modelName, inner);
-                                                        openAPI.getComponents().addSchemas(modelName, inner);
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                    List<Parameter> parameters = operation.getParameters();
-                    if (parameters != null){
-                        for (Parameter parameter : parameters) {
-                            if (parameter.getSchema() != null) {
-                                Schema model = parameter.getSchema();
-                                if (model.getProperties() != null) {
-                                    if (model.getType() == null || "object".equals(model.getType())) {
-                                        if (model.getProperties() != null && model.getProperties().size() > 0) {
-                                            flattenProperties(model.getProperties(), pathname);
-                                            String modelName = resolveModelName(model.getTitle(), parameter.getName());
-                                            parameter.setSchema(new Schema().$ref(modelName));
-                                            addGenerated(modelName, model);
-                                            openAPI.getComponents().addSchemas(modelName, model);
-                                        }
-                                    }
-                                }else if (model instanceof ComposedSchema) {
-                                    String modelName = resolveModelName(model.getTitle(), parameter.getName());
-                                    parameter.setSchema(new Schema().$ref(modelName));
-                                    addGenerated(modelName, model);
-                                    openAPI.getComponents().addSchemas(modelName, model);
-                                }else if (model instanceof ArraySchema) {
-                                    ArraySchema am = (ArraySchema) model;
-                                    Schema inner = am.getItems();
-                                    if (isObjectSchema(inner)) {
-                                        if (inner.getProperties() != null && inner.getProperties().size() > 0) {
-                                            flattenProperties(inner.getProperties(), pathname);
-                                            String modelName = resolveModelName(inner.getTitle(), parameter.getName());
-                                            String existing = matchGenerated(inner);
-                                            if (existing != null) {
-                                                am.setItems(new Schema().$ref(existing));
-                                            } else {
-                                                am.setItems(new Schema().$ref(modelName));
-                                                addGenerated(modelName, am);
-                                                openAPI.getComponents().addSchemas(modelName, am);
-                                            }
-                                        }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
-                                            flattenComposedSchema(inner, parameter.getName());
-                                            if (inner.get$ref() == null) {
-                                                String modelName = resolveModelName(inner.getTitle(), "inline_parameter_items_" + parameter.getName());
-                                                am.setItems(this.makeRefProperty(modelName, inner));
-                                                addGenerated(modelName, inner);
-                                                openAPI.getComponents().addSchemas(modelName, inner);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                    Map<String, ApiResponse> responses = operation.getResponses();
-                    if (responses != null) {
-                        for (String key : responses.keySet()) {
-                            ApiResponse response = responses.get(key);
-                            if (response.getContent() != null) {
-                                Map<String,MediaType> content = response.getContent();
-                                for (String name: content.keySet()) {
-                                    if (content.get(name) != null) {
-                                        MediaType media = content.get(name);
-                                        if (media.getSchema() != null) {
-                                            Schema mediaSchema = media.getSchema();
-                                            if (isObjectSchema(mediaSchema)) {
-                                                if (mediaSchema.getProperties() != null && mediaSchema.getProperties().size() > 0 || mediaSchema instanceof ComposedSchema) {
-                                                    String modelName = resolveModelName(mediaSchema.getTitle(), "inline_response_" + key);
-                                                    String existing = matchGenerated(mediaSchema);
-                                                    if (existing != null) {
-                                                        media.setSchema(this.makeRefProperty(existing, mediaSchema));
-                                                    } else {
-                                                        media.setSchema(this.makeRefProperty(modelName, mediaSchema));
-                                                        addGenerated(modelName, mediaSchema);
-                                                        openAPI.getComponents().addSchemas(modelName, mediaSchema);
-                                                    }
-                                                }else if (mediaSchema.getAdditionalProperties() != null && !(mediaSchema.getAdditionalProperties() instanceof Boolean)) {
-                                                    Schema innerProperty = (Schema) mediaSchema.getAdditionalProperties();
-                                                    if (isObjectSchema(innerProperty)) {
-                                                        key = "inline_response_map" + key;
-                                                        flattenMapSchema(innerProperty, key, pathname, mediaSchema);
-                                                    } else if (innerProperty instanceof ArraySchema) {
-                                                        ArraySchema arraySchema = (ArraySchema) innerProperty;
-                                                        Schema inner = arraySchema.getItems();
-                                                        if (isObjectSchema(inner)) {
-                                                            key = "inline_response_map_items" + key;
-                                                            flattenMapSchema(inner,key,pathname,mediaSchema);
-                                                        }
-                                                    }
-                                                }
-                                            }else if (mediaSchema instanceof ArraySchema) {
-                                                ArraySchema ap = (ArraySchema) mediaSchema;
-                                                Schema inner = ap.getItems();
-                                                if (isObjectSchema(inner)) {
-                                                    flattenArraySchema(inner, key, pathname, ap);
-                                                }
-                                            } else if (mediaSchema.getAdditionalProperties() != null && !(mediaSchema.getAdditionalProperties() instanceof Boolean)) {
-                                                Schema innerProperty = (Schema) mediaSchema.getAdditionalProperties();
-                                                if (isObjectSchema(innerProperty)) {
-                                                    key = "inline_response_map" + key;
-                                                    flattenMapSchema(innerProperty, key, pathname, mediaSchema);
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
+    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()) {
+              flattenBody(pathname, operation.getRequestBody());
+              flattenParams(pathname, operation.getParameters());
+              flattenResponses(pathname, operation.getResponses());
+          }
+      }
+    }
 
-        // definitions
-        if (models != null) {
-            List<String> modelNames = new ArrayList<String>(models.keySet());
-            for (String modelName : modelNames) {
-                Schema model = models.get(modelName);
-                if (model.getProperties() != null) {
-                    Map<String, Schema> properties = model.getProperties();
-                    flattenProperties(properties, modelName);
-                    fixStringModel(model);
-                } else if (model instanceof ArraySchema) {
-                    ArraySchema m = (ArraySchema) model;
-                    Schema inner = m.getItems();
-                    if (isObjectSchema(inner)) {
-                        if (inner.getProperties() != null && inner.getProperties().size() > 0) {
-                            String innerModelName = resolveModelName(inner.getTitle(), modelName + "_inner");
-                            String existing = matchGenerated(inner);
-                            if (existing == null) {
-                                openAPI.getComponents().addSchemas(innerModelName, inner);
-                                addGenerated(innerModelName, inner);
-                                m.setItems(new Schema().$ref(innerModelName));
-                            } else {
-                                m.setItems(new Schema().$ref(existing));
-                            }
-                        }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
-                            flattenComposedSchema(inner,modelName);
-                            if (inner.get$ref() == null) {
-                                modelName = resolveModelName(inner.getTitle(), "inline_array_items_" + modelName);
-                                m.setItems(this.makeRefProperty(modelName, inner));
-                                addGenerated(modelName, inner);
-                                openAPI.getComponents().addSchemas(modelName, inner);
-                            }
-                        }
-                    }
-                } else if (model instanceof ComposedSchema) {
-                    ComposedSchema composedSchema = (ComposedSchema) model;
-                    String inlineModelName = "";
-                    List<Schema> list = null;
-                    if (composedSchema.getAllOf() != null) {
-                        list  = composedSchema.getAllOf();
-                        inlineModelName = "AllOf";
-                    }else if (composedSchema.getAnyOf() != null) {
-                        list  = composedSchema.getAnyOf();
-                        inlineModelName = "AnyOf";
-                    }else if (composedSchema.getOneOf() != null) {
-                        list  = composedSchema.getOneOf();
-                        inlineModelName = "OneOf";
-                    }
+    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);
+              if (mediaType.getSchema() != null) {
+                  Schema model = mediaType.getSchema();
+                  String genericName = pathBody(pathname);
+                  if (model.getProperties() != null && model.getProperties().size() > 0) {
+                      flattenProperties(model.getProperties(), pathname);
+                      String modelName = resolveModelName(model.getTitle(), genericName);
+                      mediaType.setSchema(new Schema().$ref(modelName));
+                      addGenerated(modelName, model);
+                      openAPI.getComponents().addSchemas(modelName, model);
+                  } else if (model instanceof ComposedSchema) {
+                      flattenComposedSchema(model, pathname);
+                      if (model.get$ref() == null) {
+                          String modelName = resolveModelName(model.getTitle(), genericName);
+                          mediaType.setSchema(this.makeRefProperty(modelName, model));
+                          addGenerated(modelName, model);
+                          openAPI.getComponents().addSchemas(modelName, model);
+                      }
+                  } else if (model instanceof ArraySchema) {
+                      ArraySchema am = (ArraySchema) model;
+                      Schema inner = am.getItems();
+                      if (isObjectSchema(inner)) {
+                          if (inner.getProperties() != null && inner.getProperties().size() > 0) {
+                              flattenProperties(inner.getProperties(), pathname);
+                              String modelName = resolveModelName(inner.getTitle(), genericName);
+                              String existing = matchGenerated(inner);
+                              if (existing != null) {
+                                  am.setItems(new Schema().$ref(existing));
+                              } else {
+                                  am.setItems(new Schema().$ref(modelName));
+                                  addGenerated(modelName, inner);
+                                  openAPI.getComponents().addSchemas(modelName, inner);
+                              }
+                          }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
+                              flattenComposedSchema(inner,key);
+                              if (inner.get$ref() == null) {
+                                  String modelName = resolveModelName(inner.getTitle(), "inline_body_items_" + key + "_" + pathname);
+                                  am.setItems(this.makeRefProperty(modelName, inner));
+                                  addGenerated(modelName, inner);
+                                  openAPI.getComponents().addSchemas(modelName, inner);
+                              }
+                          }
+                      }
+                  }
+              }
+          }
+      }
+    }
 
-                    for(int i= 0; i<list.size();i++){
-                        if (list.get(i).get$ref() == null){
-                            Schema inline = list.get(i);
-                            if (inline.getProperties()!= null){
-                                flattenProperties(inline.getProperties(), modelName);
-                            }
-                            if (this.flattenComposedSchemas) {
-                                int position = i+1;
-                                inlineModelName = resolveModelName(inline.getTitle(),  modelName + inlineModelName + "_" + position);
-                                list.set(i,new Schema().$ref(inlineModelName));
-                                addGenerated(inlineModelName, inline);
-                                openAPI.getComponents().addSchemas(inlineModelName, inline);
-                            }
-                        }
-                    }
-                }
-            }
-        }
+    private void flattenParams(String pathname, List<Parameter> parameters)
+    {
+      if (parameters == null){
+        return;
+      }
+      for (Parameter parameter : parameters) {
+          if (parameter.getSchema() != null) {
+              Schema model = parameter.getSchema();
+              if (model.getProperties() != null) {
+                  if (model.getType() == null || "object".equals(model.getType())) {
+                      if (model.getProperties() != null && model.getProperties().size() > 0) {
+                          flattenProperties(model.getProperties(), pathname);
+                          String modelName = resolveModelName(model.getTitle(), parameter.getName());
+                          parameter.setSchema(new Schema().$ref(modelName));
+                          addGenerated(modelName, model);
+                          openAPI.getComponents().addSchemas(modelName, model);
+                      }
+                  }
+              }else if (model instanceof ComposedSchema) {
+                  String modelName = resolveModelName(model.getTitle(), parameter.getName());
+                  parameter.setSchema(new Schema().$ref(modelName));
+                  addGenerated(modelName, model);
+                  openAPI.getComponents().addSchemas(modelName, model);
+              }else if (model instanceof ArraySchema) {
+                  ArraySchema am = (ArraySchema) model;
+                  Schema inner = am.getItems();
+                  if (isObjectSchema(inner)) {
+                      if (inner.getProperties() != null && inner.getProperties().size() > 0) {
+                          flattenProperties(inner.getProperties(), pathname);
+                          String modelName = resolveModelName(inner.getTitle(), parameter.getName());
+                          String existing = matchGenerated(inner);
+                          if (existing != null) {
+                              am.setItems(new Schema().$ref(existing));
+                          } else {
+                              am.setItems(new Schema().$ref(modelName));
+                              addGenerated(modelName, am);
+                              openAPI.getComponents().addSchemas(modelName, am);
+                          }
+                      }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
+                          flattenComposedSchema(inner, parameter.getName());
+                          if (inner.get$ref() == null) {
+                              String modelName = resolveModelName(inner.getTitle(), "inline_parameter_items_" + parameter.getName());
+                              am.setItems(this.makeRefProperty(modelName, inner));
+                              addGenerated(modelName, inner);
+                              openAPI.getComponents().addSchemas(modelName, inner);
+                          }
+                      }
+                  }
+              }
+          }
+      }
+    }
+
+    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) {
+              Map<String,MediaType> content = response.getContent();
+              for (String name: content.keySet()) {
+                  if (content.get(name) != null) {
+                      MediaType media = content.get(name);
+                      if (media.getSchema() != null) {
+                          Schema mediaSchema = media.getSchema();
+                          if (isObjectSchema(mediaSchema)) {
+                              if (mediaSchema.getProperties() != null && mediaSchema.getProperties().size() > 0 || mediaSchema instanceof ComposedSchema) {
+                                  String modelName = resolveModelName(mediaSchema.getTitle(), "inline_response_" + key);
+                                  String existing = matchGenerated(mediaSchema);
+                                  if (existing != null) {
+                                      media.setSchema(this.makeRefProperty(existing, mediaSchema));
+                                  } else {
+                                      media.setSchema(this.makeRefProperty(modelName, mediaSchema));
+                                      addGenerated(modelName, mediaSchema);
+                                      openAPI.getComponents().addSchemas(modelName, mediaSchema);
+                                  }
+                              }else if (mediaSchema.getAdditionalProperties() != null && !(mediaSchema.getAdditionalProperties() instanceof Boolean)) {
+                                  Schema innerProperty = (Schema) mediaSchema.getAdditionalProperties();
+                                  if (isObjectSchema(innerProperty)) {
+                                      key = "inline_response_map" + key;
+                                      flattenMapSchema(innerProperty, key, pathname, mediaSchema);
+                                  } else if (innerProperty instanceof ArraySchema) {
+                                      ArraySchema arraySchema = (ArraySchema) innerProperty;
+                                      Schema inner = arraySchema.getItems();
+                                      if (isObjectSchema(inner)) {
+                                          key = "inline_response_map_items" + key;
+                                          flattenMapSchema(inner,key,pathname,mediaSchema);
+                                      }
+                                  }
+                              }
+                          }else if (mediaSchema instanceof ArraySchema) {
+                              ArraySchema ap = (ArraySchema) mediaSchema;
+                              Schema inner = ap.getItems();
+                              if (isObjectSchema(inner)) {
+                                  flattenArraySchema(inner, key, pathname, ap);
+                              }
+                          } else if (mediaSchema.getAdditionalProperties() != null && !(mediaSchema.getAdditionalProperties() instanceof Boolean)) {
+                              Schema innerProperty = (Schema) mediaSchema.getAdditionalProperties();
+                              if (isObjectSchema(innerProperty)) {
+                                  key = "inline_response_map" + key;
+                                  flattenMapSchema(innerProperty, key, pathname, mediaSchema);
+                              }
+                          }
+                      }
+                  }
+              }
+          }
+      }
+    }
+
+    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);
+          if (model.getProperties() != null) {
+              Map<String, Schema> properties = model.getProperties();
+              flattenProperties(properties, modelName);
+              fixStringModel(model);
+          } else if (model instanceof ArraySchema) {
+              ArraySchema m = (ArraySchema) model;
+              Schema inner = m.getItems();
+              if (isObjectSchema(inner)) {
+                  if (inner.getProperties() != null && inner.getProperties().size() > 0) {
+                      String innerModelName = resolveModelName(inner.getTitle(), modelName + "_inner");
+                      String existing = matchGenerated(inner);
+                      if (existing == null) {
+                          openAPI.getComponents().addSchemas(innerModelName, inner);
+                          addGenerated(innerModelName, inner);
+                          m.setItems(new Schema().$ref(innerModelName));
+                      } else {
+                          m.setItems(new Schema().$ref(existing));
+                      }
+                  }else if (inner instanceof ComposedSchema && this.flattenComposedSchemas){
+                      flattenComposedSchema(inner,modelName);
+                      if (inner.get$ref() == null) {
+                          modelName = resolveModelName(inner.getTitle(), "inline_array_items_" + modelName);
+                          m.setItems(this.makeRefProperty(modelName, inner));
+                          addGenerated(modelName, inner);
+                          openAPI.getComponents().addSchemas(modelName, inner);
+                      }
+                  }
+              }
+          } else if (model instanceof ComposedSchema) {
+              ComposedSchema composedSchema = (ComposedSchema) model;
+              String inlineModelName = "";
+              List<Schema> list = null;
+              if (composedSchema.getAllOf() != null) {
+                  list  = composedSchema.getAllOf();
+                  inlineModelName = "AllOf";
+              }else if (composedSchema.getAnyOf() != null) {
+                  list  = composedSchema.getAnyOf();
+                  inlineModelName = "AnyOf";
+              }else if (composedSchema.getOneOf() != null) {
+                  list  = composedSchema.getOneOf();
+                  inlineModelName = "OneOf";
+              }
+
+              for(int i= 0; i<list.size();i++){
+                  if (list.get(i).get$ref() == null){
+                      Schema inline = list.get(i);
+                      if (inline.getProperties()!= null){
+                          flattenProperties(inline.getProperties(), modelName);
+                      }
+                      if (this.flattenComposedSchemas) {
+                          int position = i+1;
+                          inlineModelName = resolveModelName(inline.getTitle(),  modelName + inlineModelName + "_" + position);
+                          list.set(i,new Schema().$ref(inlineModelName));
+                          addGenerated(inlineModelName, inline);
+                          openAPI.getComponents().addSchemas(inlineModelName, inline);
+                      }
+                  }
+              }
+          }
+      }
     }
 
     private void flattenArraySchema(Schema inner, String key, String pathname, ArraySchema ap) {
@@ -365,6 +391,19 @@ public class InlineModelResolver {
             }
         }
     }
+    
+    private static String pathBody(String pathname)
+    {
+      String[] parts = pathname.split("/");
+      StringBuilder body = new StringBuilder();
+      if (parts.length > 2)
+      {
+        body.append(parts[parts.length-2]);
+      }
+      body.append(parts[parts.length-1]);
+      body.append("Body");
+      return body.toString();
+    }
 
     private String resolveModelName(String title, String key) {
         if (title == null) {


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index 0b1ada61..bebf6c26 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -272,8 +272,8 @@ public class OpenAPIV3ParserTest {
         assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Pagelimit")).getOneOf().get(0).get$ref(),"#/components/schemas/Macaw2");
 
         //requestBodies
-        assertNotNull(openAPI.getComponents().getSchemas().get("Body"));
-        assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Body")).getAllOf().get(1).get$ref(),"#/components/schemas/requestBodiesAllOf2");
+        assertNotNull(openAPI.getComponents().getSchemas().get("RequestBodiesBody"));
+        assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("RequestBodiesBody")).getAllOf().get(1).get$ref(),"#/components/schemas/requestBodiesAllOf2");
         assertNotNull(openAPI.getComponents().getSchemas().get("InlineResponseItems200"));
         assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("InlineBodyItemsApplicationxmlrequestBodies")).getAllOf().get(1).get$ref(),"#/components/schemas/ApplicationxmlAllOf2");
 
@@ -416,9 +416,9 @@ public class OpenAPIV3ParserTest {
 
         OpenAPI openAPI = parseResult.getOpenAPI();
         assertNotNull(openAPI.getComponents().getSchemas().get("status"));
-        assertNotNull(openAPI.getComponents().getSchemas().get("body"));
+        assertNotNull(openAPI.getComponents().getSchemas().get("testBody"));
         assertNotNull(openAPI.getComponents().getSchemas().get("inline_response_200"));
-        assertNotNull(openAPI.getComponents().getSchemas().get("body_1"));
+        assertNotNull(openAPI.getComponents().getSchemas().get("testBody_1"));
         assertNotNull(openAPI.getComponents().getSchemas().get("Test1"));
         assertNotNull(openAPI.getComponents().getSchemas().get("Test2"));
     }
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
index 161f4430..fa96f8a8 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java
@@ -637,7 +637,46 @@ public class InlineModelResolverTest {
         RequestBody body = getOperation.getRequestBody();
         assertTrue(body.getContent().get("*/*").getSchema().get$ref() != null);
 
-        Schema bodySchema = openAPI.getComponents().getSchemas().get("body");
+        Schema bodySchema = openAPI.getComponents().getSchemas().get("helloBody");
+        assertTrue(bodySchema instanceof Schema);
+
+        assertNotNull(bodySchema.getProperties().get("address"));
+    }
+    
+    @Test
+    public void resolveInlineRequestBody_maxTwoPathParts() throws Exception {
+        OpenAPI openAPI = new OpenAPI();
+
+        ObjectSchema objectSchema = new ObjectSchema();
+        objectSchema.addProperties("street", new StringSchema());
+
+        Schema schema = new Schema();
+        schema.addProperties("address", objectSchema);
+        schema.addProperties("name", new StringSchema());
+
+        MediaType mediaType = new MediaType();
+        mediaType.setSchema(schema);
+
+        Content content = new Content();
+        content.addMediaType("*/*", mediaType );
+
+        RequestBody requestBody = new RequestBody();
+        requestBody.setContent(content);
+
+        Operation operation = new Operation();
+        operation.setRequestBody(requestBody);
+
+        PathItem pathItem = new PathItem();
+        pathItem.setGet(operation);
+        openAPI.path("/api/cloud/greet/hello",pathItem);
+
+        new InlineModelResolver().flatten(openAPI);
+
+        Operation getOperation = openAPI.getPaths().get("/api/cloud/greet/hello").getGet();
+        RequestBody body = getOperation.getRequestBody();
+        assertTrue(body.getContent().get("*/*").getSchema().get$ref() != null);
+
+        Schema bodySchema = openAPI.getComponents().getSchemas().get("greethelloBody");
         assertTrue(bodySchema instanceof Schema);
 
         assertNotNull(bodySchema.getProperties().get("address"));
@@ -766,9 +805,9 @@ public class InlineModelResolverTest {
         Schema inner = am.getItems();
         assertTrue(inner.get$ref() != null);
 
-        assertEquals( "#/components/schemas/body",inner.get$ref());
+        assertEquals( "#/components/schemas/helloBody",inner.get$ref());
 
-        Schema inline = openAPI.getComponents().getSchemas().get("body");
+        Schema inline = openAPI.getComponents().getSchemas().get("helloBody");
         assertNotNull(inline);
         assertTrue(inline instanceof Schema);
 
@@ -1052,7 +1091,7 @@ public class InlineModelResolverTest {
         RequestBody requestBody = operation.getRequestBody();
         assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
 
-        Schema body = swagger.getComponents().getSchemas().get("body");
+        Schema body = swagger.getComponents().getSchemas().get("helloBody");
         assertTrue(body instanceof Schema);
 
 
@@ -1114,9 +1153,9 @@ public class InlineModelResolverTest {
         assertTrue(inner.get$ref() != null);
 
 
-        assertEquals(inner.get$ref(), "#/components/schemas/body");
+        assertEquals(inner.get$ref(), "#/components/schemas/helloBody");
 
-        Schema inline = openAPI.getComponents().getSchemas().get("body");
+        Schema inline = openAPI.getComponents().getSchemas().get("helloBody");
         assertNotNull(inline);
 
         Schema p = (Schema)inline.getProperties().get("arbitrary");