OpenAPITools / OpenAPITools/openapi-generator
Problem with oneOf default in generated Java client (default value = string in code)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I generated a Java client from a valid schema, but the generated source contains an error
Relevant part of the schema:
"idValue": {
"oneOf": [{
"type": "string"
}, {
"type": "integer"
}],
"default": "string"
}
The generated Java source:
public static final String JSON_PROPERTY_ID_VALUE = "idValue";
private MappingJobIdValue idValue = string;
On complile:
.../MappingJob.java:[138,39] cannot find symbol
symbol: variable string
location: class finance.auxin.restclient.openfigi.model.MappingJob
It happens when I use native and restclient libraries (I didn't test the others)
openapi-generator version
Latest stable (7.7.0)
OpenAPI declaration file content or url
Used schema: https://api.openfigi.com/schema
Generation Details
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.7.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://api.openfigi.com/schema</inputSpec>
<generatorName>java</generatorName>
<library>restclient</library>
<verbose>false</verbose>
<enablePostProcessFile>false</enablePostProcessFile>
<generateModelTests>false</generateModelTests>
<generateApiDocumentation>true</generateApiDocumentation>
<generateModelDocumentation>true</generateModelDocumentation>
<cleanupOutput>true</cleanupOutput>
<configOptions>
<packageName>${default.api.package}</packageName>
<apiPackage>${default.api.package}.api</apiPackage>
<modelPackage>${default.api.package}.model</modelPackage>
<openApiNullable>false</openApiNullable>
<useJakartaEe>true</useJakartaEe>
<dateLibrary>java8</dateLibrary>
<generateClientAsBean>true</generateClientAsBean>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
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
Reproduce generation with the linked OpenFIGI schema, Java generator 7.7.0, and the restclient or native library, then inspect the generated MappingJob.java around the idValue field. Compare the emitted default with the oneOf declaration; done means the generated Java source compiles without treating the schema's string default as an unresolved variable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100