Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,18 @@ public String uniqueName(String key) {
int count = 0;
boolean done = false;
if (camelCaseFlattenNaming) {
String uniqueKey;
String concatenated = "";
for (int i = 0; i < key.split("[-|\\s|_]").length; i++) {
uniqueKey = key.split("[-|\\s|_]")[i];
for (String uniqueKey : key.split("[-|\\s|_]")) {
if (uniqueKey.isEmpty()) {
continue;
}
uniqueKey = uniqueKey.substring(0, 1).toUpperCase() + uniqueKey.substring(1);
concatenated = concatenated.concat(uniqueKey);
}
key = concatenated.replaceAll("[^a-z_\\.A-Z0-9 ]", ""); // FIXME: a parameter
if (key.isEmpty()) {
key = "inline_object";
}
}else {
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", ""); // FIXME: a parameter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,31 @@ public void testInlineItemsSchema() {
assertNotNull(openAPI.getComponents().getSchemas().get("inline_response_200"));
}

@Test(description = "https://github.com/swagger-api/swagger-parser/issues/2386")
public void testUniqueNameSkipsEmptyTokensFromLeadingSeparators() {
OpenAPI openAPI = new OpenAPI();
openAPI.setComponents(new Components());
InlineModelResolver resolver = new InlineModelResolver(false, true);
resolver.flatten(openAPI);

assertEquals("MyModel", resolver.uniqueName(" my model"));
assertEquals("Foo", resolver.uniqueName("-foo"));
assertEquals("Foo", resolver.uniqueName("_foo"));
assertEquals("FooBar", resolver.uniqueName("foo--bar"));
assertEquals("inline_object", resolver.uniqueName(""));
assertEquals("inline_object", resolver.uniqueName("---"));
}

@Test(description = "https://github.com/swagger-api/swagger-parser/issues/2386")
public void testFlattenSchemaTitleWithLeadingSeparator() {
String title = " my model";
OpenAPI openAPI = openAPIWithInlineResponseSchema(title);

new InlineModelResolver(false, true).flatten(openAPI);

assertFlattenedResponseSchema(openAPI, "MyModel", "#/components/schemas/MyModel");
}

@Test(description = "https://github.com/swagger-api/swagger-parser/issues/1200")
public void testSchemaPropertiesBeingPassedToFlattenedModel() {
OpenAPI openAPI = new OpenAPI();
Expand Down