OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] oneOf discriminator type string with enum ignores model prefix and suffix names
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using version 7.00-beta, when you try to generate oneOf with discriminator property referencing to enum, then everything works fine, but once you add generate model suffix using modelNameSuffix, compilation is failing, because suffix is not added because parent model is using enum name without suffix.
openapi-generator version
7.0.0-beta
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: transactions
description: transactions
version: 1.0.0
tags:
- name: transactions
paths:
/v1/transactions:
post:
tags:
- transactions
operationId: requestTransaction
summary: Create transaction
requestBody:
description: transaction
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/TransactionCreateRequest"
responses:
200:
description: Created transaction
content:
application/json:
schema:
$ref: "#/components/schemas/TransactionCreateRequest"
components:
schemas:
TransactionCreateRequest:
type: object
required:
- assets
properties:
assets:
$ref: "#/components/schemas/TransactionAssets"
TransactionAssets:
type: object
discriminator:
propertyName: type
mapping:
CASH: "#/components/schemas/TransactionCashAssets"
ITEMS: "#/components/schemas/TransactionItemsAssets"
oneOf:
- $ref: "#/components/schemas/TransactionCashAssets"
- $ref: "#/components/schemas/TransactionItemsAssets"
properties:
type:
$ref: "#/components/schemas/TransactionAssetsType"
TransactionCashAssets:
type: object
required:
- type
- amount
properties:
type:
$ref: "#/components/schemas/TransactionAssetsType"
amount:
type: number
TransactionItemsAssets:
type: object
required:
- type
- items
properties:
type:
$ref: "#/components/schemas/TransactionAssetsType"
items:
type: number
TransactionAssetsType:
type: string
enum:
- CASH
- ITEMS
Generation Details
<execution>
<id>client</id>
<phase>none</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/../api.yaml</inputSpec>
<generatorName>java-enhanced</generatorName>
<library>webclient</library>
<modelNameSuffix>Dto</modelNameSuffix>
<generateApis>true</generateApis>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<generateModelTests>false</generateModelTests>
<configOptions>
<oas3>true</oas3>
<java7>true</java7>
<aotHintsEnabled>true</aotHintsEnabled>
<dateLibrary>java8-localdatetime</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useJakartaEe>true</useJakartaEe>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
<delegatePattern>true</delegatePattern>
<!--suppress UnresolvedMavenProperty -->
<additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor
</additionalModelTypeAnnotations>
</configOptions>
</configuration>
</execution>
Steps to reproduce
mvn clean install
Receive error:
[41,12] cannot find symbol
[ERROR] symbol: class TransactionAssetsType
[ERROR] location: interface com.steam.trading.api.transactions.dto.TransactionAssetsDto
Related issues/PRs
Feature was added by https://github.com/OpenAPITools/openapi-generator/issues/12412
Suggest a fix
Add logic to add suffix and prefix in templates when using enum discriminator
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 Java enhanced generator and its templates, using the provided OpenAPI declaration and modelNameSuffix=Dto configuration to reproduce the failure. Run mvn clean install and confirm that the generated TransactionAssetsDto refers to the suffixed enum type and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100