Open tschaffter opened 1 year ago
A solution is to update the template converter.mustache
to replace {{name}}
by {{classname}}
.
package {{configPackage}};
{{#models}}
{{#model}}
{{#isEnum}}
import {{modelPackage}}.{{name}};
{{/isEnum}}
{{/model}}
{{/models}}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
@Configuration
public class EnumConverterConfiguration {
{{#models}}
{{#model}}
{{#isEnum}}
@Bean
Converter<{{{dataType}}}, {{name}}> {{classVarName}}Converter() {
return new Converter<{{{dataType}}}, {{name}}>() {
@Override
public {{name}} convert({{{dataType}}} source) {
return {{name}}.fromValue(source);
}
};
}
{{/isEnum}}
{{/model}}
{{/models}}
}
package {{configPackage}};
{{#models}}
{{#model}}
{{#isEnum}}
import {{modelPackage}}.{{classname}};
{{/isEnum}}
{{/model}}
{{/models}}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
@Configuration
public class EnumConverterConfiguration {
{{#models}}
{{#model}}
{{#isEnum}}
@Bean
Converter<{{{dataType}}}, {{classname}}> {{classVarName}}Converter() {
return new Converter<{{{dataType}}}, {{classname}}>() {
@Override
public {{classname}} convert({{{dataType}}} source) {
return {{classname}}.fromValue(source);
}
};
}
{{/isEnum}}
{{/model}}
{{/models}}
}
@tschaffter please try latest 6.3.0-SNAPSHOT
It doesn't look like the snapshot version is on Maven:
$ nx openapi-generate openchallenges-organization-service
> nx run openchallenges-organization-service:openapi-generate
Download 6.3.0-SNAPSHOT ...
Download failed, because of: "Request failed with status code 404"
Response:
connection close
content-length 554
last-modified Wed, 10 Aug 2016 15:08:35 GMT
etag "1fb066da6a67c7c02962f59b4b8cd1ee"
x-amz-error-code NoSuchKey
x-amz-error-message The specified key does not exist.
x-amz-error-detail-key maven2/org/openapitools/openapi-generator-cli/6.3.0-SNAPSHOT/openapi-generator-cli-6.3.0-SNAPSHOT.jar
content-type text/html
accept-ranges bytes
date Wed, 01 Feb 2023 01:05:03 GMT
via 1.1 varnish
age 2634770
x-served-by cache-iad-kjyo7100174-IAD
x-cache HIT
x-cache-hits 1
x-timer S1675213503.486762,VS0,VE2
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
/workspaces/sage-monorepo/node_modules/@openapitools/openapi-generator-cli/main.js:685
error ? reject(new Error(stderr)) : resolve(stdout);
^
Error: Error: Unable to access jarfile /workspaces/sage-monorepo/node_modules/@openapitools/openapi-generator-cli/versions/6.3.0-SNAPSHOT.jar
at /workspaces/sage-monorepo/node_modules/@openapitools/openapi-generator-cli/main.js:685:32
at ChildProcess.exithandler (node:child_process:427:5)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at Socket.<anonymous> (node:internal/child_process:449:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:320:12)
Node.js v18.13.0
@tschaffter 6.3.0 is not released yet & 6.3.0-SNAPSHOT is not available on maven central. Seems like CLI is now aware about snapshot versions
6.3.0-SNAPSHOT can be taken from here https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/6.3.0-SNAPSHOT/ (information taken from https://github.com/OpenAPITools/openapi-generator#11---compatibility)
Seems like CLI has an option to customize maven repository which might help you. Check this please https://github.com/OpenAPITools/openapi-generator-cli#using-custom--private-maven-registry
Note: I haven't tried this, so might not work
Bug Report Checklist
Description
OpenAPI generator generate the file
EnumConverterConfiguration.java
if the OA description includes at least one enum. The template does not take into account the generator configuration propertymodelNameSuffix
, which is used to name the DTO models. The issue is then that the classEnumConverterConfiguration
includes incorrect references to the DTO models.openapi-generator version
6.2.1
OpenAPI declaration file content or url
See this OpenAPI description (note the use of
enum
)Generation Details
openapi-generator-cli generate
Content of
EnumConverterConfiguration.java
(here the value ofmodelNameSuffix
is not used to name the models):List of DTO models generated (here the value of
modelNameSuffix
is correctly used to name the models):Steps to reproduce
openapi-generator-cli generate
Related issues/PRs
Suggest a fix