Skip to content

Commit 1956db1

Browse files
committed
allow camel-case separation for anonymous inner body types
1 parent edd3537 commit 1956db1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,13 @@ private static String pathBody(String pathname)
398398
StringBuilder body = new StringBuilder();
399399
if (parts.length > 2)
400400
{
401-
body.append(parts[parts.length-2]);
401+
body.append(parts[parts.length-2].replace(".", "_")).append('_');
402402
}
403-
body.append(parts[parts.length-1]);
404-
body.append("Body");
403+
if (parts.length > 1)
404+
{
405+
body.append(parts[parts.length-1].replace(".", "_")).append('_');
406+
}
407+
body.append("body");
405408
return body.toString();
406409
}
407410

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/InlineModelResolverTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public void resolveInlineRequestBody() throws Exception {
637637
RequestBody body = getOperation.getRequestBody();
638638
assertTrue(body.getContent().get("*/*").getSchema().get$ref() != null);
639639

640-
Schema bodySchema = openAPI.getComponents().getSchemas().get("helloBody");
640+
Schema bodySchema = openAPI.getComponents().getSchemas().get("hello_body");
641641
assertTrue(bodySchema instanceof Schema);
642642

643643
assertNotNull(bodySchema.getProperties().get("address"));
@@ -676,7 +676,7 @@ public void resolveInlineRequestBody_maxTwoPathParts() throws Exception {
676676
RequestBody body = getOperation.getRequestBody();
677677
assertTrue(body.getContent().get("*/*").getSchema().get$ref() != null);
678678

679-
Schema bodySchema = openAPI.getComponents().getSchemas().get("greethelloBody");
679+
Schema bodySchema = openAPI.getComponents().getSchemas().get("greet_hello_body");
680680
assertTrue(bodySchema instanceof Schema);
681681

682682
assertNotNull(bodySchema.getProperties().get("address"));
@@ -805,9 +805,9 @@ public void resolveInlineArrayRequestBody() throws Exception {
805805
Schema inner = am.getItems();
806806
assertTrue(inner.get$ref() != null);
807807

808-
assertEquals( "#/components/schemas/helloBody",inner.get$ref());
808+
assertEquals( "#/components/schemas/hello_body",inner.get$ref());
809809

810-
Schema inline = openAPI.getComponents().getSchemas().get("helloBody");
810+
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
811811
assertNotNull(inline);
812812
assertTrue(inline instanceof Schema);
813813

@@ -1091,7 +1091,7 @@ public void testArbitraryObjectRequestBodyInline() {
10911091
RequestBody requestBody = operation.getRequestBody();
10921092
assertTrue(requestBody.getContent().get("*/*").getSchema().get$ref() != null);
10931093

1094-
Schema body = swagger.getComponents().getSchemas().get("helloBody");
1094+
Schema body = swagger.getComponents().getSchemas().get("hello_body");
10951095
assertTrue(body instanceof Schema);
10961096

10971097

@@ -1153,9 +1153,9 @@ public void testArbitraryObjectBodyParamArrayInline() {
11531153
assertTrue(inner.get$ref() != null);
11541154

11551155

1156-
assertEquals(inner.get$ref(), "#/components/schemas/helloBody");
1156+
assertEquals(inner.get$ref(), "#/components/schemas/hello_body");
11571157

1158-
Schema inline = openAPI.getComponents().getSchemas().get("helloBody");
1158+
Schema inline = openAPI.getComponents().getSchemas().get("hello_body");
11591159
assertNotNull(inline);
11601160

11611161
Schema p = (Schema)inline.getProperties().get("arbitrary");

0 commit comments

Comments
 (0)