forked from loafle/openapi-generator-original
better handling of undefined inner property in array (#2635)
This commit is contained in:
parent
b797662eaf
commit
b426bab85e
@ -1878,7 +1878,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
if (p == null) {
|
||||
LOGGER.error("Unexpected missing property for name " + name);
|
||||
LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name);
|
||||
return null;
|
||||
}
|
||||
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
|
||||
@ -2022,6 +2022,21 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
} else if (ModelUtils.isFreeFormObject(p)) {
|
||||
property.isFreeFormObject = true;
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
// default to string if inner item is undefined
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ((ArraySchema) p).getItems());
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
((ArraySchema)p).setItems(innerSchema);
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getAdditionalProperties(p));
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
p.setAdditionalProperties(innerSchema);
|
||||
}
|
||||
}
|
||||
|
||||
//Inline enum case:
|
||||
@ -2092,6 +2107,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
itemName = property.name;
|
||||
}
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ((ArraySchema) p).getItems());
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
((ArraySchema)p).setItems(innerSchema);
|
||||
}
|
||||
CodegenProperty cp = fromProperty(itemName, innerSchema);
|
||||
updatePropertyForArray(property, cp);
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
@ -2104,6 +2124,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// handle inner property
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getAdditionalProperties(p));
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
p.setAdditionalProperties(innerSchema);
|
||||
}
|
||||
CodegenProperty cp = fromProperty("inner", innerSchema);
|
||||
updatePropertyForMap(property, cp);
|
||||
} else if (ModelUtils.isFreeFormObject(p)) {
|
||||
@ -4359,8 +4384,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
final ArraySchema arraySchema = (ArraySchema) s;
|
||||
Schema inner = arraySchema.getItems();
|
||||
if (inner == null) {
|
||||
LOGGER.warn("warning! No inner type supplied for array parameter \"" + s.getName() + "\", using String");
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator due to missing iner type definition in the spec");
|
||||
LOGGER.error("No inner type supplied for array parameter `{}`. Default to type:string", s.getName());
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator due to missing inner type definition in the spec");
|
||||
arraySchema.setItems(inner);
|
||||
}
|
||||
|
||||
@ -4373,7 +4398,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenParameter.isContainer = true;
|
||||
codegenParameter.isListContainer = true;
|
||||
codegenParameter.description = escapeText(s.getDescription());
|
||||
codegenParameter.dataType = getTypeDeclaration(s);
|
||||
codegenParameter.dataType = getTypeDeclaration(arraySchema);
|
||||
if (codegenParameter.baseType != null && codegenParameter.enumName != null) {
|
||||
codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName);
|
||||
} else {
|
||||
@ -4522,6 +4547,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(schema);
|
||||
if (inner == null) {
|
||||
LOGGER.error("No inner type supplied for map parameter `{}`. Default to type:string", schema.getName());
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator");
|
||||
schema.setAdditionalProperties(inner);
|
||||
}
|
||||
@ -4550,10 +4576,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
final ArraySchema arraySchema = (ArraySchema) schema;
|
||||
Schema inner = arraySchema.getItems();
|
||||
if (inner == null) {
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator");
|
||||
LOGGER.error("No inner type supplied for array parameter `{}`. Default to type:string", schema.getName());
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
arraySchema.setItems(inner);
|
||||
}
|
||||
CodegenProperty codegenProperty = fromProperty("property", schema);
|
||||
CodegenProperty codegenProperty = fromProperty("property", arraySchema);
|
||||
imports.add(codegenProperty.baseType);
|
||||
CodegenProperty innerCp = codegenProperty;
|
||||
CodegenProperty mostInnerItem = innerCp;
|
||||
|
@ -708,15 +708,17 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
Schema inner = ap.getItems();
|
||||
if (inner == null) {
|
||||
LOGGER.warn(ap.getName() + "(array property) does not have a proper inner type defined.Default to string");
|
||||
LOGGER.error("`{}` (array property) does not have a proper inner type defined. Default to type:string", ap.getName());
|
||||
inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||
ap.setItems(inner);
|
||||
}
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
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");
|
||||
LOGGER.error("`{}` (map property) does not have a proper inner type defined. Default to type:string", p.getName());
|
||||
inner = new StringSchema().description("TODO default missing map inner type to string");
|
||||
p.setAdditionalProperties(inner);
|
||||
}
|
||||
return getSchemaType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
@ -742,8 +744,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
} else {
|
||||
pattern = "new ArrayList<%s>()";
|
||||
}
|
||||
|
||||
if (ap.getItems() == null) {
|
||||
return null;
|
||||
LOGGER.error("`{}` (array property) does not have a proper inner type defined. Default to type:string", ap.getName());
|
||||
Schema inner = new StringSchema().description("TODO default missing array inner type to string");
|
||||
ap.setItems(inner);
|
||||
}
|
||||
|
||||
String typeDeclaration = getTypeDeclaration(ap.getItems());
|
||||
|
Loading…
x
Reference in New Issue
Block a user