OpenAPITools / OpenAPITools/openapi-generator

Problem with oneOf default in generated Java client (default value = string in code)

Open
#19,147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.