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

Generating examples for generic type in request body with annotation #2816

Open
Bartosz389 opened this issue Dec 17, 2024 · 0 comments
Open

Comments

@Bartosz389
Copy link

Is your feature request related to a problem? Please describe.

Hi,

We are working on Java 17 with 'org.springframework.boot' version '3.2.3'.
My problem is that I want to generate an openApi description for one POST endpoint which in request body is using a generic type.
It is easy to generate a schema with @Schema(oneOf = Foo.class, Bar.class) for a generic object
Example:

public class ImportBar<T extends ImportableFoo> {
private UUID uuid;
@Schema(decsription = "where are my examples!?", oneOf = Foo.class, Bar.class)
private T genericItem;
}

I know that Swagger is not your project but if I visualise this in Swagger I will have list of schemas but ony one example of request body with fields given by Foo.class.
But when there is an "examples" field in OpenApi I have a drop down so I can choose an example.

What I would like to have is to obtain something I can do with annotation @ExampleObject - but using my actual java classes not the String. I have 6 implementations of ImportableFoo and each have 25 fields. It is not possible to mantain it using String in annotations.

So my desired OpenApi:

  /import/foo:
    post:
      tags:
      - bar-controller
      operationId: importFoo
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/ImportRequestImportableFoo'
            examples:
              MessageItem: 

Describe the solution you'd like

I would like that "exaples" would be generated - I think based on the schemas as there I can specify example for each one with annotation @Schema(name = foo, example = "bar") - with some annotation or extended version of @ExampleObject annotation in controller

Describe alternatives you've considered

Using @ExampleObject with serialized class as String is not really a solution for this problem

Additional context

  • Add any other context or screenshots about the feature request here.
    Zrzut ekranu z 2024-12-17 10-38-43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant