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

Generated openapi yml for @Body + String datatype variable is with errors #1930

Open
desmondblue opened this issue Jan 8, 2025 · 3 comments

Comments

@desmondblue
Copy link

Expected Behavior

There should not be any such errors coming up while generating openapi configuration

Actual Behaviour

Error while consuming generated openapi from micronaut openapi codegen plugin

Illegal schema found with non-object type combined with properties, no
properties should be defined:
class StringSchema...

Steps To Reproduce

I have an api like so:

@Operation(summary = "Execute a search to fetch a particular tea.", tags = {
          "ExampleRequests"}, security = {@SecurityRequirement(name = "bearer")})
  @ApiResponses(value = {
          @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
          @ApiResponse(responseCode = "default", description = "default errors for all error responses", content = @Content(schema = @Schema(implementation = ErrorMessage.class)))})
  @Post(value = "/example/{beverageId}/{teaId}{?reqId,maxResultCount}", processes = "application/json;charset=UTF-8")
  public HttpResponse<?> fetchSampleTea(@RequestBean ExampleRequestBean bean, @Nullable @Body String content)
  {
    bean.setPayload(content);
    return HttpResponse.ok(teaService.executeTeaSearch(bean));
  }

Now upon assembling the swagger.yml for the following requestBody gets generated like so which is incorrect:

      requestBody:
      content:
        application/json;charset=UTF-8:
          schema:
            type: string
            properties:
              payload:
                type: string
            nullable: true

I looked around for the possible causes scoured through documentations etc but could not find anything as such which may indicate I am doing something wrong. Although I could be wrong and this may not be a bug but regardless any help would be appreciated. Thanks.

Environment Information

-Operating System: Windows 11

  • Java: jdk21
  • Micronaut Core : 4.6.3
  • io.micronaut.openapi: 6.13

Example Application

No response

Version

4.6.3

@altro3
Copy link
Collaborator

altro3 commented Jan 9, 2025

Could you create full eample reproducer? In your sample code I don't see ExampleRequestBean class structure and annotations

@altro3
Copy link
Collaborator

altro3 commented Jan 9, 2025

As I understand, payload property inside ExampleRequestBean. Looks like a bug with usage @Body with String class and @RequestBean annotation together.

Please, create full sample application reproducer

@desmondblue
Copy link
Author

@altro3
I have created a sample application. I have also checked that the issue is getting reproduced in the same.
The bug seems to be stemming from String payload being initialized as null in ExampleRequestBean while being a String.
Maybe you will have a better insight into it than me.
P.S. Link to repo:
https://github.com/desmondblue/MicronautOpenAPIGenerationIssue

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

2 participants