forked from loafle/openapi-generator-original
Initialization of typeAliases was triggered by fromModel(...), which is incorrect. (#14054)
When fromOperation(...) was called before fromModel, the aliases were uninitialized. (cherry picked from commit 44ea23168362cfacf8a61ff944701990cf3fea76) Co-authored-by: Clemens Heppner <ch@wps.de>
This commit is contained in:
+4
-5
@@ -242,7 +242,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// Then translated back during JSON encoding and decoding
|
||||
protected Map<String, String> specialCharReplacements = new LinkedHashMap<>();
|
||||
// When a model is an alias for a simple type
|
||||
protected Map<String, String> typeAliases = null;
|
||||
protected Map<String, String> typeAliases = Collections.emptyMap();
|
||||
protected Boolean prependFormOrBodyParameters = false;
|
||||
// The extension of the generated documentation files (defaults to markdown .md)
|
||||
protected String docExtension;
|
||||
@@ -844,6 +844,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// Set global settings such that helper functions in ModelUtils can lookup the value
|
||||
// of the CLI option.
|
||||
ModelUtils.setDisallowAdditionalPropertiesIfNotPresent(getDisallowAdditionalPropertiesIfNotPresent());
|
||||
|
||||
// Multiple operations rely on proper type aliases, so we should always update them
|
||||
typeAliases = getAllAliases(ModelUtils.getSchemas(openAPI));
|
||||
}
|
||||
|
||||
// override with any message to be shown right before the process finishes
|
||||
@@ -2861,10 +2864,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema schema) {
|
||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
||||
if (typeAliases == null) {
|
||||
// Only do this once during first call
|
||||
typeAliases = getAllAliases(allDefinitions);
|
||||
}
|
||||
|
||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||
if (schema.equals(trueSchema)) {
|
||||
|
||||
+1
@@ -1763,6 +1763,7 @@ public class DefaultCodegenTest {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/component-deprecated.yml");
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
CodegenModel codegenPetModel = codegen.fromModel("Pet", openAPI.getComponents().getSchemas().get("Pet"));
|
||||
Assert.assertTrue(codegenPetModel.isDeprecated);
|
||||
|
||||
+1
@@ -864,6 +864,7 @@ public class AbstractJavaCodegenTest {
|
||||
public void testOneOfModelImports() throws Exception {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/oneOf_nonPrimitive.yaml");
|
||||
final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Schema<?> schema = openAPI.getComponents().getSchemas().get("Example");
|
||||
|
||||
+1
@@ -263,6 +263,7 @@ public class AbstractKotlinCodegenTest {
|
||||
public void testEnumPropertyWithDefaultValue() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/kotlin/issue10591-enum-defaultValue.yaml");
|
||||
final AbstractKotlinCodegen codegen = new P_AbstractKotlinCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Schema test1 = openAPI.getComponents().getSchemas().get("ModelWithEnumPropertyHavingDefault");
|
||||
CodegenModel cm1 = codegen.fromModel("ModelWithEnumPropertyHavingDefault", test1);
|
||||
|
||||
+2
@@ -132,6 +132,7 @@ public class AbstractPhpCodegenTest {
|
||||
public void testArrayOfArrays() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_8945.yaml");
|
||||
final AbstractPhpCodegen codegen = new P_AbstractPhpCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Schema test1 = openAPI.getComponents().getSchemas().get("MyResponse");
|
||||
CodegenModel cm1 = codegen.fromModel("MyResponse", test1);
|
||||
@@ -150,6 +151,7 @@ public class AbstractPhpCodegenTest {
|
||||
public void testEnumPropertyWithDefaultValue() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/php/issue_10244.yaml");
|
||||
final AbstractPhpCodegen codegen = new P_AbstractPhpCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Schema test1 = openAPI.getComponents().getSchemas().get("ModelWithEnumPropertyHavingDefault");
|
||||
CodegenModel cm1 = codegen.fromModel("ModelWithEnumPropertyHavingDefault", test1);
|
||||
|
||||
+2
@@ -180,6 +180,7 @@ public class TypeScriptNodeClientCodegenTest {
|
||||
.addSchemas("Child", childSchema);
|
||||
|
||||
final TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
codegen.setModelNameSuffix("Suffix");
|
||||
|
||||
final HashMap<String, ModelsMap> allModels = createParameterForPostProcessAllModels(
|
||||
@@ -209,6 +210,7 @@ public class TypeScriptNodeClientCodegenTest {
|
||||
.addSchemas("Child", childSchema);
|
||||
|
||||
final TypeScriptNodeClientCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
codegen.setModelNamePrefix("Prefix");
|
||||
|
||||
final HashMap<String, ModelsMap> allModels = createParameterForPostProcessAllModels(
|
||||
|
||||
Reference in New Issue
Block a user