ModelValidationException in JAVA Jersey

35 Views Asked by At

OpenAPI.yml

paths:
  /getname:
    get:
      tags:
        - test
      summary: get name
      operationId: getName
      responses:
        '200':
          description: ok
          content:
            application/json:
            schema:
              type: string

  /getage:
    get:
      tags:
        - test
      summary: Age
      operationId: getAge
      responses:
        '200':
          description: A User object
          content:
            application/json:
              schema:
        type:string

Interface NameApi

@Path("/getname")
public interface NameApi{
  
  @GET
  @Produces({"application/json"})
  Response getName();
}

Interface AgeAPI

@Path("/getage")
public interface AgeApi{
  static {

  @GET
  @Produces({"application/json"})
  Response getAge();
}

Both of them are automatically generated upon running the following command, so I can't modify them:

mvn clean generate-resources -Popenapigen

Main class is implementing above interface

public class Test implements AgeApi, NameApi {

    @Override
    public Response getName() { 
            return Response.ok().entity("test").build();
    }

    @Override
    public Response getAge() {
        return Response.ok().entity("14").build();
    }
}

I want to keep two different paths here, like getage & getname, but getting following error:

[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods Test.getAge() and public Test.getName at matching regular expression /getage. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail

0

There are 0 best solutions below