swagger-api / swagger-api/swagger-codegen
[JAVASpring] Incorrect model classnames but only in lists?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Since our main.yaml was getting oversized way too quickly we decided to split the file up in separate files and $ref them in the main.yaml. However when using the following code
details:
type: array
items:
$ref: './DetailDto.yaml'
The DetailDto is generated correctly but the details list will look for the following class SchemasDetailDtoYaml.java which seems to be the path. When everything was in a single file and we referenced #/components/schemas/DetailDto everything was fine.
Swagger-codegen version
3.0.55, also broken in 3.0.52. Haven't used any other version yet
Swagger declaration file content or url
Main.yaml
DataDto:
$ref: './schemas/DataDto.yaml'
DetailDto:
$ref: './schemas/DetailDto.yaml'
Data.yaml
type: object
properties:
details:
type: array
items:
$ref: './DetailDto.yaml'
Command line used for generation
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.52</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api/main.yaml</inputSpec>
<!-- allows you to generate a list of configuration options, won't generate code if enabled -->
<!-- <configHelp>true</configHelp>-->
<output>src/main/java</output>
<templateDirectory>${project.basedir}/templates</templateDirectory>
<language>spring</language>
<modelPackage>org.joorz.project.dto.generated</modelPackage>
<apiPackage>org.joorz.project.service.generated</apiPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<dateLibrary>java8</dateLibrary>
<sourceFolder>/</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Create the yaml files like mentioned above
- Execute maven build command
- Get compile errors
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 by reproducing the generated-name mismatch with Main.yaml, Data.yaml, and DetailDto.yaml using the shown swagger-codegen Maven plugin configuration. Inspect how the Spring generator resolves the relative $ref inside the array, then verify that the generated list refers to DetailDto rather than SchemasDetailDtoYaml and that the project compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring, yaml
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100