mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 06:30:52 +00:00
added custom class loading for configurations
This commit is contained in:
parent
277f26a5bb
commit
05e1d02341
@ -71,6 +71,18 @@ public class Codegen extends DefaultGenerator {
|
|||||||
return new JaxRSServerCodegen();
|
return new JaxRSServerCodegen();
|
||||||
else if("static".equals(name))
|
else if("static".equals(name))
|
||||||
return new StaticDocCodegen();
|
return new StaticDocCodegen();
|
||||||
|
else if(name.indexOf(".") > 0) {
|
||||||
|
// see if it's a class
|
||||||
|
try {
|
||||||
|
System.out.println("loading class " + name);
|
||||||
|
Class customClass = Class.forName(name);
|
||||||
|
System.out.println("loaded");
|
||||||
|
return (CodegenConfig)customClass.newInstance();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException("can't load class " + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw new RuntimeException("unsupported client type");
|
throw new RuntimeException("unsupported client type");
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ public class DefaultGenerator implements Generator {
|
|||||||
|
|
||||||
Map<String, Object> apis = new HashMap<String, Object>();
|
Map<String, Object> apis = new HashMap<String, Object>();
|
||||||
apis.put("apis", allOperations);
|
apis.put("apis", allOperations);
|
||||||
|
|
||||||
bundle.put("apiInfo", apis);
|
bundle.put("apiInfo", apis);
|
||||||
|
|
||||||
for(SupportingFile support : config.supportingFiles()) {
|
for(SupportingFile support : config.supportingFiles()) {
|
||||||
String outputFolder = config.outputFolder();
|
String outputFolder = config.outputFolder();
|
||||||
if(support.folder != null && !"".equals(support.folder))
|
if(support.folder != null && !"".equals(support.folder))
|
||||||
@ -137,7 +137,6 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
||||||
// group by tag, create a Default grouping if none
|
|
||||||
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
||||||
List<String> tags = null;
|
List<String> tags = null;
|
||||||
|
|
||||||
@ -164,13 +163,27 @@ public class DefaultGenerator implements Generator {
|
|||||||
for(String tag : tags) {
|
for(String tag : tags) {
|
||||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation);
|
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation);
|
||||||
co.tags = new ArrayList<String>();
|
co.tags = new ArrayList<String>();
|
||||||
co.tags.add(tag);
|
co.tags.add(sanitizeTag(tag));
|
||||||
|
|
||||||
config.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String sanitizeTag(String tag) {
|
||||||
|
// remove spaces and make strong case
|
||||||
|
String [] parts = tag.split(" ");
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
for(String part: parts) {
|
||||||
|
if(!"".equals(part)) {
|
||||||
|
buf.append(Character.toUpperCase(part.charAt(0)));
|
||||||
|
if(part.length() > 1)
|
||||||
|
buf.append(part.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||||
|
}
|
||||||
|
|
||||||
public File writeToFile(String filename, String contents) throws IOException {
|
public File writeToFile(String filename, String contents) throws IOException {
|
||||||
System.out.println("writing file " + filename);
|
System.out.println("writing file " + filename);
|
||||||
File output = new File(filename);
|
File output = new File(filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user