【Quarkus】OpenAPI Generator(jaxrs-spec)で生成したソースが、エンドポイントがうまく指定できずREST Assuredでテストできない

TL;DR

  • 生成対象となるOpenAPIでpathを1種類しか持たないとき、
    • クラス単位に設定される@Pathにフルパスが設定される
    • メソッド単位にパスは設定されない
  • Quarkusが提供するテスト用アノテーション@TestHTTPResourceは、クラス単位に設定された@Pathまでを注入する
  • したがって、クラス単位に設定したPathにパスパラメータが含まれている場合、@TestHTTPResourceを利用したテストができない
  • @TestHTTPResourceを外してフルパスでテストするしかなさそう

環境

動作環境

  • Ubuntu 20.04(WSL2)
  • openapitools/openapi-generator-cli(Dockerイメージ)

設定値

library: quarkus
additionalProperties:
  dateLibrary: java8-localdatetime
  hideGenerationTimestamp: true
  openApiNullable: false
  useBeanValidation: true
  useRuntimeException: true
  microprofileRestClientVersion: "3.0"
  serializationLibrary: "jackson"
  useJakartaEe: true
  generateBuilders: true
  interfaceOnly: true
  useSwaggerAnnotations: false
  sourceFolder: "src/main/java"

実行コマンドの例

GENERATOR=jaxrs-spec && docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i /local/input/petstore_2path.yaml -g ${GENERATOR} -o /local/out2/${GENERATOR} -c /local/input/config_server.yaml

試したこと(エンドポイントの個数によって生成のされ方が異なる)

エンドポイントが1種類のとき

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets/{id}:
    post:
      summary: "Add a new pet to the store"
      description: "desc"
      operationId: "methodpost"
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
          description: ユーザID
      responses:
        200:
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetsResponse"
                type: object
                properties:
                  user:
                    type: object
                    properties:
                      age:
                        type: string
                      sex:
                        type: string
    put:
      summary: "Add a new pet to the store"
      description: "desc"
      operationId: "methodput"
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
          description: ユーザID
      responses:
        200:
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetsResponse"
                type: object
components:
  schemas:
    Petfoo:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Petshoge:
      type: array
      items:
        $ref: "#/components/schemas/Petfoo"

    PetsResponse:
      properties:
        id:
          type: integer
          format: int64
          example: 3
        name:
          type: string
          example: "wan"
        tag:
          type: string
          example: "inu"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
package org.openapitools.api;

import org.openapitools.model.PetsResponse;

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;




import java.io.InputStream;
import java.util.Map;
import java.util.List;
import jakarta.validation.constraints.*;
import jakarta.validation.Valid;


@Path("/pets/{id}")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.5.0-SNAPSHOT")
public interface PetsApi {

    @POST
    @Produces({ "application/json" })
    PetsResponse methodpost(@PathParam("id") Integer id);

    @PUT
    @Produces({ "application/json" })
    PetsResponse methodput(@PathParam("id") Integer id);
}

エンドポイントが2種類のとき

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets/{id}:
    post:
      summary: "Add a new pet to the store"
      description: "desc"
      operationId: "methodpost"
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
          description: ユーザID
      responses:
        200:
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetsResponse"
                type: object
                properties:
                  user:
                    type: object
                    properties:
                      age:
                        type: string
                      sex:
                        type: string
    put:
      summary: "Add a new pet to the store"
      description: "desc"
      operationId: "methodput"
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
          description: ユーザID
      responses:
        200:
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetsResponse"
                type: object
  /pets/name/{name}:
    post:
      summary: "Add a new pet to the store"
      description: "desc"
      operationId: "anothermethodpost"
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: integer
          description: 顧客名
      responses:
        200:
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetsResponse"
                type: object
                properties:
                  user:
                    type: object
                    properties:
                      age:
                        type: string
                      sex:
                        type: string
components:
  schemas:
    Petfoo:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Petshoge:
      type: array
      items:
        $ref: "#/components/schemas/Petfoo"

    PetsResponse:
      properties:
        id:
          type: integer
          format: int64
          example: 3
        name:
          type: string
          example: "wan"
        tag:
          type: string
          example: "inu"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
package org.openapitools.api;

import org.openapitools.model.PetsResponse;

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;




import java.io.InputStream;
import java.util.Map;
import java.util.List;
import jakarta.validation.constraints.*;
import jakarta.validation.Valid;


@Path("/pets")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", comments = "Generator version: 7.5.0-SNAPSHOT")
public interface PetsApi {

    @POST
    @Path("/name/{name}")
    @Produces({ "application/json" })
    PetsResponse anothermethodpost(@PathParam("name") Integer name);

    @POST
    @Path("/{id}")
    @Produces({ "application/json" })
    PetsResponse methodpost(@PathParam("id") Integer id);

    @PUT
    @Path("/{id}")
    @Produces({ "application/json" })
    PetsResponse methodput(@PathParam("id") Integer id);
}

参考