OpenAPITools / OpenAPITools/openapi-generator
jaxrs-jersey: Problem with nonexisting import and wildcard responsecode
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The generator creates non compilable java code.
Contains the response a schema with oneOf, the created code references to an class OneOfxxx. In my examlple de.test.openapi.server.model.OneOfCatDog. But the file will not be generated, so the code doesn't compile.
Furthermore if I add a wildcard response like '5XX' as described here https://swagger.io/docs/specification/describing-responses/. I'll get an annotation like this @io.swagger.annotations.ApiResponse(code = 5XX, message = "General server error", response = Void.class The problem here is, that code is defined as an integer. So it won't compile.
openapi-generator version
openapi-generator-maven-plugin 4.2.3
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server. You can find out more about Swagger
at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For
this sample, you can use the api key `special-key` to test the authorization filters.'
termsOfService: http://swagger.io/terms/
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: https://petstore.swagger.io/v2
- url: http://petstore.swagger.io/v2
paths:
/petData/{type}/{id}:
get:
summary: Description
description: Get
operationId: getPet
parameters:
- in: path
name: type
description: reference for dataType
required: true
schema:
$ref: '#/components/schemas/Datatypes'
- in: path
name: id
description: reference
required: true
schema:
type: string
responses:
'200':
description: deliver existing data
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
'5XX':
description: General server error
content: {}
security:
- petstore_auth:
- write:pets
- read:pets
x-codegen-request-body-name: body
components:
schemas:
Datatypes:
type: string
enum: [cat, dog]
Cat:
type: object
required: [id]
properties:
id:
type: string
name:
type: string
age:
type: integer
Dog:
type: object
required: [id]
properties:
id:
type: string
name:
type: string
securitySchemes:
petstore_auth:
type: oauth2
flows:
implicit:
authorizationUrl: http://petstore.swagger.io/oauth/dialog
scopes:
write:pets: modify pets in your account
read:pets: read your pets
api_key:
type: apiKey
name: api_key
in: header
Command line used for generation
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.test</groupId>
<artifactId>openapi</artifactId>
<name>openapi test</name>
<version>1.0.0-SNAPSHOT</version>
<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.18</swagger-core-version>
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
<jersey2-version>2.22.2</jersey2-version>
<jackson-version>2.9.9</jackson-version>
<junit-version>4.13</junit-version>
<logback-version>1.1.7</logback-version>
<servletapi-version>3.1.0</servletapi-version>
</properties>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<scope>compile</scope>
<version>${swagger-core-version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback-version}</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servletapi-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey2-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey2-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api2.yaml</inputSpec>
<output>${project.basedir}</output>
<generatorName>jaxrs-jersey</generatorName>
<configOptions>
<generatePom>true</generatePom>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>jersey2</library>
<sourceFolder>src/main/generated</sourceFolder>
<implFolder>src/main/java</implFolder>
<apiPackage>de.test.openapi.server</apiPackage>
<invokerPackage>de.test.openapi.server.invoker</invokerPackage>
<modelPackage>de.test.openapi.server.model</modelPackage>
</configOptions>
<generateSupportingFiles>true</generateSupportingFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Steps to reproduce
run maven compile
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the api2.yaml reproduction and the jaxrs-jersey generator configuration shown in the issue, then run maven compile. Trace the generated model reference for the oneOf response and the ApiResponse annotation for the 5XX response. Done means the generated Java code compiles for both cases without the missing class or invalid integer annotation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100