swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Subresource scanning based on @ApiOperation

Open shivangshah opened this issue 11 years ago • 22 comments

Per discussions on #925 with @fehguy , creating new issue.

Through a subresource, if a path is not given at root level (because it gets subresource'd from inheritance), the api will not show up in swagger. For example:

@Path("/api/v1")
@Api(tags = "V1 APIs - All", value = "/api/v1", description = "MDM Services")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BaseResource {

@Path("/somePath")
    @ApiOperation(value = "Returns Some service", response = SomeResource.class)
    public SomeResource getSomeService() {
        return this.someService;
    }
}
@Api(tags = "V1 Tenant APIs", hidden = true, value = "/tenants", description = "MDM Base Service")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class SomeResource {
@GET
    @Path("")
    @CacheControl(maxAge = 3, maxAgeUnit = TimeUnit.SECONDS)
    @ApiOperation(value = "get tenants", notes = "Sort Order Values can be 'ASC' or 'DESC'", response = String.class)
    public Response getStuff(@ApiParam(value = DATASOURCE_HEADER, required = true)
{
}

had to provide @Path("") for the swagger scanner to pickup that api. Otherwise it did not recognize the inherited path

shivangshah avatar Mar 29 '15 16:03 shivangshah

I feel that the first @ApiOperation :

@Path("/somePath")
@ApiOperation(value = "Returns Some service", response = SomeResource.class)
public SomeResource getSomeService() {
   return this.someService;
}

Maybe could be removed as you defined the @ApiOperation on the GET of the scanned @Path("/somePath") resource, which define:

@GET
@Path("")
@CacheControl(maxAge = 3, maxAgeUnit = TimeUnit.SECONDS)
@ApiOperation(value = "get tenants", notes = "Sort Order Values can be 'ASC' or 'DESC'", response = String.class)
public Response getStuff(@ApiParam(value = DATASOURCE_HEADER, required = true) { ... }

So... In this case, what documentation would shown? "Returns Some service", "get tenants" or both... I think that its the same path with two documentation definitions

jmarreroc avatar Mar 30 '15 07:03 jmarreroc

@jmarreroc Not sure I understand. The first @Path("/somePath") is basically returning a subresource while the second @Path("") is just for swagger to scan and pick up that specific subresource method (yes, with the same path). The difference is we don't provide an HTTP method when a subresource is returned. JAX-RS won't understand a @GET on a subresource (although I haven't tried it first hand but that's what i'd expect)

The "returns some service" api operation actually doesn't do anything from what I can see. It's just a way to let swagger know that this is a subresource and you need to go inside this subresource class to scan the remaining methods (and corresponding paths). So you will only see the documentation for "getTenants" (as expected)

shivangshah avatar Mar 30 '15 13:03 shivangshah

Ok, so finally swagger shown only the documentation defined over the HTTP method. Thx!

jmarreroc avatar Mar 30 '15 14:03 jmarreroc

That's what I found so far .. yes ! And no problem.

shivangshah avatar Mar 30 '15 14:03 shivangshah

this is fixed in develop_2.0

fehguy avatar Mar 31 '15 00:03 fehguy

@fehguy Thank you ! Which snapshot/release I can test this with ?

shivangshah avatar Mar 31 '15 00:03 shivangshah

If you wait a few, there will be a formal release. I'm verifying for 1.5.0-M2 right now.

fehguy avatar Mar 31 '15 00:03 fehguy

sounds good .. let me know what release .. currently I am on 1.5.4-Snapshot

shivangshah avatar Mar 31 '15 00:03 shivangshah

@shivangshah - it was indeed released under 1.5.0-M2.

webron avatar Mar 31 '15 08:03 webron

@webron @fehguy I just tried with 1.5.0-M2. The bug is still there. I had to give @Path("") for the scanner to pick it up the subresource method even though there is an @ApiOperation

shivangshah avatar Mar 31 '15 14:03 shivangshah

@shivangshah - this should be fixed in develop_2.0 now. Can you try?

webron avatar Apr 29 '15 09:04 webron

@webron do you know which snapshot i can test it with instead of branch? (I might not be able to clone the branch and test :( )

shivangshah avatar Apr 29 '15 21:04 shivangshah

@shivangshah I don't think we have a published snapshot for it yet, so you'd have to build it on your own.

webron avatar Apr 30 '15 09:04 webron

@webron I see ok .. when I get a chance, I will build and try it out ..

shivangshah avatar Apr 30 '15 14:04 shivangshah

Sorry for the late response @webron @fehguy . I just got around testing this on 1.5.0 release and it still does not work .. :(

shivangshah avatar Jun 10 '15 16:06 shivangshah

@shivangshah - I'm afraid that at this point you'd have to provide us with a sample project that mimics the problem for us to further investigate.

webron avatar Jun 10 '15 16:06 webron

@webron Let me set one up and send you guys the link soon ..

shivangshah avatar Jun 10 '15 16:06 shivangshah

Is there still the lack of the example project? It still doen't work.

MichaelVoegeli avatar Jun 20 '16 09:06 MichaelVoegeli

Running into the same problem. Only the most trivial kind of JAX-RS application seems to be supported.

defnull avatar Jun 20 '16 17:06 defnull

Which version are you using?

webron avatar Jun 20 '16 22:06 webron