mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-08 08:30:56 +00:00
Merge branch 'master' into cli-enhancements-2
This commit is contained in:
commit
38b1e1aad7
@ -13,17 +13,22 @@ public class CodegenConfigLoader {
|
||||
*/
|
||||
public static CodegenConfig forName(String name) {
|
||||
ServiceLoader<CodegenConfig> loader = load(CodegenConfig.class);
|
||||
|
||||
StringBuilder availableConfigs = new StringBuilder();
|
||||
|
||||
for (CodegenConfig config : loader) {
|
||||
if (config.getName().equals(name)) {
|
||||
return config;
|
||||
}
|
||||
|
||||
availableConfigs.append(config.getName()).append("\n");
|
||||
}
|
||||
|
||||
// else try to load directly
|
||||
try {
|
||||
return (CodegenConfig) Class.forName(name).newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Can't load config class with name ".concat(name), e);
|
||||
throw new RuntimeException("Can't load config class with name ".concat(name) + " Available: " + availableConfigs.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ public class DefaultCodegen {
|
||||
// override with any special text escaping logic
|
||||
public String escapeText(String input) {
|
||||
if (input != null) {
|
||||
input = input.trim();
|
||||
String output = input.replaceAll("\n", "\\\\n");
|
||||
output = output.replace("\"", "\\\"");
|
||||
return output;
|
||||
@ -394,7 +395,13 @@ public class DefaultCodegen {
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
Property additionalProperties2 = ap.getAdditionalProperties();
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties2 + "\n" //
|
||||
+ "\tIn Property: " + p);
|
||||
}
|
||||
String inner = getSwaggerType(additionalProperties2);
|
||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
@ -769,7 +776,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
operationId = builder.toString();
|
||||
LOGGER.warn("generated operationId " + operationId);
|
||||
LOGGER.info("generated operationId " + operationId + "\tfor Path: " + httpMethod + " " + path);
|
||||
}
|
||||
operationId = removeNonNameElementToCamelCase(operationId);
|
||||
op.path = path;
|
||||
@ -1009,6 +1016,10 @@ public class DefaultCodegen {
|
||||
}
|
||||
p.jsonSchema = Json.pretty(param);
|
||||
|
||||
if (System.getProperty("debugParser") != null) {
|
||||
LOGGER.info("working on Parameter " + param);
|
||||
}
|
||||
|
||||
// move the defaultValue for headers, forms and params
|
||||
if (param instanceof QueryParameter) {
|
||||
p.defaultValue = ((QueryParameter) param).getDefaultValue();
|
||||
@ -1022,7 +1033,11 @@ public class DefaultCodegen {
|
||||
SerializableParameter qp = (SerializableParameter) param;
|
||||
Property property = null;
|
||||
String collectionFormat = null;
|
||||
if ("array".equals(qp.getType())) {
|
||||
String type = qp.getType();
|
||||
if (null == type) {
|
||||
LOGGER.warn("Type is NULL for Serializable Parameter: " + param);
|
||||
}
|
||||
if ("array".equals(type)) {
|
||||
Property inner = qp.getItems();
|
||||
if (inner == null) {
|
||||
LOGGER.warn("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String");
|
||||
@ -1034,7 +1049,7 @@ public class DefaultCodegen {
|
||||
p.baseType = pr.datatype;
|
||||
p.isContainer = true;
|
||||
imports.add(pr.baseType);
|
||||
} else if ("object".equals(qp.getType())) {
|
||||
} else if ("object".equals(type)) {
|
||||
Property inner = qp.getItems();
|
||||
if (inner == null) {
|
||||
LOGGER.warn("warning! No inner type supplied for map parameter \"" + qp.getName() + "\", using String");
|
||||
@ -1047,12 +1062,13 @@ public class DefaultCodegen {
|
||||
imports.add(pr.baseType);
|
||||
} else {
|
||||
Map<PropertyId, Object> args = new HashMap<PropertyId, Object>();
|
||||
String format = qp.getFormat();
|
||||
args.put(PropertyId.ENUM, qp.getEnum());
|
||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), args);
|
||||
property = PropertyBuilder.build(type, format, args);
|
||||
}
|
||||
if (property == null) {
|
||||
LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
|
||||
property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + qp.getType() + " but not supported");
|
||||
LOGGER.warn("warning! Property type \"" + type + "\" not found for parameter \"" + param.getName() + "\", using String");
|
||||
property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + type + " but not supported");
|
||||
}
|
||||
property.setRequired(param.getRequired());
|
||||
CodegenProperty model = fromProperty(qp.getName(), property);
|
||||
@ -1067,6 +1083,10 @@ public class DefaultCodegen {
|
||||
imports.add(model.complexType);
|
||||
}
|
||||
} else {
|
||||
if (!(param instanceof BodyParameter)) {
|
||||
LOGGER.error("Cannot use Parameter " + param + " as Body Parameter");
|
||||
}
|
||||
|
||||
BodyParameter bp = (BodyParameter) param;
|
||||
Model model = bp.getSchema();
|
||||
|
||||
@ -1439,4 +1459,42 @@ public class DefaultCodegen {
|
||||
}
|
||||
return new CliOption("library", sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* sanitize name (parameter, property, method, etc)
|
||||
*
|
||||
* @param name string to be sanitize
|
||||
* @return sanitized string
|
||||
*/
|
||||
public String sanitizeName(String name) {
|
||||
// NOTE: performance wise, we should have written with 2 replaceAll to replace desired
|
||||
// character with _ or empty character. Below aims to spell out different cases we've
|
||||
// encountered so far and hopefully make it easier for others to add more special
|
||||
// cases in the future.
|
||||
|
||||
// input[] => input
|
||||
name = name.replaceAll("\\[\\]", "");
|
||||
|
||||
// input[a][b] => input_a_b
|
||||
name = name.replaceAll("\\[", "_");
|
||||
name = name.replaceAll("\\]", "");
|
||||
|
||||
// input(a)(b) => input_a_b
|
||||
name = name.replaceAll("\\(", "_");
|
||||
name = name.replaceAll("\\)", "");
|
||||
|
||||
// input.name => input_name
|
||||
name = name.replaceAll("\\.", "_");
|
||||
|
||||
// input-name => input_name
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// input name and age => input_name_and_age
|
||||
name = name.replaceAll(" ", "_");
|
||||
|
||||
// remove everything else other than word, number and _
|
||||
// $php_variable => php_variable
|
||||
return name.replaceAll("[^a-zA-Z0-9_]", "");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -39,12 +41,15 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts = null;
|
||||
protected Swagger swagger = null;
|
||||
|
||||
public CodeGenStatus status = CodeGenStatus.UNRUN;
|
||||
|
||||
@Override
|
||||
public Generator opts(ClientOptInput opts) {
|
||||
this.opts = opts;
|
||||
|
||||
@ -55,6 +60,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<File> generate() {
|
||||
if (swagger == null || config == null) {
|
||||
throw new RuntimeException("missing swagger input or config!");
|
||||
@ -150,6 +156,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
}
|
||||
@ -203,6 +210,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
}
|
||||
@ -277,6 +285,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
}
|
||||
@ -416,6 +425,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||
if (operation != null) {
|
||||
if (System.getProperty("debugOperations") != null) {
|
||||
LOGGER.debug("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation + "\n");
|
||||
}
|
||||
List<String> tags = operation.getTags();
|
||||
if (tags == null) {
|
||||
tags = new ArrayList<String>();
|
||||
@ -445,44 +457,54 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
|
||||
for (String tag : tags) {
|
||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||
co.tags = new ArrayList<String>();
|
||||
co.tags.add(sanitizeTag(tag));
|
||||
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
CodegenOperation co = null;
|
||||
try {
|
||||
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||
co.tags = new ArrayList<String>();
|
||||
co.tags.add(sanitizeTag(tag));
|
||||
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
|
||||
List<Map<String, List<String>>> securities = operation.getSecurity();
|
||||
if (securities == null) {
|
||||
continue;
|
||||
}
|
||||
Map<String, SecuritySchemeDefinition> authMethods = new HashMap<String, SecuritySchemeDefinition>();
|
||||
for (Map<String, List<String>> security : securities) {
|
||||
if (security.size() != 1) {
|
||||
//Not sure what to do
|
||||
List<Map<String, List<String>>> securities = operation.getSecurity();
|
||||
if (securities == null) {
|
||||
continue;
|
||||
}
|
||||
String securityName = security.keySet().iterator().next();
|
||||
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
|
||||
if (securityDefinition != null) {
|
||||
if(securityDefinition instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Definition = (OAuth2Definition) securityDefinition;
|
||||
OAuth2Definition oauth2Operation = new OAuth2Definition();
|
||||
oauth2Operation.setType(oauth2Definition.getType());
|
||||
oauth2Operation.setAuthorizationUrl(oauth2Definition.getAuthorizationUrl());
|
||||
oauth2Operation.setFlow(oauth2Definition.getFlow());
|
||||
oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl());
|
||||
for (String scope : security.values().iterator().next()) {
|
||||
if (oauth2Definition.getScopes().containsKey(scope)) {
|
||||
oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope));
|
||||
}
|
||||
}
|
||||
authMethods.put(securityName, oauth2Operation);
|
||||
} else {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
}
|
||||
Map<String, SecuritySchemeDefinition> authMethods = new HashMap<String, SecuritySchemeDefinition>();
|
||||
for (Map<String, List<String>> security : securities) {
|
||||
if (security.size() != 1) {
|
||||
//Not sure what to do
|
||||
continue;
|
||||
}
|
||||
String securityName = security.keySet().iterator().next();
|
||||
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
|
||||
if (securityDefinition != null) {
|
||||
if(securityDefinition instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Definition = (OAuth2Definition) securityDefinition;
|
||||
OAuth2Definition oauth2Operation = new OAuth2Definition();
|
||||
oauth2Operation.setType(oauth2Definition.getType());
|
||||
oauth2Operation.setAuthorizationUrl(oauth2Definition.getAuthorizationUrl());
|
||||
oauth2Operation.setFlow(oauth2Definition.getFlow());
|
||||
oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl());
|
||||
for (String scope : security.values().iterator().next()) {
|
||||
if (oauth2Definition.getScopes().containsKey(scope)) {
|
||||
oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope));
|
||||
}
|
||||
}
|
||||
authMethods.put(securityName, oauth2Operation);
|
||||
} else {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
co.authMethods = config.fromSecurity(authMethods);
|
||||
}
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
co.authMethods = config.fromSecurity(authMethods);
|
||||
catch (Exception ex) {
|
||||
LOGGER.error("Error while trying to get Config from Operation for tag(" + tag + ")\n" //
|
||||
+ "\tResource: " + httpMethod + " " + resourcePath + "\n"//
|
||||
+ "\tOperation:" + operation + "\n" //
|
||||
+ "\tDefinitions: " + swagger.getDefinitions() + "\n");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class XmlExampleGenerator {
|
||||
ArrayProperty p = (ArrayProperty) property;
|
||||
Property inner = p.getItems();
|
||||
boolean wrapped = false;
|
||||
if (property.getXml() != null && property.getXml().getWrapped()) {
|
||||
if (property.getXml() != null && property.getXml().getWrapped() != null && property.getXml().getWrapped()) {
|
||||
wrapped = true;
|
||||
}
|
||||
if (wrapped) {
|
||||
|
@ -146,8 +146,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@ -249,7 +249,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId);
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-java-client";
|
||||
@ -82,14 +86,17 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(buildLibraryCliOption(supportedLibraries));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "java";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java client library.";
|
||||
}
|
||||
@ -191,14 +198,15 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
if("_".equals(name)) {
|
||||
name = "_u";
|
||||
@ -229,6 +237,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
@ -284,6 +294,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Property " + p);
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@ -299,7 +312,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,7 +163,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_");
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
|
@ -207,11 +207,14 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getOperations(Map<String, Object> objs) {
|
||||
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
Map<String, Object> api = apis.get(0);
|
||||
return (Map<String, Object>) api.get("operations");
|
||||
for (Map<String, Object> api : apis) {
|
||||
result.add((Map<String, Object>) api.get("operations"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
@ -221,7 +224,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
opsByPath.put(op.path, op);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
|
||||
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
|
||||
for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) {
|
||||
Map<String, Object> opsByPathEntry = new HashMap<String, Object>();
|
||||
opsByPathList.add(opsByPathEntry);
|
||||
@ -239,16 +242,13 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = getOperations(objs);
|
||||
|
||||
if (operations != null) {
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
|
||||
List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops);
|
||||
operations.put("operationsByPath", opsByPathList);
|
||||
}
|
||||
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
}
|
@ -328,9 +328,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace non-word characters to `_`
|
||||
// e.g. `created-at` to `created_at`
|
||||
name = name.replaceAll("[^a-zA-Z0-9_]", "_");
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all upper case, do noting
|
||||
if (name.matches("^[A-Z_]$")) {
|
||||
@ -371,7 +370,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
public void setClassPrefix(String classPrefix) {
|
||||
|
@ -300,6 +300,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setParameterNamingConvention((String) additionalProperties.get("variableNamingConvention"));
|
||||
}
|
||||
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
// phone_number => phoneNumber
|
||||
@ -342,4 +345,20 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -167,8 +167,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@ -177,7 +177,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// underscore the variable name
|
||||
// petId => pet_id
|
||||
name = underscore(dropDots(name));
|
||||
name = underscore(name);
|
||||
|
||||
// remove leading underscore
|
||||
name = name.replaceAll("^_*", "");
|
||||
@ -258,7 +258,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return underscore(operationId);
|
||||
return underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
|
@ -199,8 +199,8 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@ -279,7 +279,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return underscore(operationId);
|
||||
return underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -175,6 +175,15 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
public void setConfigPackage(String configPackage) {
|
||||
this.configPackage = configPackage;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ namespace {{packageName}}.Client
|
||||
/// <returns>Escaped string.</returns>
|
||||
public string EscapeString(string str)
|
||||
{
|
||||
return RestSharp.Contrib.HttpUtility.UrlEncode(str);
|
||||
return RestSharp.Extensions.StringExtensions.UrlEncode(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -14,7 +14,7 @@
|
||||
{{#operations}}
|
||||
{{#operationsByPath}}
|
||||
"{{{path}}}": {
|
||||
{{#operation}}
|
||||
{{#operation}}
|
||||
"{{httpMethod}}": {
|
||||
"summary": "{{summary}}",
|
||||
"description":"{{notes}}",
|
||||
@ -34,7 +34,6 @@
|
||||
{{/operation}}
|
||||
} {{#hasMore}},{{/hasMore}}
|
||||
{{/operationsByPath}}
|
||||
{{#hasMore}},{{/hasMore}}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
@ -355,6 +355,20 @@ class JavaModelTest extends FlatSpec with Matchers {
|
||||
vars.get(0).name should be("createdAt")
|
||||
}
|
||||
|
||||
it should "convert query[password] to queryPassword" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
.property("query[password]", new StringProperty())
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
val vars = cm.vars
|
||||
vars.get(0).baseName should be("query[password]")
|
||||
vars.get(0).getter should be("getQueryPassword")
|
||||
vars.get(0).setter should be("setQueryPassword")
|
||||
vars.get(0).name should be("queryPassword")
|
||||
}
|
||||
|
||||
it should "properly escape names per 567" in {
|
||||
val model = new ModelImpl()
|
||||
.description("a sample model")
|
||||
|
2
pom.xml
2
pom.xml
@ -517,7 +517,7 @@
|
||||
<jmustache-version>1.9</jmustache-version>
|
||||
<testng-version>6.9.6</testng-version>
|
||||
<surefire-version>2.18.1</surefire-version>
|
||||
<jmockit-version>1.18</jmockit-version>
|
||||
<jmockit-version>1.19</jmockit-version>
|
||||
<reflections-version>0.9.10</reflections-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -49,6 +49,16 @@ namespace IO.Swagger.Client
|
||||
{
|
||||
get { return _defaultHeaderMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status code of the previous request
|
||||
/// </summary>
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response headers of the previous request
|
||||
/// </summary>
|
||||
public Dictionary<String, String> ResponseHeaders { get; private set; }
|
||||
|
||||
// Creates and sets up a RestRequest prior to a call.
|
||||
private RestRequest PrepareRequest(
|
||||
@ -110,7 +120,10 @@ namespace IO.Swagger.Client
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
return (Object)RestClient.Execute(request);
|
||||
var response = RestClient.Execute(request);
|
||||
StatusCode = (int) response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object) response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -133,7 +146,10 @@ namespace IO.Swagger.Client
|
||||
{
|
||||
var request = PrepareRequest(
|
||||
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
|
||||
return (Object) await RestClient.ExecuteTaskAsync(request);
|
||||
var response = await RestClient.ExecuteTaskAsync(request);
|
||||
StatusCode = (int)response.StatusCode;
|
||||
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
|
||||
return (Object)response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -154,7 +170,7 @@ namespace IO.Swagger.Client
|
||||
/// <returns>Escaped string.</returns>
|
||||
public string EscapeString(string str)
|
||||
{
|
||||
return RestSharp.Contrib.HttpUtility.UrlEncode(str);
|
||||
return RestSharp.Extensions.StringExtensions.UrlDecode(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -32,15 +32,15 @@
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>Lib\SwaggerClient\bin\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestSharp">
|
||||
<HintPath>Lib\SwaggerClient\bin\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="RestSharp">
|
||||
<HintPath>Lib\SwaggerClient\bin\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Lib\SwaggerClient\src\main\csharp\IO\Swagger\Api\PetApi.cs" />
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -9,8 +9,8 @@ from .models.order import Order
|
||||
|
||||
# import apis into sdk package
|
||||
from .apis.user_api import UserApi
|
||||
from .apis.store_api import StoreApi
|
||||
from .apis.pet_api import PetApi
|
||||
from .apis.store_api import StoreApi
|
||||
|
||||
# import ApiClient
|
||||
from .api_client import ApiClient
|
||||
|
@ -2,5 +2,5 @@ from __future__ import absolute_import
|
||||
|
||||
# import apis into api package
|
||||
from .user_api import UserApi
|
||||
from .store_api import StoreApi
|
||||
from .pet_api import PetApi
|
||||
from .store_api import StoreApi
|
||||
|
@ -409,7 +409,7 @@ class PetApi(object):
|
||||
select_header_content_type([])
|
||||
|
||||
# Authentication setting
|
||||
auth_settings = ['petstore_auth', 'api_key']
|
||||
auth_settings = ['api_key', 'petstore_auth']
|
||||
|
||||
response = self.api_client.call_api(resource_path, method,
|
||||
path_params,
|
||||
|
Loading…
x
Reference in New Issue
Block a user