Fix issue with C# generator when the model name is "File" (#1428)

* fix get schema type in abstract c# class

* update c# petstore sample
This commit is contained in:
William Cheng
2018-11-14 09:43:31 +08:00
committed by GitHub
parent c8837ea414
commit efde4a8eb8
27 changed files with 1023 additions and 38 deletions

View File

@@ -160,21 +160,21 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
typeMapping = new HashMap<String, String>();
typeMapping.put("string", "string");
typeMapping.put("binary", "byte[]");
typeMapping.put("bytearray", "byte[]");
typeMapping.put("ByteArray", "byte[]");
typeMapping.put("boolean", "bool?");
typeMapping.put("integer", "int?");
typeMapping.put("float", "float?");
typeMapping.put("long", "long?");
typeMapping.put("double", "double?");
typeMapping.put("number", "decimal?");
typeMapping.put("datetime", "DateTime?");
typeMapping.put("DateTime", "DateTime?");
typeMapping.put("date", "DateTime?");
typeMapping.put("file", "System.IO.Stream");
typeMapping.put("array", "List");
typeMapping.put("list", "List");
typeMapping.put("map", "Dictionary");
typeMapping.put("object", "Object");
typeMapping.put("uuid", "Guid?");
typeMapping.put("UUID", "Guid?");
}
public void setReturnICollection(boolean returnICollection) {
@@ -766,20 +766,19 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
String type;
if (openAPIType == null) {
openAPIType = ""; // set swagger type to empty string if null
LOGGER.error("OpenAPI Type for {} is null. Default to UNKNOWN_OPENAPI_TYPE instead.", p.getName());
openAPIType = "UNKNOWN_OPENAPI_TYPE";
}
// NOTE: typeMapping here supports things like string/String, long/Long, datetime/DateTime as lowercase keys.
// Should we require explicit casing here (values are not insensitive).
// TODO avoid using toLowerCase as typeMapping should be case-sensitive
if (typeMapping.containsKey(openAPIType.toLowerCase(Locale.ROOT))) {
type = typeMapping.get(openAPIType.toLowerCase(Locale.ROOT));
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type)) {
return type;
}
} else {
type = openAPIType;
}
return toModelName(type);
}