swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.39k stars 2.19k forks source link

Rest Resources configured with JAX RS @Path where the value is composed of more than one path segments is not supported #138

Closed johnnymongiat closed 11 years ago

johnnymongiat commented 11 years ago

The source issue is described here: https://groups.google.com/forum/#!topic/swagger-swaggersocket/b0nzZFoY6Uc

As a summary, the issue involves getting a HTTP 404 response when trying to load the expected API documentation (as generated by Swagger) for a rest resource that is annotated with a JAX RS @Path where the value is composed of more than one "path segments", for example,

@Path("/v1/bars") @Api(value = "/v1/bars", description = "Operations related to Bar object(s)") @Produces({ MediaType.APPLICATION_JSON }) public class BarsResource {

@GET
@Path("/{id}")
@ApiOperation(value = "Find a Bar by ID", notes = "Returns the Bar identified by the provided ID", responseClass = "com.xyz.model.Bar")
@ApiErrors(value = { @ApiError(code = 400, reason = "Invalid ID"), @ApiError(code = 404, reason = "Bar not found") })
public Response getBarById(
        @ApiParam(value = "ID of the Bar that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("id") String id) {
    ...
}

}

If the "/v1" portion is removed from the @Path value, thus becoming @Path("/bars") - everything else stays the same, then the documentation is correctly returned (HTTP 200).

Version 1.2.0 (swagger-core_2.9.1 + swagger-jaxr_2.9.1).

dotheygandalf commented 11 years ago

I came across this same issue. It is sort of documented here. What you need is to create a separate resource listing endpoint that will expose the v1/whatever path.

https://github.com/wordnik/swagger-core/tree/master/samples/scala-alt-resource-listing

The result works for us but it does seem a bit flaky. The resources exposed on the v1 path for us don't always show up. We solved this by using a static root resource json which was needed anyways to keep track of separate versions.

chadhahn commented 11 years ago

Pretty sure this commit to include the nested routes via regex fixes this. Try 1.2.1-SNAPSHOT version vs 1.2.0 and see if it works. https://github.com/wordnik/swagger-core/commit/30db009431f621fa0fc6caf0c73a052ce7ef6c90

johnnymongiat commented 11 years ago

Thanks for the suggestions! However, I feel that the "multi-segmented path" should be supported out of the box...

Where can I download the proposed 1.2.1-SNAPSHOT from (I don't see it in maven central)? Is it hosted on another repository?

fehguy commented 11 years ago

hi folks, sorry for the delay--they are in sonatype snapshots, here:

https://oss.sonatype.org/content/repositories/snapshots/com/wordnik/swagger-core_2.9.1/

Just add that repo to your repositories and you'll be golden.

johnnymongiat commented 11 years ago

Thanks for the repository info. I can confirm that the 1.2.1-SNAPSHOT does indeed address the original issue!! I really appreciate the help, and the quick responses - well done...

ericchile commented 11 years ago

Is there are release schedule for this artifact? I would like to use this version but don't want to hold up my project from releasing because of this SNAPSHOT dependency.

fehguy commented 11 years ago

Pushing out a release today, I'll close this issue when it's up.

fehguy commented 11 years ago

Hi, released:

https://oss.sonatype.org/content/repositories/releases/com/wordnik/swagger-core_2.9.1/