mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
[all] Support for Free-Form Objects (#849)
Consider "additionalProperties: true" Fixes #796
This commit is contained in:
parent
99646e6436
commit
3f65d6c350
@ -75,7 +75,6 @@ import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
@ -1094,7 +1093,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema additionalProperties = (Schema) schema.getAdditionalProperties();
|
||||
Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
String type = additionalProperties.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties + "\n" //
|
||||
@ -1998,7 +1997,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
property.maxItems = p.getMaxProperties();
|
||||
|
||||
// handle inner property
|
||||
CodegenProperty cp = fromProperty("inner", (Schema) p.getAdditionalProperties());
|
||||
CodegenProperty cp = fromProperty("inner", ModelUtils.getAdditionalProperties(p));
|
||||
updatePropertyForMap(property, cp);
|
||||
} else { // model
|
||||
// TODO revise the logic below
|
||||
@ -2288,7 +2287,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenProperty innerProperty = fromProperty("response", as.getItems());
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
} else if (ModelUtils.isMapSchema(responseSchema)) {
|
||||
CodegenProperty innerProperty = fromProperty("response", (Schema) responseSchema.getAdditionalProperties());
|
||||
CodegenProperty innerProperty = fromProperty("response", ModelUtils.getAdditionalProperties(responseSchema));
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
} else {
|
||||
if (cm.complexType != null) {
|
||||
@ -2674,7 +2673,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
} else if (ModelUtils.isMapSchema(parameterSchema)) { // for map parameter
|
||||
CodegenProperty codegenProperty = fromProperty("inner", (Schema) parameterSchema.getAdditionalProperties());
|
||||
CodegenProperty codegenProperty = fromProperty("inner", ModelUtils.getAdditionalProperties(parameterSchema));
|
||||
codegenParameter.items = codegenProperty;
|
||||
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
|
||||
codegenParameter.baseType = codegenProperty.dataType;
|
||||
@ -4381,7 +4380,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(schema);
|
||||
if (inner == null) {
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator");
|
||||
schema.setAdditionalProperties(inner);
|
||||
@ -4469,7 +4468,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
imports.add(codegenParameter.baseType);
|
||||
} else {
|
||||
CodegenProperty codegenProperty = fromProperty("property", schema);
|
||||
if (schema.getAdditionalProperties() != null) {// http body is map
|
||||
if (ModelUtils.getAdditionalProperties(schema) != null) {// http body is map
|
||||
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
|
||||
} else if (codegenProperty != null) {
|
||||
String codegenModelName, codegenModelDescription;
|
||||
|
@ -238,7 +238,7 @@ public class InlineModelResolver {
|
||||
}
|
||||
} else if (property instanceof MapSchema) {
|
||||
MapSchema mp = (MapSchema) property;
|
||||
Schema innerProperty = (Schema) mp.getAdditionalProperties();
|
||||
Schema innerProperty = ModelUtils.getAdditionalProperties(mp);
|
||||
if (innerProperty instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) innerProperty;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
@ -431,7 +431,7 @@ public class InlineModelResolver {
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isMapSchema(property)) {
|
||||
Schema inner = (Schema) property.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(property);
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
@ -519,7 +519,7 @@ public class InlineModelResolver {
|
||||
model.setDescription(description);
|
||||
model.setName(object.getName());
|
||||
model.setExample(example);
|
||||
model.setItems((Schema) object.getAdditionalProperties());
|
||||
model.setItems(ModelUtils.getAdditionalProperties(object));
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -236,10 +236,10 @@ public class ExampleGenerator {
|
||||
Map<String, Object> mp = new HashMap<String, Object>();
|
||||
if (property.getName() != null) {
|
||||
mp.put(property.getName(),
|
||||
resolvePropertyToExample(propertyName, mediaType, (Schema) property.getAdditionalProperties(), processedModels));
|
||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(property), processedModels));
|
||||
} else {
|
||||
mp.put("key",
|
||||
resolvePropertyToExample(propertyName, mediaType, (Schema) property.getAdditionalProperties(), processedModels));
|
||||
resolvePropertyToExample(propertyName, mediaType, ModelUtils.getAdditionalProperties(property), processedModels));
|
||||
}
|
||||
return mp;
|
||||
} else if (ModelUtils.isUUIDSchema(property)) {
|
||||
|
@ -329,7 +329,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
return getTypeDeclaration(inner) + "_Vectors.Vector";
|
||||
}
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
String name = getTypeDeclaration(inner) + "_Map";
|
||||
if (name.startsWith("Swagger.")) {
|
||||
return name;
|
||||
|
@ -18,12 +18,12 @@
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.base.Strings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.DefaultCodegen;
|
||||
@ -196,7 +196,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
if (inner == null) {
|
||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined");
|
||||
@ -229,11 +229,11 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
final MapSchema ap = (MapSchema) p;
|
||||
final String pattern = "new HashMap<%s>()";
|
||||
if (ap.getAdditionalProperties() == null) {
|
||||
if (ModelUtils.getAdditionalProperties(ap) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return String.format(pattern, String.format("String, %s", getTypeDeclaration((Schema) ap.getAdditionalProperties())));
|
||||
return String.format(pattern, String.format("String, %s", getTypeDeclaration(ModelUtils.getAdditionalProperties(ap))));
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "l";
|
||||
@ -366,7 +366,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
} else if (ModelUtils.isLongSchema(p)) {
|
||||
example = example.isEmpty() ? "123456789L" : example + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue((Schema) p.getAdditionalProperties()) + "}";
|
||||
example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue(ModelUtils.getAdditionalProperties(p)) + "}";
|
||||
|
||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
||||
example = example.isEmpty() ? "password123" : escapeText(example);
|
||||
|
@ -811,7 +811,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
// Should we also support maps of maps?
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<string, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -290,7 +290,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
Schema inner = ap.getItems();
|
||||
return "LIST [" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
@ -557,7 +557,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = (Schema) p.getAdditionalProperties();
|
||||
Schema additionalProperties2 = ModelUtils.getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
||||
|
@ -258,7 +258,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
Schema inner = ap.getItems();
|
||||
return "[]" + getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[string]" + getTypeDeclaration(inner);
|
||||
}
|
||||
//return super.getTypeDeclaration(p);
|
||||
|
@ -679,7 +679,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
if (inner == null) {
|
||||
LOGGER.warn(p.getName() + "(map property) does not have a proper inner type defined. Default to string");
|
||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||
@ -728,11 +728,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
} else {
|
||||
pattern = "new HashMap<%s>()";
|
||||
}
|
||||
if (p.getAdditionalProperties() == null) {
|
||||
if (ModelUtils.getAdditionalProperties(p) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String typeDeclaration = String.format("String, %s", getTypeDeclaration((Schema) p.getAdditionalProperties()));
|
||||
String typeDeclaration = String.format("String, %s", getTypeDeclaration(ModelUtils.getAdditionalProperties(p)));
|
||||
Object java8obj = additionalProperties.get("java8");
|
||||
if (java8obj != null) {
|
||||
Boolean java8 = Boolean.valueOf(java8obj.toString());
|
||||
|
@ -282,7 +282,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
if (ModelUtils.isArraySchema(p)) {
|
||||
return getArrayTypeDeclaration((ArraySchema) p);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
// Maps will be keyed only by primitive Kotlin string
|
||||
return getSchemaType(p) + "<kotlin.String, " + getTypeDeclaration(inner) + ">";
|
||||
|
@ -332,7 +332,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner) + "[]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||
} else if (StringUtils.isNotBlank(p.get$ref())) { // model
|
||||
String type = super.getTypeDeclaration(p);
|
||||
|
@ -88,7 +88,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
||||
Schema inner = ((ArraySchema) schema).getItems();
|
||||
return getSchemaType(schema) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(schema);
|
||||
return getSchemaType(schema) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
@ -206,7 +206,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
@ -235,7 +235,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "new HashMap[String, " + inner + "]() ";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -227,7 +227,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
@ -246,7 +246,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
inner = mp1.getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = (Schema) p.getAdditionalProperties();
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
// Handle string enums
|
||||
|
@ -189,7 +189,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ public class ApexClientCodegen extends AbstractApexCodegen {
|
||||
Long def = (Long) p.getDefault();
|
||||
out = def == null ? out : def.toString() + "L";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
String s = inner == null ? "Object" : getTypeDeclaration(inner);
|
||||
out = String.format("new Map<String, %s>()", s);
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
|
@ -388,7 +388,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -99,7 +99,7 @@ public class ConfluenceWikiCodegen extends DefaultCodegen implements CodegenConf
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -305,7 +305,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
else if (ModelUtils.isByteArraySchema(p)) {
|
||||
@ -343,7 +343,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -294,7 +294,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">*";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">*";
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
@ -325,7 +325,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "new QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -323,7 +323,7 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
@ -359,7 +359,7 @@ public class CppQt5QHttpEngineServerCodegen extends AbstractCppCodegen implement
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -308,7 +308,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)
|
||||
@ -339,7 +339,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "std::map<utility::string_t, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -270,7 +270,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
@ -307,7 +307,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -307,7 +307,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
|
||||
} else if (ModelUtils.isPasswordSchema(p)) {
|
||||
return "String.t";
|
||||
|
@ -486,7 +486,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -239,7 +239,7 @@ public class FinchServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "(Map.Map String " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@ -570,7 +570,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = (Schema) p.getAdditionalProperties();
|
||||
Schema additionalProperties2 = ModelUtils.getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Schema " + additionalProperties2 + "\n" //
|
||||
|
@ -293,7 +293,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "Map.Map String " + getTypeDeclaration(inner);
|
||||
}
|
||||
return fixModelChars(super.getTypeDeclaration(p));
|
||||
@ -328,7 +328,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema additionalProperties2 = (Schema) p.getAdditionalProperties();
|
||||
Schema additionalProperties2 = ModelUtils.getAdditionalProperties(p);
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties2 + "\n" //
|
||||
|
@ -174,7 +174,7 @@ public class JMeterClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -601,7 +601,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@ -863,9 +863,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType(am.getItems()));
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(model)) {
|
||||
if (model.getAdditionalProperties() != null) {
|
||||
if (ModelUtils.getAdditionalProperties(model) != null) {
|
||||
codegenModel.getVendorExtensions().put("x-isMap", true);
|
||||
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType((Schema) model.getAdditionalProperties()));
|
||||
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType(ModelUtils.getAdditionalProperties(model)));
|
||||
} else {
|
||||
String type = model.getType();
|
||||
if (isPrimitiveType(type)){
|
||||
|
@ -236,7 +236,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "<!" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "Object<!string, "+ getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "Object";
|
||||
|
@ -119,7 +119,7 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration((Schema) schema.getAdditionalProperties());
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo
|
||||
inner = ((ArraySchema) p).getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = (Schema) p.getAdditionalProperties();
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
|
@ -337,7 +337,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return getSchemaType(p) + "<" + innerTypeDeclaration + ">*";
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -163,7 +163,7 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -497,7 +497,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
}
|
||||
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
|
||||
|
@ -383,7 +383,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner) + "[]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
// TODO not sure if the following map/hash declaration is correct
|
||||
return "{String, " + getTypeDeclaration(inner) + "}";
|
||||
} else if (!languageSpecificPrimitives.contains(getSchemaType(p))) {
|
||||
|
@ -404,7 +404,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
return getSchemaType(p) + "(str, " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[str, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -286,7 +286,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return getTypeDeclaration(inner);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return "Vec<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "::std::collections::HashMap<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
|
||||
|
@ -730,7 +730,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeDeclaration.append(innerType).append(">");
|
||||
return typeDeclaration.toString();
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
String innerType = getTypeDeclaration(inner);
|
||||
StringBuilder typeDeclaration = new StringBuilder(typeMapping.get("map")).append("<").append(typeMapping.get("string")).append(", ");
|
||||
typeDeclaration.append(innerType).append(">");
|
||||
@ -797,7 +797,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return instantiationTypes.get("array") + "<" + getSchemaType(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return instantiationTypes.get("map") + "<" + typeMapping.get("string") + ", " + getSchemaType(inner) + ">";
|
||||
} else {
|
||||
return null;
|
||||
|
@ -276,7 +276,7 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
return null;
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "Map[String, " + inner + "].empty ";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -347,7 +347,7 @@ public class ScalaGatlingCodegen extends AbstractScalaCodegen implements Codegen
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -131,7 +131,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -118,7 +118,7 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
|
@ -230,7 +230,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
|
||||
final Schema additionalProperties = (Schema) schema.getAdditionalProperties();
|
||||
final Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
|
||||
if (additionalProperties != null) {
|
||||
codegenModel.additionalPropertiesType = getSchemaType(additionalProperties);
|
||||
@ -333,7 +333,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@ -422,7 +422,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
return getSchemaType((Schema) p.getAdditionalProperties());
|
||||
return getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
|
@ -284,7 +284,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel,
|
||||
Schema schema) {
|
||||
|
||||
final Schema additionalProperties = (Schema) schema.getAdditionalProperties();
|
||||
final Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
|
||||
if (additionalProperties != null) {
|
||||
codegenModel.additionalPropertiesType = getSchemaType(additionalProperties);
|
||||
@ -420,7 +420,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@ -524,7 +524,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
return getSchemaType((Schema) p.getAdditionalProperties());
|
||||
return getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
|
@ -270,7 +270,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
Schema inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = (Schema) p.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@ -359,7 +359,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toInstantiationType(Schema p) {
|
||||
if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType((Schema) p.getAdditionalProperties());
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "[String:" + inner + "]";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
|
@ -98,7 +98,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration((Schema) schema.getAdditionalProperties());
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
inner = ((ArraySchema) p).getItems();
|
||||
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
inner = (Schema) p.getAdditionalProperties();
|
||||
inner = ModelUtils.getAdditionalProperties(p);
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "any";
|
||||
@ -127,7 +127,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration((Schema) schema.getAdditionalProperties());
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.media.FileSchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -77,7 +78,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration((Schema) schema.getAdditionalProperties());
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
codegenModel.additionalPropertiesType = getSchemaType((Schema) schema.getAdditionalProperties());
|
||||
codegenModel.additionalPropertiesType = getSchemaType(ModelUtils.getAdditionalProperties(schema));
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
|
@ -307,6 +307,9 @@ public class ModelUtils {
|
||||
if (schema.getAdditionalProperties() instanceof Schema) {
|
||||
return true;
|
||||
}
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && (Boolean)schema.getAdditionalProperties()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -657,4 +660,14 @@ public class ModelUtils {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public static Schema getAdditionalProperties(Schema schema) {
|
||||
if(schema.getAdditionalProperties() instanceof Schema) {
|
||||
return (Schema) schema.getAdditionalProperties();
|
||||
}
|
||||
if(schema.getAdditionalProperties() instanceof Boolean && (Boolean)schema.getAdditionalProperties()) {
|
||||
return new ObjectSchema();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenModelFactory;
|
||||
import org.openapitools.codegen.CodegenModelType;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
@ -307,6 +305,35 @@ public class JavaClientCodegenTest {
|
||||
output.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreeFormObjects() {
|
||||
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/issue796.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
JavaClientCodegen codegen = new JavaClientCodegen();
|
||||
|
||||
Schema test1 = openAPI.getComponents().getSchemas().get("MapTest1");
|
||||
CodegenModel cm1 = codegen.fromModel("MapTest1", test1, openAPI.getComponents().getSchemas());
|
||||
Assert.assertEquals(cm1.getDataType(), "Map");
|
||||
Assert.assertEquals(cm1.getParent(), "HashMap<String, Object>");
|
||||
Assert.assertEquals(cm1.getClassname(), "MapTest1");
|
||||
|
||||
Schema test2 = openAPI.getComponents().getSchemas().get("MapTest2");
|
||||
CodegenModel cm2 = codegen.fromModel("MapTest2", test2, openAPI.getComponents().getSchemas());
|
||||
Assert.assertEquals(cm2.getDataType(), "Map");
|
||||
Assert.assertEquals(cm2.getParent(), "HashMap<String, Object>");
|
||||
Assert.assertEquals(cm2.getClassname(), "MapTest2");
|
||||
|
||||
Schema test3 = openAPI.getComponents().getSchemas().get("MapTest3");
|
||||
CodegenModel cm3 = codegen.fromModel("MapTest3", test3, openAPI.getComponents().getSchemas());
|
||||
Assert.assertEquals(cm3.getDataType(), "Map");
|
||||
Assert.assertEquals(cm3.getParent(), "HashMap<String, Object>");
|
||||
Assert.assertEquals(cm3.getClassname(), "MapTest3");
|
||||
|
||||
Schema other = openAPI.getComponents().getSchemas().get("OtherObj");
|
||||
CodegenModel cm = codegen.fromModel("OtherObj", other, openAPI.getComponents().getSchemas());
|
||||
Assert.assertEquals(cm.getDataType(), "Object");
|
||||
Assert.assertEquals(cm.getClassname(), "OtherObj");
|
||||
}
|
||||
|
||||
private void ensureContainsFile(Map<String, String> generatedFiles, File root, String filename) {
|
||||
File file = new File(root, filename);
|
||||
String absoluteFilename = file.getAbsolutePath().replace("\\", "/");
|
||||
|
@ -0,0 +1,37 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: Issue 796
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://localhost:123/api
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
tags:
|
||||
- test
|
||||
responses:
|
||||
201:
|
||||
description: Successful response
|
||||
components:
|
||||
schemas:
|
||||
MapTest1:
|
||||
type: object
|
||||
description: This type example 1
|
||||
additionalProperties: {}
|
||||
MapTest2:
|
||||
type: object
|
||||
description: This type example 2
|
||||
additionalProperties: true
|
||||
MapTest3:
|
||||
type: object
|
||||
description: This type example 3
|
||||
additionalProperties:
|
||||
type: object
|
||||
OtherObj:
|
||||
type: object
|
||||
description: This type example 4
|
||||
additionalProperties: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user