swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
but when CodeGen generate the Java client code, it set date as OffsetDateTime. So to use Instant instead I use options typeMapping and importMapping to change Types. It work well for generated models classes but not for Api classes. Where type mapping work but not import mapping and the code does not compile.
output from mvn package
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/hugo/IdeaProjects/perso/tut-rest/rest/src/main/java/com/test/generated/api/EmployeeControllerApi.java:[262,45] cannot find symbol
symbol: class Instant
location: class com.test.generated.api.EmployeeControllerApi
And the compiled code Have the rigth type mapping
public ResourcesEmployee searchUsingGET(Instant searchAfter) throws RestClientException
But Instant is not imported
Swagger-codegen version
Tried with swagger-codegen-maven-plugin version 2.4.7
Command line used for generation
I use the maven plugin to generate the code but this command line to the trick
Description
I have an Api that use
java.time.Instant
as request parameter.but when CodeGen generate the Java client code, it set date as
OffsetDateTime
. So to use Instant instead I use optionstypeMapping
andimportMapping
to change Types. It work well for generated models classes but not for Api classes. Where type mapping work but not import mapping and the code does not compile.output from
mvn package
And the compiled code Have the rigth type mapping
But
Instant
is not importedSwagger-codegen version
Tried with
swagger-codegen-maven-plugin
version 2.4.7Command line used for generation
I use the maven plugin to generate the code but this command line to the trick
Steps to reproduce
GET
endpoint that usejava.time.Instant
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate --library=resttemplate -i http://localhost:8080/v2/api-docs -l java --type-mappings OffsetDateTime=Instant --import-mappings java.time.OffsetDateTime=java.time.Instant -DdateLibrary=java8
Suggest a fix/enhancement
I don't really know how to solve this now but I'm pretty sure it's around this line https://github.com/swagger-api/swagger-codegen/blob/83a3de0a970f0fd23cbc44ae87e0484aaaacd450/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java#L989
if I print the values in
AllImport
the value specified in--import-mapping
is missing