Forum Discussion

kpilandjr's avatar
kpilandjr
New Contributor
21 days ago

Bootstrapped servlet returns empty JSON as of 2.2.24

Sorry if I've missed something in the docs, but our apps use a bootstrapped HTTP servlet to configure OpenAPI using JAX-RS and when we upgraded to Swagger 2.2.24 the servlet started producing an empty OpenAPI JSON payload.

Original code for our servlet is here (nothing proprietary about this):

// @formatter:off
@OpenAPIDefinition(
         info = info(title = "NextGen Web Services", description = "Web services for the NextGen application."),
         tags = {@Tag(name = OpenApiBootstrap.TAG_API, description = "Services to communicate with NextGen")},
         servers = @Server(url = "/nextgen"))
// @formatter:on
@WebServlet(name = "OpenAPI", description = "OpenAPI Spec Servlet", loadOnStartup = 2)
public final class OpenApiBootstrap extends HttpServlet {
   private static final long serialVersionUID = 1L;

   /** Tag for API web services. */
   public static final String TAG_API = "API";

   @Override
   public void init(final ServletConfig servletConfig) throws ServletException {
      try {
         new JaxrsOpenApiContextBuilder<>().servletConfig(servletConfig)
                  .openApiConfiguration(
                           new SwaggerConfiguration().resourcePackages(Collections.singleton("com.pjm.nextgen.rest")))
                  .buildContext(true);
      } catch (final OpenApiConfigurationException e) {
         throw new ServletException(e);
      }
   }
}

After upgrading to Swagger 2.2.24, the JSON file returned from the servlet is essentially empty:

{"openapi":"3.0.1"}

I noticed that the examples do not show using the OpenAPIDefinition annotation, so I tried translating that to just setting up the configurations in the Java code like this:

@WebServlet(name = "OpenAPI", description = "OpenAPI Spec Servlet", loadOnStartup = 2)
public final class OpenApiBootstrap extends HttpServlet {
   private static final long serialVersionUID = 1L;

   /** Tag for API web services. */
   public static final String TAG_API = "API";

   @Override
   public void init(final ServletConfig servletConfig) throws ServletException {
      try {
         final Info info = new Info().title("NextGen Web Services")
                  .description("Web services for the NextGen application.");
         final OpenAPI oas = new OpenAPI().info(info)
                  .tags(List.of(new Tag().name(TAG_API).description("Services to communicate with NextGen")))
                  .servers(List.of(new Server().url("/nextgen")));
         oas.info(info);
         final SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas).prettyPrint(true)
                  .resourcePackages(Stream.of("com.pjm.nextgen.rest").collect(Collectors.toSet()));

         new JaxrsOpenApiContextBuilder<>().servletConfig(servletConfig).openApiConfiguration(oasConfig)
                  .buildContext(true);
      } catch (final OpenApiConfigurationException e) {
         throw new ServletException(e);
      }
   }
}

This advances things a bit farther but the JSON payload still contains no definitions for the services. So I'm guessing that JAX-RS is somehow not finding the services anymore? 

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "NextGen Web Services",
    "description" : "Web services for the NextGen application."
  },
  "servers" : [ {
    "url" : "/nextgen"
  } ],
  "tags" : [ {
    "name" : "API",
    "description" : "Services to communicate with NextGen"
  } ]
}

Any ideas on what we might be missing here?

No RepliesBe the first to reply