Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed -Add underscores automatically when space are present #182 #192

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -20,10 +20,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static java.io.File.separator;

Expand Down Expand Up @@ -196,6 +193,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
//System.out.println("key = " + entryProp.getKey() + " value = " + entryProp.getValue());
Map<String, Any> propMap = new HashMap<>();
String name = entryProp.getKey();
name = name.trim().replaceAll(" ", "_");
propMap.put("jsonProperty", Any.wrap(name));
if(name.startsWith("@")) {
name = name.substring(1);
Expand Down Expand Up @@ -242,6 +240,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
if("enum".equals(entryElement.getKey())) {
propMap.put("isEnum", Any.wrap(true));
propMap.put("nameWithEnum", Any.wrap(name.substring(0, 1).toUpperCase() + name.substring(1) + "Enum"));
this.addUnderscores(entryElement);
propMap.put("value", Any.wrap(entryElement.getValue()));
}
if("format".equals(entryElement.getKey())) {
Expand Down Expand Up @@ -460,4 +459,15 @@ private static String getBasePath(OpenApi3 openApi3) {
}
return basePath;
}

private static void addUnderscores(Map.Entry<String, Any> entryElement) {
Iterator<Any> iterator = entryElement.getValue().iterator();
List<Any> list = new ArrayList<>();
while (iterator.hasNext()) {
Any any = iterator.next();
String value = any.toString().trim().replaceAll(" ", "_");
list.add(Any.wrap(value));
}
entryElement.setValue(Any.wrap(list));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static java.io.File.separator;

Expand Down Expand Up @@ -163,6 +160,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
//System.out.println("key = " + entryProp.getKey() + " value = " + entryProp.getValue());
Map<String, Any> propMap = new HashMap<>();
String name = entryProp.getKey();
name = name.trim().replaceAll(" ", "_");
propMap.put("jsonProperty", Any.wrap(name));
if(name.startsWith("@")) {
name = name.substring(1);
Expand Down Expand Up @@ -209,6 +207,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
if("enum".equals(entryElement.getKey())) {
propMap.put("isEnum", Any.wrap(true));
propMap.put("nameWithEnum", Any.wrap(name.substring(0, 1).toUpperCase() + name.substring(1) + "Enum"));
this.addUnderscores(entryElement);
propMap.put("value", Any.wrap(entryElement.getValue()));
}
if("format".equals(entryElement.getKey())) {
Expand Down Expand Up @@ -341,4 +340,14 @@ public List<Map<String, Any>> getOperationList(Object model) {
}
return result;
}
private static void addUnderscores(Map.Entry<String, Any> entryElement) {
Iterator<Any> iterator = entryElement.getValue().iterator();
List<Any> list = new ArrayList<>();
while (iterator.hasNext()) {
Any any = iterator.next();
String value = any.toString().trim().replaceAll(" ", "_");
list.add(Any.wrap(value));
}
entryElement.setValue(Any.wrap(list));
}
}