Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix
  • Loading branch information
martin-mfg committed Jan 14, 2024
commit 5141bfcf1deaf63d6bc10c9b0d8c6b95917f7fea
Original file line number Diff line number Diff line change
Expand Up @@ -7353,7 +7353,26 @@ protected void addBodyModelSchema(CodegenParameter codegenParameter, String name
}

protected void updateRequestBodyForMap(CodegenParameter codegenParameter, Schema schema, String name, Set<String> imports, String bodyParameterName) {
if (StringUtils.isNotBlank(name) && !(ModelUtils.isFreeFormObject(schema) && !ModelUtils.shouldGenerateFreeFormObjectModel(name, this))) {
boolean useModel = true;
if (StringUtils.isNotBlank(name)) {
if (ModelUtils.isFreeFormObject(schema)) {
if (!ModelUtils.shouldGenerateFreeFormObjectModel(name, this)) {
useModel = false;
}
} else if (ModelUtils.isMapSchema(schema)) {
if (!ModelUtils.shouldGenerateMapModel(schema)) {
useModel = false;
}
} else if (ModelUtils.isArraySchema(schema)) {
if (!ModelUtils.shouldGenerateArrayModel(schema)) {
useModel = false;
}
}
} else {
useModel = false;
}

if (useModel) {
this.addBodyModelSchema(codegenParameter, name, schema, imports, bodyParameterName, true);
} else {
Schema inner = ModelUtils.getAdditionalProperties(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,13 @@ void generateModels(List<File> files, List<ModelMap> allModels, List<String> unu
continue;
}
} else if (ModelUtils.isMapSchema(schema)) { // check to see if it's a "map" model
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
// in the inner schemas, and the outer schema does not have properties.
if (!ModelUtils.isGenerateAliasAsModel(schema) && !ModelUtils.isComposedSchema(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
if (!ModelUtils.shouldGenerateMapModel(schema)) {
// schema without property, i.e. alias to map
LOGGER.info("Model {} not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)", name);
continue;
}
} else if (ModelUtils.isArraySchema(schema)) { // check to see if it's an "array" model
if (!ModelUtils.isGenerateAliasAsModel(schema) && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
if (!ModelUtils.shouldGenerateArrayModel(schema)) {
// schema without property, i.e. alias to array
LOGGER.info("Model {} not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)", name);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,17 @@ public static boolean shouldGenerateFreeFormObjectModel(String name, CodegenConf
return unaliasedSchema.get$ref() != null;
}

public static boolean shouldGenerateMapModel(Schema schema) {
// A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
// for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
// in the inner schemas, and the outer schema does not have properties.
return ModelUtils.isGenerateAliasAsModel(schema) || ModelUtils.isComposedSchema(schema) || !(schema.getProperties() == null || schema.getProperties().isEmpty());
}

public static boolean shouldGenerateArrayModel(Schema schema) {
return ModelUtils.isGenerateAliasAsModel(schema) || !(schema.getProperties() == null || schema.getProperties().isEmpty());
}

/**
* If a Schema contains a reference to another Schema with '$ref', returns the referenced Schema if it is found or the actual Schema in the other cases.
*
Expand Down