Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
6 tasks
azadebrahimian opened this issue Mar 27, 2024 · 3 comments
Open
6 tasks

Comments

@azadebrahimian
Copy link

azadebrahimian commented Mar 27, 2024

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
@sfumarolo
Copy link

I'm having similar issues with an anyOf in the National Weather Service's public API.

    JsonLdContext:
      anyOf:
        -
          type: array
          items: {  }
        -
          type: object

The code generated can't handle when an Array is returned, even though the spec says it should be fine.

@wing328
Copy link
Member

wing328 commented Apr 4, 2024

please try java (jesery2) client generator with the latest master as we've merged a PR to support array in oneOf

you can find snapshot version in project's readme.

@wing328
Copy link
Member

wing328 commented Apr 8, 2024

just merged #18324 to provide array type support in anyOf, oneOf,

please give it a try with the snapshot version (which will be published soon as part of the CI workflow)

snapshot version can be found in the project's readme.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants