Skip to content

Map Fields Disappear with Groovy on Classpath #2046

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

Closed
JosephWitthuhnTR opened this issue Jan 18, 2023 · 2 comments
Closed

Map Fields Disappear with Groovy on Classpath #2046

JosephWitthuhnTR opened this issue Jan 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@JosephWitthuhnTR
Copy link

JosephWitthuhnTR commented Jan 18, 2023

Issue Description

When Groovy is on the classpath at the same time as springdoc-openapi-starter-webmvc-ui, Map fields do not show up in the generated Open API spec (and therefore, they also don't show up in the Swagger UI). This happens just when Groovy is on the classpath, even if we are not using it.

In the example below, when it works (without Groovy on the classpath), both fields show up in the spec/UI. But adding Groovy causes the Map field to disappear from both.

Reproducing the Issue

For example, if I have this model class, TestRequest.java with two fields and basic getters/setters:

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;

public class TestRequest {
  @Schema(description = "Joe was here with a tuna melt!")
  private String joeWasHere;

  @Schema(description = "This is an example of a map that does not work.!")
  private Map<String, String> testingTheMap;

  public String getJoeWasHere() { return joeWasHere; }
  public void setJoeWasHere(String joeWasHere) { this.joeWasHere = joeWasHere; }
  public Map<String, String> getTestingTheMap() { return testingTheMap; }
  public void setTestingTheMap(Map<String, String> testingTheMap) { this.testingTheMap = testingTheMap; }
}

And a controller that doesn't do much but have one endpoint that takes this request class as a request body (although the same problem applies to responses and other spec generation):

import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {
  @PostMapping
  @ApiResponse(responseCode = "200", description = "Random endpoint.")
  @ResponseStatus(HttpStatus.OK)
  public void testingMethod(@RequestBody TestRequest testRequest) {
    System.out.println("Method was run!");
  }
}

This works fine if I run this application with just these two dependencies:

  • org.springframework.boot:spring-boot-starter-web:3.0.1
  • org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2

But the exact same project does not work if I simply add org.apache.groovy:groovy:4.0.7 to the classpath (and make no other changes). I have confirmed that the issue seems to also exist for 2.0.0 and 2.0.1 of the springdoc-openapi-starter-webmvc-ui modules, and that the problem also exists if I downgrade Groovy to 4.0.6.

I'll also note that this problem doesn't occur if you use the exact same code and Groovy version, but downgrade to Spring-Boot 2.7.7 and springdoc-openapi-ui 1.6.14. So it seems this issue is new with SpringDoc 2.X.

@JosephWitthuhnTR
Copy link
Author

Update: I've noticed that this also applies to ZoneId where we are passing around timezones.

I've found this workaround, but it is not clear to me why I should have to do this (or what else I might be breaking by doing so):

SpringDocUtils.getConfig().removeRequestWrapperToIgnore(Map.class);
SpringDocUtils.getConfig().removeRequestWrapperToIgnore(ZoneId.class);

@bnasslahsen
Copy link
Collaborator

@JosephWitthuhnTR,

It will be fixed in the next release.
This is another workaround:

springdoc.enable-groovy=false

@bnasslahsen bnasslahsen added the bug Something isn't working label Feb 5, 2023
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

No branches or pull requests

2 participants