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

questions about Support for Subresource Locators

Open jmarreroc opened this issue 11 years ago • 6 comments

Hello!

I'm trying to adjust my resources hierarchy (who describes a tree morphology) as related on Subresource locators support for jax-rs 1.1 (as @mdekmetzian mentioned is this issue few years ago...) : http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-310003.4.1

So, i have a Resource:


@Path("resource")
@Produces("application/json")
@Api(value="resource")
public class Resource {

    @GET
    @ApiOperation( ... )
    public Resource get() {
        return this;
    }

    @Path("/{subresource}")
    public SubResource get(@PathParam("subresource") String subresource) {      
        return new SubResource(subresource);        
    }
}

And a set of subresources describing a tree form (as showns this simple example), with no '@Path' class annotation defined as mentioned in http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-310003.4.1 subresource specification (specifically in the WidgetResource definition):

@Produces("application/json")
//@Api <-- tried but doesn't work
public class SubResource {

    @GET
    @ApiOperation( ... ) //???
    public SubResource get() {
        return this;
    }

    @Path("/items")
    public OtherResource items(...) {       
        return new OtherResource(...);      
    }
}

I read all posts and see the examples attached but... finally i can say that i didn't understand how to document my resource hierarchy with swagger, (or if it's now supported) and nobody talks at this respect. All I see in the example provided (https://github.com/mdekmetzian/subresource_example) is that both resources '/pet' and '/owner' have their own @Path definition, so both are considered as resorurces who hang from root '/' and that isn't my scenario. So if I annotate all my resource classes whith @Path, i loose the resource exploration support dinamically provided by Jax-rs. What i'm doing wrong?! I just type directly in the browser the URIS and can navigate perfectly all resources hierarchy but cannot provide correctly the documentation to swagger.

Also tried to include the @ApiOperation as mentioned fehguy over the subresource construction method but finally I get in the UI : "SwaggerOperation " + nickname + " is missing method". It has sense because it's not annotated with @GET, wich is annoted in the subresource class...


@Path("resource")
@Produces("application/json")
@Api(value="resource")
public class Resource {

    @GET
    @ApiOperation( ... )
    public Resource get() {
        return this;
    }

    @ApiOperation( ... )
    @Path("/{subresource}")
    public SubResource get(@PathParam("subresource") String subresource) {      
        return new SubResource(subresource);        
    }
}
@Produces("application/json")
@Api(value="subresource") // tried but doesn't work
public class SubResource {

    @GET
    @ApiOperation( ... ) //???
    public SubResource get() {
        return this;
    }

    @Path("/items")
    public OtherResource items(...) {       
        return new OtherResource(...);      
    }
}

So, what I'm doing wrong? :( I'm using Swagger 2.11 : (bundle version 1.3.10)

Thank you for your time!

jmarreroc avatar Mar 20 '15 13:03 jmarreroc

Hi, try 1.5.3-M1-SNAPSHOT. We recently updated the subresource support there. Also a sample should help you as well:

https://github.com/swagger-api/swagger-core/tree/develop_2.0/samples/java-jaxrs-subresource

1.5.0-M2 should be released this weekend. I'd love to get your feedback on this beforehand!

fehguy avatar Mar 20 '15 13:03 fehguy

Oh! Sure I will do. Let me try it, but i need to configure it properly because i'm using an OSGi-Swagger connector and maybe in the locally building of the p2 repository some version could be deprecated as you suggest. Thanks!

jmarreroc avatar Mar 20 '15 14:03 jmarreroc

Hi, looks like we need to send a PR to that repository.

fehguy avatar Mar 23 '15 04:03 fehguy

Hi again,

I'm facing some issues related with an OSGi environment + Swagger. So I'm using an existing swagger OSGi connector who uses a maven p2 plugin who delegates in tycho plugin for finally generate the OSGi bundles. There is a problem when the maven artifact version does'nt adjust completly with the bundles version convention (tycho report). In this case... I'm using the 1.5.2-M1 core swagger version, and getting: invalid version "1.5.2-M1": non-numeric "2-M1" I'm still researching all the tycho plugin contents for any way to configure the version mapping during the bundle construction, but: is there any other previous version wich implements support for Subresource Locators?

Thank you very much!

jmarreroc avatar Mar 23 '15 15:03 jmarreroc

@jmarreroc I did some testing with the latest 1.5.4 snapshot. Here are my results: https://github.com/swagger-api/swagger-core/issues/925 Maybe we can close one of these issues as duplicate? I think we both are having almost the same issue.

shivangshah avatar Mar 28 '15 21:03 shivangshah

Alright! follow discusion on #942

jmarreroc avatar Mar 30 '15 07:03 jmarreroc