forked from loafle/openapi-generator-original
fix parent name look up using schema name (#17807)
This commit is contained in:
@@ -51,8 +51,11 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
public Set<String> oneOf = new TreeSet<>();
|
||||
public Set<String> allOf = new TreeSet<>();
|
||||
|
||||
// The schema name as written in the OpenAPI document.
|
||||
// The schema name as written in the OpenAPI document
|
||||
// If it's a reserved word, it will be escaped.
|
||||
public String name;
|
||||
// The original schema name as written in the OpenAPI document.
|
||||
public String schemaName;
|
||||
// The language-specific name of the class that implements this schema.
|
||||
// The name of the class is derived from the OpenAPI schema name with formatting rules applied.
|
||||
// The classname is derived from the OpenAPI schema name, with sanitization and escaping rules applied.
|
||||
@@ -492,6 +495,15 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
|
||||
public void setSchemaName(String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
|
||||
public List<CodegenProperty> getOptionalVars() {
|
||||
return optionalVars;
|
||||
}
|
||||
@@ -1144,6 +1156,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
Objects.equals(oneOf, that.oneOf) &&
|
||||
Objects.equals(allOf, that.allOf) &&
|
||||
Objects.equals(name, that.name) &&
|
||||
Objects.equals(schemaName, that.schemaName) &&
|
||||
Objects.equals(classname, that.classname) &&
|
||||
Objects.equals(title, that.title) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
@@ -1192,7 +1205,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getParent(), getParentSchema(), getInterfaces(), getAllParents(), getParentModel(),
|
||||
getInterfaceModels(), getChildren(), anyOf, oneOf, allOf, getName(), getClassname(), getTitle(),
|
||||
getInterfaceModels(), getChildren(), anyOf, oneOf, allOf, getName(), getSchemaName(), getClassname(), getTitle(),
|
||||
getDescription(), getClassVarName(), getModelJson(), getDataType(), getXmlPrefix(), getXmlNamespace(),
|
||||
getXmlName(), getClassFilename(), getUnescapedDescription(), getDiscriminator(), getDefaultValue(),
|
||||
getArrayModelType(), isAlias, isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble,
|
||||
@@ -1214,6 +1227,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("CodegenModel{");
|
||||
sb.append("name='").append(name).append('\'');
|
||||
sb.append(", schemaName='").append(schemaName).append('\'');
|
||||
sb.append(", parent='").append(parent).append('\'');
|
||||
sb.append(", parentSchema='").append(parentSchema).append('\'');
|
||||
sb.append(", interfaces=").append(interfaces);
|
||||
|
||||
@@ -667,14 +667,16 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
parent.getChildren().add(cm);
|
||||
parent.hasChildren = true;
|
||||
Schema parentSchema = this.openAPI.getComponents().getSchemas().get(parent.name);
|
||||
Schema parentSchema = this.openAPI.getComponents().getSchemas().get(parent.schemaName);
|
||||
if (parentSchema == null) {
|
||||
throw new NullPointerException(parent.name + " in " + this.openAPI.getComponents().getSchemas());
|
||||
}
|
||||
if (parentSchema.getDiscriminator() == null) {
|
||||
parent = allModels.get(parent.getParent());
|
||||
} else {
|
||||
LOGGER.warn("Failed to look up parent schema: {}", parent.schemaName);
|
||||
parent = null;
|
||||
} else {
|
||||
if (parentSchema.getDiscriminator() == null) {
|
||||
parent = allModels.get(parent.getParent());
|
||||
} else {
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3122,6 +3124,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
m.name = name;
|
||||
}
|
||||
m.schemaName = name; // original schema name
|
||||
m.title = escapeText(schema.getTitle());
|
||||
m.description = escapeText(schema.getDescription());
|
||||
m.unescapedDescription = schema.getDescription();
|
||||
|
||||
Reference in New Issue
Block a user