Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MicroProfile OpenAPI generation does not support anyOf or oneOf for schema type array #35948

Closed
colesturza opened this issue Sep 15, 2023 · 4 comments

Comments

@colesturza
Copy link

colesturza commented Sep 15, 2023

Describe the bug

I am trying to define a response type that looks like the following in OpenAPI.

responses:
   "200":
   description: OK
   content:
     application/json:
       schema:
         type: array
         items:
           anyOf:
           - $ref: '#/components/schemas/SubClassADto'
           - $ref: '#/components/schemas/SubClassBDto'
           - $ref: '#/components/schemas/SubClassCDto'

I'm using the following MicroProfile OpenAPI annotations to do so.

@APIResponse(responseCode = "200", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.ARRAY, anyOf = { SubClassADto.class, SubClassBDto.class, SubClassCDto.class })))

However, Quarkus' MicroProfile OpenAPI generator does not generate the proper OpenAPI specification for either anyOf or oneOf. It is generating a invalid specification that does not make sense instead.

Expected behavior

The Quarkus' MicroProfile OpenAPI generator should generate the following specification for an array type that utilizes the anyOf or oneOf field.

anyOf:

@Schema(type = SchemaType.ARRAY, anyOf = { ... })
 schema:
   type: array
   items:
     anyOf:
     - ...

oneOf:

@Schema(type = SchemaType.ARRAY, oneOf= { ... })
 schema:
   type: array
   items:
     oneOf:
     - ...

Actual behavior

The Quarkus' MicroProfile OpenAPI generator presently generates the following specification for an array type that utilizes the anyOf or oneOf field.

anyOf:

@Schema(type = SchemaType.ARRAY, anyOf = { ... })
 schema:
   type: array
   anyOf:
   - ...

oneOf:

@Schema(type = SchemaType.ARRAY, oneOf= { ... })
 schema:
   type: array
   oneOf:
   - ...

How to Reproduce?

Reproducer: https://github.com/colesturza/quarkus-microprofile-openapi-bug-reproducer

Output of uname -a or ver

Linux desktop 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.8" 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7-Ubuntu-122.04)
OpenJDK 64-Bit Server VM (build 17.0.8+7-Ubuntu-122.04, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.11.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Tested with Gradle 8.2.1 and Apache Maven 3.9.3

Additional information

No response

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 15, 2023

/cc @EricWittmann (openapi), @MikeEdgar (openapi), @evanchooly (kotlin), @geoand (kotlin), @phillip-kruger (openapi)

@colesturza
Copy link
Author

Sorry about the Kotlin tag, I originally had the full output of gradlew --version and it contained the Kotlin version.

@MikeEdgar
Copy link
Contributor

@colesturza , it's not ideal, but you should be able to do something like the following.

@Schema(anyOf = { SubClassADto.class, SubClassBDto.class, SubClassCDto.class })
static class MyResponseItem {
}

Then you can use @Schema(implementation = MyResponseItem[].class) to use the referenced class as the schema of the array items.

@gsmet
Copy link
Member

gsmet commented Nov 22, 2024

The question has been answered AFAICS.

@gsmet gsmet closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
@gsmet gsmet added kind/question Further information is requested and removed kind/bug Something isn't working labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants