Skip to content

mikesaurus/openapi-gen-alias-type-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openapi-generator Alias Type Bug

Summary

This is an example project to demonstrate a openapi-generator bug that causes a compilation error when setting the generateAliasAsModel option to true.

Expected Behavior

When generating client code with openapi-generator and the generateAliasAsModel option set to true, standard model fields of alias object types are initialized to null or to a new instance of the alias object type, and the code compiles.

For example:

public class StandardModelClass {
  private MapAliasModelClass mapAliasModel = null;
}

or

public class StandardModelClass {
  private MapAliasModelClass mapAliasModel = new MapAliasModelClass();
}

Actual Behavior

When generating client code with openapi-generator and the generateAliasAsModel option set to true, standard model fields of alias object types are initialized to a new instance of the base object type, not the alias object type, and compilation fails.

For example:

public class StandardModelClass {
  private MapAliasModelClass mapAliasModel = new HashMap<String, String>();
}

Building

Configured for Maven 3 and Java 11. Change the <java.version> POM property if using a different Java version (and the local jenv version if using jenv).

To build, run mvn install from the project root. This will result in the following compilation error:

org/example/service/v1/model/Person.java:[76,43] incompatible types: java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> cannot be converted to org.example.service.v1.model.Relationships

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published