Forum Discussion

Kassarn's avatar
Kassarn
Frequent Visitor
5 years ago

How to document resource at base path of application

Hello , i have java project using resteasy services and basic swagger config via application class. When i access openapi.json file at my applicaiton url  its seem swagger skip to document the method which is  on root path "/". I have this problem when the base path is "/".  My generated json file is bellow with the dependancy i use and sample code:

I ll be glad if somoene help!

@ApplicationPath("/")
public class Application extends javax.ws.rs.core.Application {

	@Override
	public Set<Class<?>> getClasses() {
		return Stream.of(PersonService.class, OpenApiResource.class, AcceptHeaderOpenApiResource.class)
				.collect(Collectors.toSet());
	}

}
@Path("/")
@OpenAPIDefinition( tags = { @Tag (name = "persons") } ,info = @Info (title = "Person API",version = "1.0.0") ,servers = @Server(url = "/"))
public class PersonService {
	@GET
	@Path("/person")
	@Produces(MediaType.APPLICATION_JSON)
	public Person getPerson() {
		return new Person("1","person");
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Person getPersonById(@PathParam("petId") String id) {	
		return new Person("2","person2");
	}
}
{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "Person API",
    "version" : "1.0.0"
  },
  "tags" : [ {
    "name" : "persons"
  } ],
  "paths" : {
    "/person" : {
      "get" : {
        "operationId" : "getPerson",
        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/Person"
                }
              }
            }
          }
        }
      }
    }
  },
  "components" : {
    "schemas" : {
      "Person" : {
        "type" : "object",
        "properties" : {
          "id" : {
            "type" : "string"
          },
          "name" : {
            "type" : "string"
          }
        }
      }
    }
  }
}
<dependency>
    <groupId>io.swagger.core.v3</groupId>
    <artifactId>swagger-jaxrs2</artifactId>
    <version>2.0.8</version>
</dependency>
No RepliesBe the first to reply