Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty propert
*/
protected Map<String, Schema> getModelNameToSchemaCache() {
if (modelNameToSchemaCache == null) {
// Create a cache to efficiently lookup schema based on model name.
Map<String, Schema> m = new HashMap<>();
ModelUtils.getSchemas(openAPI).forEach((key, schema) -> m.put(toModelName(key), schema));
modelNameToSchemaCache = Collections.unmodifiableMap(m);
Expand Down Expand Up @@ -1060,6 +1059,7 @@ public void setOpenAPI(OpenAPI openAPI) {
once(LOGGER).warn(UNSUPPORTED_V310_SPEC_MSG);
}
this.openAPI = openAPI;
this.modelNameToSchemaCache = null;
// Set global settings such that helper functions in ModelUtils can lookup the value
// of the CLI option.
ModelUtils.setDisallowAdditionalPropertiesIfNotPresent(getDisallowAdditionalPropertiesIfNotPresent());
Expand Down Expand Up @@ -7166,18 +7166,15 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
}

String varDataType = var.mostInnerItems != null ? var.mostInnerItems.dataType : var.dataType;
Optional<Schema> referencedSchema = ModelUtils.getSchemas(openAPI).entrySet().stream()
.filter(entry -> Objects.equals(varDataType, toModelName(entry.getKey())))
.map(Map.Entry::getValue)
.findFirst();
String dataType = (referencedSchema.isPresent()) ? getTypeDeclaration(referencedSchema.get()) : varDataType;
Schema referencedSchema = getModelNameToSchemaCache().get(varDataType);
String dataType = referencedSchema != null ? getTypeDeclaration(referencedSchema) : varDataType;
List<EnumVarMap> enumVars = buildEnumVars(values, dataType);
postProcessEnumVars(enumVars);

// if "x-enum-varnames" or "x-enum-descriptions" defined, update varnames
Map<String, Object> extensions = var.mostInnerItems != null ? var.mostInnerItems.getVendorExtensions() : var.getVendorExtensions();
if (referencedSchema.isPresent()) {
extensions = referencedSchema.get().getExtensions();
if (referencedSchema != null) {
extensions = referencedSchema.getExtensions();
}
updateEnumVarsWithExtensions(enumVars, extensions, dataType);
allowableValues.put(ENUM_VARS, enumVars);
Expand Down
Loading