OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Is there currently support for oneOf/anyOf keywords in API spec?

Open
#18,241 3 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

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

I am trying to generate the necessary models for my API spec in springboot, however I am noticing issues with the generated files that utilize the oneOf keyword. I’d be more than happy to give more information on the specifics I am dealing with, but I’d first like to know if this is fully supported yet in my use case (java/springboot).

openapi-generator version

Most recent version

OpenAPI declaration file content or url
OneOfJobConfigs:
      title: OneOfJobConfigs
      oneOf:
        - $ref: '#/components/schemas/ObjectiveAJobConfig'
        - $ref: '#/components/schemas/ObjectiveBJobConfig'
        - $ref: '#/components/schemas/ObjectiveCJobConfig'
      discriminator:
        propertyName: job_config
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "job_config", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = JobsConfigCreateInput.class, name = "JobsConfigCreateInput"),
  @JsonSubTypes.Type(value = ObjectiveAJobConfig.class, name = "ObjectiveAJobConfig"),
  @JsonSubTypes.Type(value = ObjectiveBJobConfig.class, name = "ObjectiveBJobConfig"),
  @JsonSubTypes.Type(value = ObjectiveCJobConfig.class, name = "ObjectiveCJobConfig")
})

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OneOfJobConfigs {
  @JsonProperty("job_config")
  @Valid 
  private ObjectiveBJobConfigJobConfig jobConfig;
  

}

This is the generated model, but I need to be able to access all three Objective#JobConfigs from this.

Generation Details

n/a

Steps to reproduce

Use oneOf somewhere in your openAPI spec, and run the generate mvn command.

Related issues/PRs
Suggest a fix

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

Start with the supplied OpenAPI oneOf schema and the generated OneOfJobConfigs Java model, then run generation with the Maven command described in the issue. Compare the generated model with ObjectiveAJobConfig, ObjectiveBJobConfig, and ObjectiveCJobConfig. Done means the generated Java models support accessing all three oneOf variants, with the discriminator behavior confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.