[BUG] [Java] JAX-RS Jersey Compile errors when using oneOf in OpenApi definition
Bug Report Checklist
- [ x] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [ x] Have you searched for related issues/PRs?
- [ x] What's the actual output vs expected output?
- [ x] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have the validated the following openapi.yaml that uses the oneOf keyword and I tried the latest openapi-generator-cli-5.0.0-beta3 and the stable openapi-generator-cli-4.3.1 to create a server stub for JAX-RS Jersey:
openapi: 3.0.0
info:
version: 0.0.1
title: oneOf example
description: ''
paths:
/animal:
post:
summary: Create a new animal
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Animal'
responses:
'201':
description: Created
components:
schemas:
Animal:
type: object
properties:
name:
type: string
props:
oneOf:
- $ref: '#/components/schemas/Fish'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: animalType
Fish:
type: object
properties:
animalType:
type: string
depth:
type: integer
required:
- depth
- animalType
additionalProperties: false
Dog:
type: object
properties:
animalType:
type: string
country:
type: string
required:
- country
- animalType
additionalProperties: false
The generated jax-rs server code produces the following compile error. This error with produced by both tested openapi-generator versions (4.3.1 and 5.0.0-beta3) even though the bugfix of #7263 in 5.0.0-beta3 should have resolved the issue.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project openapi-jaxrs-server: Compilation failure: Compilation failure:
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[21,30] cannot find symbol
[ERROR] symbol: class OneOfFishDog
[ERROR] location: package org.openapitools.model
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[41,11] cannot find symbol
[ERROR] symbol: class OneOfFishDog
[ERROR] location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[63,23] cannot find symbol
[ERROR] symbol: class OneOfFishDog
[ERROR] location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[75,10] cannot find symbol
[ERROR] symbol: class OneOfFishDog
[ERROR] location: class org.openapitools.model.Animal
[ERROR] /debugging/openapi-5.0.3-beta/jax-rs-server/src/gen/java/org/openapitools/model/Animal.java:[79,24] cannot find symbol
[ERROR] symbol: class OneOfFishDog
[ERROR] location: class org.openapitools.model.Animal
openapi-generator version
- stable: 4.3.1
- latest snapshot: 5.0.0-beta3
Generation Details
java -jar openapi-generator-cli-5.0.0-beta.jar generate -i openapi.yaml -g jaxrs-jersey -o jax-rs-server/
Steps to reproduce
- create directory
debugging - save the above definition to
debugging/openapi.yaml - download openapi-generator to
debugging - mkdir
debugging/jax-rs-jersey cd debugging && ava -jar openapi-generator-cli-5.0.0-beta3.jar generate -i openapi.yaml -g jaxrs-jersey -o jax-rs-server/
Related issues/PRs
#7263
#7789
#7414
#7256
#7235
Sponsorship
I am happy to sponsor this fix with 200$ cc @wing328
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
Ran into the same issue. Is there any workaround for this issue?
This has apparently been solved.
I just tested with OpenAPI Generator 7.0.1 and didn't encounter any compiler errors.