1

それぞれが異なるコンテンツ タイプを生成する 2 つのリソース パスを持つ jaxrs アプリケーションがあります。(swagger-ui で使用する) openapi ファイルを生成しようとしていますが、生成されるコンテンツ タイプは 1 つだけです。

次の例を参照してください。

@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" : { }
            }
          }
        }
      }
    }

私の問題は、text/html しか生成しないことです。@Produces2 つを 1 つのリソースに組み合わせると、次のようになります。

@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" : { }
            }
          }
        }
      }
    }

私は何か間違ったことをしていますか?それともこれはバグですか?

4

0 に答える 0