mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-04-27 03:54:17 +00:00
Merge pull request #3124 from mateuszmackowiak/objc/core_data_support_for_array_model
[Objc] - CoreData support for ArrayModels
This commit is contained in:
@@ -22,6 +22,7 @@ public class CodegenModel {
|
||||
public String unescapedDescription;
|
||||
public String discriminator;
|
||||
public String defaultValue;
|
||||
public String arrayModelType;
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>(); // a list of required properties
|
||||
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
|
||||
@@ -35,7 +36,7 @@ public class CodegenModel {
|
||||
public Set<String> allMandatory;
|
||||
|
||||
public Set<String> imports = new TreeSet<String>();
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired;
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, isArrayModel;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
@@ -1198,6 +1198,8 @@ public class DefaultCodegen {
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
ArrayProperty arrayProperty = new ArrayProperty(am.getItems());
|
||||
m.hasEnums = false; // Otherwise there will be a NullPointerException in JavaClientCodegen.fromModel
|
||||
m.isArrayModel = true;
|
||||
m.arrayModelType = fromProperty(name, arrayProperty).complexType;
|
||||
addParentContainer(m, name, arrayProperty);
|
||||
} else if (model instanceof RefModel) {
|
||||
// TODO
|
||||
@@ -1465,7 +1467,9 @@ public class DefaultCodegen {
|
||||
if (p instanceof BinaryProperty) {
|
||||
property.isBinary = true;
|
||||
}
|
||||
|
||||
if (p instanceof UUIDProperty) {
|
||||
property.isString = true;
|
||||
}
|
||||
if (p instanceof ByteArrayProperty) {
|
||||
property.isByteArray = true;
|
||||
}
|
||||
|
||||
+8
-80
@@ -1,6 +1,7 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
@@ -94,7 +95,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.clear();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("datetime", "NSDate");
|
||||
typeMapping.put("boolean", "NSNumber");
|
||||
typeMapping.put("string", "NSString");
|
||||
typeMapping.put("integer", "NSNumber");
|
||||
@@ -105,12 +106,15 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("array", "NSArray");
|
||||
typeMapping.put("map", "NSDictionary");
|
||||
typeMapping.put("number", "NSNumber");
|
||||
typeMapping.put("bigdecimal", "NSNumber");
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
typeMapping.put("file", "NSURL");
|
||||
typeMapping.put("binary", "NSData");
|
||||
typeMapping.put("ByteArray", "NSData");
|
||||
typeMapping.put("bytearray", "NSData");
|
||||
typeMapping.put("byte", "NSData");
|
||||
typeMapping.put("uuid", "NSString");
|
||||
typeMapping.put("password", "NSString");
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
setReservedWordsLowerCase(
|
||||
@@ -293,8 +297,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (typeMapping.containsKey(swaggerType.toLowerCase())) {
|
||||
type = typeMapping.get(swaggerType.toLowerCase());
|
||||
if (languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type)) {
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
@@ -304,15 +308,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
|
||||
public CodegenProperty coreDatafromProperty(String name, Property p) {
|
||||
CodegenProperty property = fromProperty(name, p);
|
||||
if(!generateCoreData) {
|
||||
return property;
|
||||
}
|
||||
property.baseType = getTypeCoreDataDeclaration(p);
|
||||
return property;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -377,73 +372,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getTypeCoreDataDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
String innerType = getSwaggerType(inner);
|
||||
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
// In this codition, type of property p is array of primitive,
|
||||
// return container type with pointer, e.g. `NSArray*<NSString*>*'
|
||||
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
// In this codition, type of property p is array of model,
|
||||
// return container type combine inner type with pointer, e.g. `NSArray<SWGTag>*'
|
||||
else {
|
||||
for (String sd : advancedMapingTypes) {
|
||||
if(innerTypeDeclaration.startsWith(sd)) {
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
}
|
||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
|
||||
if (innerTypeDeclaration.endsWith("*")) {
|
||||
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||
}
|
||||
if (languageSpecificPrimitives.contains(innerTypeDeclaration)) {
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + "*>*";
|
||||
} else {
|
||||
for (String s : advancedMapingTypes) {
|
||||
if(innerTypeDeclaration.startsWith(s)) {
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + "*>*";
|
||||
}
|
||||
}
|
||||
return getSwaggerType(p) + "<NSString*, " + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else {
|
||||
String swaggerType = getSwaggerType(p);
|
||||
|
||||
// In this codition, type of p is objective-c primitive type, e.g. `NSSNumber',
|
||||
// return type of p with pointer, e.g. `NSNumber*'
|
||||
if (languageSpecificPrimitives.contains(swaggerType) &&
|
||||
foundationClasses.contains(swaggerType)) {
|
||||
return swaggerType + "*";
|
||||
}
|
||||
// In this codition, type of p is c primitive type, e.g. `bool',
|
||||
// return type of p, e.g. `bool'
|
||||
else if (languageSpecificPrimitives.contains(swaggerType)) {
|
||||
return swaggerType;
|
||||
}
|
||||
// In this codition, type of p is objective-c object type, e.g. `SWGPet',
|
||||
// return type of p with pointer, e.g. `SWGPet*'
|
||||
else {
|
||||
return swaggerType + "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeBinary(String dataType) {
|
||||
return dataType.toLowerCase().startsWith("nsdata");
|
||||
|
||||
Reference in New Issue
Block a user