swagger-api / swagger-api/swagger-codegen

[Java] --model-name-suffix not working with oneOf

Open
#12,168 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

--model-name-suffix in combination with oneOf produces Java code that does not compile,
If model-name-suffix is dto, it generates interface with name OneOfDto while using in class as implement it use name without dto

interface generated - OneOfNodeDto.java
code generated :
public class ActionNodeDto extends NodeInstanceDto implements OneOfNode {

Swagger-codegen version

3.0.42

Swagger declaration file content or url

Node:
type: object
oneOf:
- $ref: '#/components/schemas/EventNode'
- $ref: '#/components/schemas/SwitchNode'
- $ref: '#/components/schemas/ActionNode'

ActionNode:
allOf:
- $ref: '#/components/schemas/NodeInstance'
- type: object
properties:

class generated
public class ActionNodeDto extends NodeInstanceDto implements OneOfNode {

}

Command line used for generation

generated by maven plugin

io.swagger.codegen.v3
swagger-codegen-maven-plugin
3.0.42



generate


${basedir}/src/main/resources/swagger/xyz.yaml
${project.build.directory}/generated-sources/swagger
spring
${project.groupId}.api.v1.dto
false
false
false
true
false
false
dto
false

true
java8

spring-boot



Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

allOf is generating the file with Dto and using in extends with same name with dto, only oneof has the issue, it can be handle similar to allOf

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated Java models from the supplied Node, EventNode, SwitchNode, and ActionNode schema using the Maven plugin configuration with modelNameSuffix set to dto. Compare the oneOf-generated interface reference with the allOf behavior; done means the generated ActionNodeDto references the suffixed OneOfNodeDto name and the Java output compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.