Repository navigation
Open
Description
Description
I got the following error when generate code by using openapi-generator-maven-plugin.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project swagger-vnfm: Compilation failure
[ERROR] /swagger-vnfm/target/generated-sources/src/main/java/com/openapi/test/VimConnectionInfo.java:[43,49] incompatible types: java.lang.String cannot be converted to com.openapi.test.VimType
openapi-generator version
3.2.0
OpenAPI declaration file content or url
swagger: '2.0'
info:
description: This spec is mainly for testing
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: [email protected]
license:
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: 'petstore.swagger.io:80'
basePath: /v2
paths:
/test:
get:
description: Gets all operation occurrence resources.
responses:
'200':
description: Successful response
schema:
type: string
default:
description: Error payload
schema:
type: string
tags:
- test
schemes:
- http
definitions:
VimType:
description: Type of the VIM info structure.
type: string
enum:
- OPENSTACK_V2
- OPENSTACK_V3
- VMWARE_VCLOUD
- OTHER_VIM_INFO
VimConnectionInfo:
type: object
required:
- id
- vimType
discriminator: vimType
properties:
id:
description: Identifier of the VIM
type: string
vimType:
$ref: '#/definitions/VimType'
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'Command line used for generation
mvn clean compile
Steps to reproduce
The maven pom.xml is
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vnfm.model</groupId>
<artifactId>swagger-vnfm</artifactId>
<packaging>jar</packaging>
<version>DYNAMIC-SNAPSHOT</version>
<name>swagger-vnfm</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<swagger-core-version>1.5.21</swagger-core-version>
<gson-version>2.8.1</gson-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>lcm-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.yaml</inputSpec>
<language>java</language>
<generateApis>false</generateApis>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<skipOverwrite>true</skipOverwrite>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<output>${project.build.directory}/generated-sources</output>
<modelPackage>com.openapi.test</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Related issues/PRs
No
Suggest a fix/enhancement
Metadata
Metadata
Assignees
Labels
No labels
Activity
jmini commentedon Aug 14, 2018
Thank you for this feedback. It is very valuable.
I think the specific issue is that your discriminator is an enum. This might be not supported yet.
Other question from my side:
Is your spec complete? What is the idea behind using a discriminator here? There is no mapping and no ComposedSchema (
oneOf,allOf).yuanpli commentedon Aug 14, 2018
Hi,
This swagger is provided by collaborator, and what I used here is simplified for the privacy policy. The whole definition for object
VimConnectionInfois posted as below. And there is a explanation for why used discriminator"Type of the VIM info structure. This field will be used as a discriminator for different types of VIMs.OTHER_VIM_INFOis provided for forward compatibility with later microversions of the API."yuanpli commentedon Aug 17, 2018
Any update?
jmini commentedon Aug 17, 2018
Feel free to propose a pull request
keenanpepper commentedon Oct 18, 2019
This issue appears to be fixed in 4.1.3.
antweb commentedon Feb 4, 2020
Using an enum descriminator is still broken on 4.2.3 and the current master (4.3.0-SNAPSHOT).
I built a simple example based on the OpenAPI docs:
Generated with
The issue seems to be this line in the constructor of the base type (
Pet):which doesn't compile unless
petTypeis a String. The fix should be rather simple. Whenever the discriminator is an enum, the constructor should be something like this:mukhiparshant commentedon Jun 9, 2021
Any update on this?
aeneasr commentedon Sep 4, 2021
It appears this is still an issue if we have a discriminator but only one available option:
Will cause:
This works:
jasonrberk commentedon Oct 6, 2021
exact same issue with 5.2.1 today. I can't change the spec file, as it's provided by a vendor. Not sure what my options are....
EDIT:
I switched to https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin and used
<version>3.0.29</version>and my models are generated successfullyto see available configOptions use
java -jar ./swagger-codegen-cli.jar config-help -l javajohnlinp commentedon Nov 10, 2021
I don't think @antweb's proposed fix is a general fix. It will work on @antweb's example because the enum values (i.e.
Cat,Dog,Lizard) are exactly the same with the class names. It won't work if the enum values and class names don't match, e.g. the enum values change into something likeCAT_TYPE,DOG_TYPE,LIZARD_TYPE.[Java][Client] Add support for enum-typed discriminator
dnievas-tr commentedon Feb 14, 2022
I'm also experiencing this issue.
dev-velo commentedon Dec 9, 2022
Same here as well
CSALS commentedon Oct 14, 2023
Still facing this issue in 2023 :(
bedaka commentedon Nov 28, 2023
Same here
javabean68 commentedon Dec 16, 2023
Same here
jesudornenkrone commentedon May 8, 2024
I ran into the same problem yesterday. Any ideas or plans?
kunalpmj commentedon Jun 4, 2024
I am also experiencing same issue
Alamonall commentedon Jun 10, 2024
Same...
kmunees commentedon Dec 20, 2024
I am also facing the issue. is this fixed on any particular version?