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

Optional of List does not generate proper schema ref #809

Closed
matlach opened this issue May 28, 2021 · 0 comments · Fixed by #810
Closed

Optional of List does not generate proper schema ref #809

matlach opened this issue May 28, 2021 · 0 comments · Fixed by #810
Labels
bug Something isn't working
Milestone

Comments

@matlach
Copy link

matlach commented May 28, 2021

Hi there,

In our application we rely on Optional<...> for each of our models properties to allow us to distinguish between "undefined" vs. "null" vs. "an actual value". When generating OpenAPI all schemas are properly referenced except for array-like data structure.

For example, using WildFly 23.0.2.Final which bundle SmallRye OpenAPI 2.1.2:

@Path("/aresources")
public class AResource {
    public static class A {
        public UUID id;
        public Optional<B> optionalOfB;
        public List<B> listOfB;
        public Optional<List<B>> optionalListOfB;
    }

    public static class B {
        public UUID id;
    }

    @GET @Path("/") @Operation(summary = "List A")
    public List<A> listA() {
        return Collections.emptyList();
    }
}

will generate the following yaml (excerpt):

openapi: 3.0.3
components:
  schemas:
    A:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/UUID'
        listOfB:
          type: array
          items:
            $ref: '#/components/schemas/B'
        optionalListOfB:
          type: object
          nullable: true
        optionalOfB:
          allOf:
          - $ref: '#/components/schemas/B'
          - nullable: true
    B:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/UUID'

but should have instead:

openapi: 3.0.3
components:
  schemas:
    A:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/UUID'
        listOfB:
          type: array
          items:
            $ref: '#/components/schemas/B'
        optionalListOfB:
          type: array
          items:
            $ref: '#/components/schemas/B'
          nullable: true
        optionalOfB:
          allOf:
          - $ref: '#/components/schemas/B'
          - nullable: true
    B:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/UUID'

I've also tested out the latest SmallRye OpenAPI 2.1.4, which had lead to the exact same result.

My guess is #210 does not cover this specific use case and/or there's an issue within the io.smallrye.openapi.runtime.util.TypeUtil.

Let me know if I can be any help to resolve this issue; this is last one preventing us migrating from Swagger to OpenAPI.

Thank you!

@MikeEdgar MikeEdgar added the bug Something isn't working label May 28, 2021
@MikeEdgar MikeEdgar added this to the 2.1.5 milestone May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants