forked from loafle/openapi-generator-original
Merge remote-tracking branch 'main/master'
This commit is contained in:
@@ -105,6 +105,8 @@ public interface CodegenConfig {
|
||||
|
||||
void processSwagger(Swagger swagger);
|
||||
|
||||
String sanitizeTag(String tag);
|
||||
|
||||
String toApiFilename(String name);
|
||||
|
||||
String toModelFilename(String name);
|
||||
|
||||
@@ -2293,6 +2293,19 @@ public class DefaultCodegen {
|
||||
return name.replaceAll("[^a-zA-Z0-9_]", "");
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String[] parts = tag.split(" ");
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (String part : parts) {
|
||||
if (StringUtils.isNotEmpty(part)) {
|
||||
buf.append(StringUtils.capitalize(part));
|
||||
}
|
||||
}
|
||||
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Only write if the file doesn't exist
|
||||
*
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
@@ -623,8 +622,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
try {
|
||||
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger);
|
||||
co.tags = new ArrayList<String>();
|
||||
co.tags.add(sanitizeTag(tag));
|
||||
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
co.tags.add(config.sanitizeTag(tag));
|
||||
config.addOperationToGroup(config.sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
|
||||
List<Map<String, List<String>>> securities = operation.getSecurity();
|
||||
if (securities == null && swagger.getSecurity() != null) {
|
||||
@@ -683,19 +682,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return parameter.getName() + ":" + parameter.getIn();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String[] parts = tag.split(" ");
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (String part : parts) {
|
||||
if (isNotEmpty(part)) {
|
||||
buf.append(capitalize(part));
|
||||
}
|
||||
}
|
||||
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) {
|
||||
Map<String, Object> operations = new HashMap<String, Object>();
|
||||
|
||||
@@ -145,6 +145,11 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sanitizeTag(String tag) {
|
||||
return tag.replaceAll("[^a-zA-Z_]+", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + namespaceToFolder(apiPackage);
|
||||
@@ -160,6 +165,11 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return dashize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return underscore(toApiName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return dashize(name);
|
||||
|
||||
@@ -44,7 +44,8 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"case", "defer", "go", "map", "struct",
|
||||
"chan", "else", "goto", "package", "switch",
|
||||
"const", "fallthrough", "if", "range", "type",
|
||||
"continue", "for", "import", "return", "var")
|
||||
"continue", "for", "import", "return", "var", "error")
|
||||
// Added "error" as it's used so frequently that it may as well be a keyword
|
||||
);
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
@@ -131,8 +132,22 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
public String escapeReservedWord(String name)
|
||||
{
|
||||
// Can't start with an underscore, as our fields need to start with an
|
||||
// UppercaseLetter so that Go treats them as public/visible.
|
||||
|
||||
// Options?
|
||||
// - MyName
|
||||
// - AName
|
||||
// - TheName
|
||||
// - XName
|
||||
// - X_Name
|
||||
// ... or maybe a suffix?
|
||||
// - Name_ ... think this will work.
|
||||
|
||||
// FIXME: This should also really be a customizable option
|
||||
return camelize(name) + '_';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,8 +181,13 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
// params should be lowerCamelCase. E.g. "person Person", instead of
|
||||
// "Person Person".
|
||||
//
|
||||
// REVISIT: Actually, for idiomatic go, the param name should
|
||||
// really should just be a letter, e.g. "p Person"), but we'll get
|
||||
// around to that some other time... Maybe.
|
||||
return camelize(toVarName(name), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,7 +220,24 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
return getSwaggerType(p) + "[string]" + getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
//return super.getTypeDeclaration(p);
|
||||
|
||||
// Not using the supertype invocation, because we want to UpperCamelize
|
||||
// the type.
|
||||
String swaggerType = getSwaggerType(p);
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
return typeMapping.get(swaggerType);
|
||||
}
|
||||
|
||||
if(typeMapping.containsValue(swaggerType)) {
|
||||
return swaggerType;
|
||||
}
|
||||
|
||||
if(languageSpecificPrimitives.contains(swaggerType)) {
|
||||
return swaggerType;
|
||||
}
|
||||
|
||||
return camelize(swaggerType, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,6 +83,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
);
|
||||
instantiationTypes.put("array", "ArrayList");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
typeMapping.put("date", "Date");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
@@ -488,7 +490,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0 ||
|
||||
type.equals("Map") || type.equals("List")) {
|
||||
type.equals("Map") || type.equals("List") ||
|
||||
type.equals("File") || type.equals("Date")) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user