Open mtraynham opened 4 years ago
I also have this issue, but with the java spring generator. Could these issues be related?
@u4842 I believe the issue you linked is related and not necessarily typescript, nor java-spring or kotlin-client specific. I believe the issue is actually buried deep in the DefaultCodegen parsing of Operations and this affects all languages.
As mentioned in the Suggest a fix section, I believe the additionalProperties
on a map type don't get added to the imports
Set and thus aren't included in the generated import list of the API. I suggested maybe passing that imports
set down into the fromResponse
function so they could be added as a one-off instead of adding a new property to the CodegenOperation.
Unfortunately, I'm not entirely familiar with this code, so was hoping a maintainer could delegate best course of action.
I'm also seeing some imports that are not reflected in the project's dependencies:
com.google.gson.reflect.TypeToken;
com.squareup.okhttp.Call
okio.BufferedSink
okio.Okio
org.threeten.bp.LocalDate
and many more. 5.0.0-beta2
/edit: I had to add:
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
compile group: 'com.squareup.okhttp', name: 'logging-interceptor', version: '2.7.5'
compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.9.0'
compile group: 'org.threeten', name: 'threetenbp', version: '1.4.0'
compile group: 'io.swagger.core.v3', name: 'swagger-annotations', version: '2.1.4'
compile group: 'io.gsonfire', name: 'gson-fire', version: '1.8.4'
to get it to compile. But many of those imports are unused.
Using the latest release for a Maven project (JDK11.0.10 and Kotlin 1.4.21), here are the equivalent dependencies I needed to add explicitly in order to get the classpath to work properly:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.7</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.14.7</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.24</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.8.4</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
To find out which versions you need for your project, just go into your target/generated-sources/openapi/...
folder and check the build.gradle
file.
The underlying problem seems to be that some of the dependencies of the plugin are apparently designed to be dependencies of the project that uses the plugin. This information should be made explicit in the README
instructions if that's supposed to be intended behavior. Or, if there's an OpenAPI dependency we can add that will cover all the above, it should say to add that in the README
as a project dependency alongside the plugin.
Maven plugins are supposed to be designed (if my understanding is right) to have their own independent dependency tree, so it's not designed to include those things in the project's classpath itself (i.e. via mvn dependency:tree
).
Bug Report Checklist
Description
Generator failing to include import when an Operation's response type is
Map<List<Type>>
.For instance a function that returns
Map<List<Option>>
fails to includeOption
as part of the imports and the class becomes unable to compile.See the yaml below for the input.
The following code is generated. There is a reference to
Option
in the code, but the import is not included.openapi-generator version
4.3.0-SNAPSHOT
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
Maybe pass in the Operations
imports
Set reference to the fromResponse method and add any arbitrary imports as needed.