forked from loafle/openapi-generator-original
Merge branch 'master' into java-reserved-operation-id
Conflicts: modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCSharpCodegen.java modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ObjcClientCodegen.java modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java
This commit is contained in:
@@ -93,9 +93,9 @@ public class ExampleGenerator {
|
||||
};
|
||||
}
|
||||
} else if (property instanceof DateProperty) {
|
||||
return new java.util.Date(System.currentTimeMillis());
|
||||
return "2000-01-23T04:56:07.000+0000";
|
||||
} else if (property instanceof DateTimeProperty) {
|
||||
return new java.util.Date(System.currentTimeMillis());
|
||||
return "2000-01-23T04:56:07.000+0000";
|
||||
} else if (property instanceof DecimalProperty) {
|
||||
return new BigDecimal(1.3579);
|
||||
} else if (property instanceof DoubleProperty) {
|
||||
|
||||
@@ -16,10 +16,8 @@ import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -33,8 +31,6 @@ public class XmlExampleGenerator {
|
||||
public static String TAG_END = "</";
|
||||
private static String EMPTY = "";
|
||||
protected Map<String, Model> examples;
|
||||
protected SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
|
||||
public XmlExampleGenerator(Map<String, Model> examples) {
|
||||
this.examples = examples;
|
||||
@@ -172,7 +168,7 @@ public class XmlExampleGenerator {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return dtFormat.format(new Date());
|
||||
return "2000-01-23T04:56:07.000Z";
|
||||
}
|
||||
} else if (property instanceof StringProperty) {
|
||||
if (property.getExample() != null) {
|
||||
@@ -184,7 +180,7 @@ public class XmlExampleGenerator {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return dateFormat.format(new Date());
|
||||
return "2000-01-23T04:56:07.000Z";
|
||||
}
|
||||
} else if (property instanceof IntegerProperty) {
|
||||
if (property.getExample() != null) {
|
||||
|
||||
@@ -276,14 +276,15 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
@@ -471,7 +472,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
|
||||
@@ -249,12 +249,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type)) {
|
||||
return toModelName(type);
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -314,6 +314,23 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(type)) {
|
||||
LOGGER.warn(type+ " (reserved word) cannot be used as model name. Renamed to " + ("object_" + type) + " before further processing");
|
||||
type = "object_" + type; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert input to proper model name according to ObjC style guide
|
||||
* without checking for reserved words
|
||||
*
|
||||
* @param type Model anme
|
||||
* @return model Name in ObjC style guide
|
||||
*/
|
||||
public String toModelNameWithoutReservedWordCheck(String type) {
|
||||
type = type.replaceAll("[^0-9a-zA-Z_]", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// language build-in classes
|
||||
@@ -425,7 +442,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
|
||||
@@ -219,7 +219,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
@@ -231,7 +232,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore(dropDots("object_" + name)));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
@@ -267,14 +269,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return underscore(sanitizeName(operationId));
|
||||
|
||||
Reference in New Issue
Block a user