swagger-maven-plugin не генерирует оба типа содержимого в файле openapi - PullRequest
0 голосов
/ 26 мая 2020

У меня есть приложение jaxrs с двумя путями к ресурсам, каждый из которых создает свой тип содержимого. Я пытаюсь создать файл openapi (для использования с swagger-ui), но создается только один тип содержимого.

См. Этот пример:

@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();
  }
}

Если я запустил 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>
.
.

Он производит

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

Моя проблема в том, что он генерирует только текст / html. Когда я объединяю два @Produces в один ресурс:

@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();
  }
}

, получается

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

Я что-то делаю не так? Или это ошибка?

...