springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

missing schema when enumAsRef = true for GroupedOpenApi

Open zdary opened this issue 2 months ago • 3 comments

We use GroupedOpenApi definitions to provide integration partners only relevant openapi specification. When we have an enum with @Schema(..., enumAsRef = true) and it's registred with @StringToClassMapItem only then the the generated code correctly creates a reference but the referenced schema is not present in the openapi.

To reproduce:

  • The type is only present via dependentSchemas (here via @StringToClassMapItem), and
  • The enum is marked enumAsRef = true, and
  • The OpenAPI instance is the per-group one created by GroupedOpenApi, not the global doc.

Workarounds:

  • remove enumAsRef from the enum class
  • add the enum as a parameter to a method.

zdary avatar Nov 14 '25 06:11 zdary

Have you tried using the io.swagger.v3.core.jackson.ModelResolver.enumsAsRef = true; approach? (placing that definition as a static initialization in your application). Or is it the case that you do not want all enums in the application to be defined as references?

Mattias-Sehlstedt avatar Nov 14 '25 17:11 Mattias-Sehlstedt

@Mattias-Sehlstedt I have just tried it with

static {
  io.swagger.v3.core.jackson.ModelResolver.enumsAsRef = true;
}

it makes no difference. The schema is not present if the only reference to that class is through @StringToClassMapItem.

the code around @StringToClassMapItem should make sure the class was registered for schema when creating that reference.

zdary avatar Nov 15 '25 03:11 zdary

Thanks for checking. Could you provide a Minimal, Reproducible Example - with HelloController that illustrates the problem? It would enable someone to more easily understand the exact problem and debug it (and also verify whether a solution actually solves your issue).

For your case this would basically be that you have a controller with two endpoints, and that you then have two groups defined that split these into two specifications. And then somewhere in there there is an enum that gets lost. This test controller should be somewhat close to what it might look like.

Mattias-Sehlstedt avatar Nov 15 '25 10:11 Mattias-Sehlstedt