thehpi
thehpi

Reputation: 5833

swagger-maven-plugin doesn't generate both content-types in openapi file

I have a jaxrs application with two resource paths where each produce a different content-type. I'm trying to generate an openapi file (for use with swagger-ui) but only one content-type is genrated.

See this example:

@Path("test")
public class TestResource {

  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public Response getListJ(){
    return Response.ok().entity("\"foo\" : \"bar\"").build();
  }

  @GET
  @Produces({MediaType.TEXT_HTML})
  public Response getListH(){
      return Response.ok().entity("<html></html>").build();
  }
}

If I run the swagger-maven-plugin

.
.
    <dependencies>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-jaxrs2</artifactId>
            <version>2.1.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <configuration>
                    <outputFileName>test-api</outputFileName>
                    <outputPath>${project.build.directory}</outputPath>
                    <outputFormat>JSONANDYAML</outputFormat>
                    <resourcePackages>
                        <package>my.test.package</package>
                    </resourcePackages>
                    <prettyPrint>true</prettyPrint>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>resolve</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
.
.

It produces

    "/test" : {
      "get" : {
        "operationId" : "getListH_1",
        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "text/html" : { }
            }
          }
        }
      }
    }

My problem is that it only generates text/html. When I combine the two @Produces into one resource:

@Path("test")
public class TestResource {

  @GET
  @Produces({MediaType.APPLICATION_JSON,MediaType.TEXT_HTML})
  public Response getList(){
    entity = getEntity(); // implementation not shown
    return Response.ok().entity(entity).build();
  }
}

then it produces

    "/test" : {
      "get" : {
        "operationId" : "getList",
        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "application/json" : { },
              "text/html" : { }
            }
          }
        }
      }
    }

Am I doing something wrong? Or is this a bug?

Upvotes: 1

Views: 499

Answers (0)

Related Questions