Skip to content

Commit 20a2bbc

Browse files
committed
minor code cleanup/refactoring using globalSchemas
1 parent d78f97b commit 20a2bbc

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
16821682
addProperties(allProperties, allRequired, child, allDefinitions);
16831683
}
16841684
}
1685-
addVars(m, unaliasPropertySchema(allDefinitions, properties), required, allProperties, allRequired);
1685+
addVars(m, unaliasPropertySchema(properties), required, allProperties, allRequired);
16861686

16871687
} else {
16881688
m.dataType = getSchemaType(schema);
@@ -1705,7 +1705,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
17051705
m.isString = Boolean.TRUE;
17061706
}
17071707

1708-
addVars(m, unaliasPropertySchema(allDefinitions, schema.getProperties()), schema.getRequired());
1708+
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired());
17091709
}
17101710

17111711
if (m.vars != null) {
@@ -2593,12 +2593,8 @@ public CodegenResponse fromResponse(OpenAPI openAPI, String responseCode, ApiRes
25932593
} else {
25942594
r.code = responseCode;
25952595
}
2596-
Schema responseSchema;
2597-
if (openAPI != null && openAPI.getComponents() != null) {
2598-
responseSchema = ModelUtils.unaliasSchema(openAPI.getComponents().getSchemas(), ModelUtils.getSchemaFromResponse(response));
2599-
} else { // no model/alias defined
2600-
responseSchema = ModelUtils.getSchemaFromResponse(response);
2601-
}
2596+
Schema responseSchema = ModelUtils.unaliasSchema(globalSchemas, ModelUtils.getSchemaFromResponse(response));
2597+
26022598
r.schema = responseSchema;
26032599
r.message = escapeText(response.getDescription());
26042600
// TODO need to revise and test examples in responses
@@ -3386,16 +3382,13 @@ protected void addImport(CodegenModel m, String type) {
33863382
/**
33873383
* Loop through propertiies and unalias the reference if $ref (reference) is defined
33883384
*
3389-
* @param allSchemas all schemas defined in the spec
33903385
* @param properties model properties (schemas)
33913386
* @return model properties with direct reference to schemas
33923387
*/
3393-
private Map<String, Schema> unaliasPropertySchema
3394-
(Map<String, Schema> allSchemas, Map<String, Schema> properties) {
3388+
private Map<String, Schema> unaliasPropertySchema(Map<String, Schema> properties) {
33953389
if (properties != null) {
33963390
for (String key : properties.keySet()) {
3397-
properties.put(key, ModelUtils.unaliasSchema(allSchemas, properties.get(key)));
3398-
3391+
properties.put(key, ModelUtils.unaliasSchema(globalSchemas, properties.get(key)));
33993392
}
34003393
}
34013394

0 commit comments

Comments
 (0)