From 79856abae9a512ee05c678835bc308f6e0de26ba Mon Sep 17 00:00:00 2001 From: Thomas Townsend Date: Sat, 30 Jun 2018 09:23:04 +0100 Subject: [PATCH] Fix subResourcePath when using tags in java-jersey (#215) --- .../codegen/languages/JavaJerseyServerCodegen.java | 13 +++++++++++++ .../java/org/openapitools/api/AnotherFakeApi.java | 2 +- .../src/gen/java/org/openapitools/api/FakeApi.java | 14 +++++++------- .../src/gen/java/org/openapitools/api/PetApi.java | 12 ++++++------ .../gen/java/org/openapitools/api/StoreApi.java | 8 ++++---- .../src/gen/java/org/openapitools/api/UserApi.java | 14 +++++++------- .../java/org/openapitools/api/AnotherFakeApi.java | 2 +- .../src/gen/java/org/openapitools/api/FakeApi.java | 14 +++++++------- .../src/gen/java/org/openapitools/api/PetApi.java | 12 ++++++------ .../gen/java/org/openapitools/api/StoreApi.java | 8 ++++---- .../src/gen/java/org/openapitools/api/UserApi.java | 14 +++++++------- 11 files changed, 63 insertions(+), 50 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJerseyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJerseyServerCodegen.java index d31a56b1f4..d6bf317b97 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJerseyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJerseyServerCodegen.java @@ -159,6 +159,19 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen { @Override public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { if (useTags) { + String basePath = resourcePath; + if (basePath.startsWith("/")) { + basePath = basePath.substring(1); + } + int pos = basePath.indexOf("/"); + if (pos > 0) { + basePath = basePath.substring(0, pos); + } + + if (co.path.startsWith("/" + basePath)) { + co.path = co.path.substring(("/" + basePath).length()); + } + co.subresourceOperation = !co.path.isEmpty(); super.addOperationToGroup(tag, resourcePath, operation, co, operations); } else { String basePath = resourcePath; diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java index 97fccd1305..58b1843fd4 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java @@ -35,7 +35,7 @@ public class AnotherFakeApi { private final AnotherFakeApiService delegate = AnotherFakeApiServiceFactory.getAnotherFakeApi(); @PATCH - + @Path("/dummy") @Consumes({ "application/json" }) @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "To test special tags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?" }) diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/FakeApi.java index c6ffdf9c1e..bde117950d 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/FakeApi.java @@ -41,7 +41,7 @@ public class FakeApi { private final FakeApiService delegate = FakeApiServiceFactory.getFakeApi(); @POST - + @Path("/outer/boolean") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", }) @@ -54,7 +54,7 @@ public class FakeApi { return delegate.fakeOuterBooleanSerialize(body,securityContext); } @POST - + @Path("/outer/composite") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of object with outer number type", response = OuterComposite.class, tags={ "fake", }) @@ -67,7 +67,7 @@ public class FakeApi { return delegate.fakeOuterCompositeSerialize(outerComposite,securityContext); } @POST - + @Path("/outer/number") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer number types", response = BigDecimal.class, tags={ "fake", }) @@ -80,7 +80,7 @@ public class FakeApi { return delegate.fakeOuterNumberSerialize(body,securityContext); } @POST - + @Path("/outer/string") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer string types", response = String.class, tags={ "fake", }) @@ -93,7 +93,7 @@ public class FakeApi { return delegate.fakeOuterStringSerialize(body,securityContext); } @PUT - + @Path("/body-with-query-params") @Consumes({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "", notes = "", response = Void.class, tags={ "fake", }) @@ -171,7 +171,7 @@ public class FakeApi { return delegate.testEnumParameters(enumHeaderStringArray,enumHeaderString,enumQueryStringArray,enumQueryString,enumQueryInteger,enumQueryDouble,enumFormStringArray,enumFormString,securityContext); } @POST - + @Path("/inline-additionalProperties") @Consumes({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "test inline additionalProperties", notes = "", response = Void.class, tags={ "fake", }) @@ -184,7 +184,7 @@ public class FakeApi { return delegate.testInlineAdditionalProperties(requestBody,securityContext); } @GET - + @Path("/jsonFormData") @Consumes({ "application/x-www-form-urlencoded" }) @io.swagger.annotations.ApiOperation(value = "test json serialization of form data", notes = "", response = Void.class, tags={ "fake" }) diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/PetApi.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/PetApi.java index 45e52ad466..b827352469 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/PetApi.java @@ -55,7 +55,7 @@ public class PetApi { return delegate.addPet(pet,securityContext); } @DELETE - + @Path("/{petId}") @io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = { @@ -74,7 +74,7 @@ public class PetApi { return delegate.deletePet(petId,apiKey,securityContext); } @GET - + @Path("/findByStatus") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = { @@ -93,7 +93,7 @@ public class PetApi { return delegate.findPetsByStatus(status,securityContext); } @GET - + @Path("/findByTags") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = { @@ -112,7 +112,7 @@ public class PetApi { return delegate.findPetsByTags(tags,securityContext); } @GET - + @Path("/{petId}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { @@ -149,7 +149,7 @@ public class PetApi { return delegate.updatePet(pet,securityContext); } @POST - + @Path("/{petId}") @Consumes({ "application/x-www-form-urlencoded" }) @io.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = { @@ -169,7 +169,7 @@ public class PetApi { return delegate.updatePetWithForm(petId,name,status,securityContext); } @POST - + @Path("/{petId}/uploadImage") @Consumes({ "multipart/form-data" }) @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = { diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/StoreApi.java index 5f7c9a99ca..2c9da75e76 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/StoreApi.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/StoreApi.java @@ -36,7 +36,7 @@ public class StoreApi { private final StoreApiService delegate = StoreApiServiceFactory.getStoreApi(); @DELETE - + @Path("/order/{order_id}") @io.swagger.annotations.ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class, tags={ "store", }) @@ -50,7 +50,7 @@ public class StoreApi { return delegate.deleteOrder(orderId,securityContext); } @GET - + @Path("/inventory") @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = { @@ -64,7 +64,7 @@ public class StoreApi { return delegate.getInventory(securityContext); } @GET - + @Path("/order/{order_id}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", }) @@ -79,7 +79,7 @@ public class StoreApi { return delegate.getOrderById(orderId,securityContext); } @POST - + @Path("/order") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store" }) diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/UserApi.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/UserApi.java index 3d8b0ae299..3e42609391 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/UserApi.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/api/UserApi.java @@ -49,7 +49,7 @@ public class UserApi { return delegate.createUser(user,securityContext); } @POST - + @Path("/createWithArray") @io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @@ -62,7 +62,7 @@ public class UserApi { return delegate.createUsersWithArrayInput(user,securityContext); } @POST - + @Path("/createWithList") @io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @@ -75,7 +75,7 @@ public class UserApi { return delegate.createUsersWithListInput(user,securityContext); } @DELETE - + @Path("/{username}") @io.swagger.annotations.ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", }) @@ -89,7 +89,7 @@ public class UserApi { return delegate.deleteUser(username,securityContext); } @GET - + @Path("/{username}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ "user", }) @@ -104,7 +104,7 @@ public class UserApi { return delegate.getUserByName(username,securityContext); } @GET - + @Path("/login") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", }) @@ -119,7 +119,7 @@ public class UserApi { return delegate.loginUser(username,password,securityContext); } @GET - + @Path("/logout") @io.swagger.annotations.ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class, tags={ "user", }) @@ -131,7 +131,7 @@ public class UserApi { return delegate.logoutUser(securityContext); } @PUT - + @Path("/{username}") @io.swagger.annotations.ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user" }) diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java index a695ffeb47..75f9f8f6e1 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/AnotherFakeApi.java @@ -55,7 +55,7 @@ public class AnotherFakeApi { } @PATCH - + @Path("/dummy") @Consumes({ "application/json" }) @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "To test special tags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", }) diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/FakeApi.java index 6203c1341d..91439b3e8a 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/FakeApi.java @@ -61,7 +61,7 @@ public class FakeApi { } @POST - + @Path("/outer/boolean") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", }) @@ -73,7 +73,7 @@ public class FakeApi { return delegate.fakeOuterBooleanSerialize(body,securityContext); } @POST - + @Path("/outer/composite") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of object with outer number type", response = OuterComposite.class, tags={ "fake", }) @@ -85,7 +85,7 @@ public class FakeApi { return delegate.fakeOuterCompositeSerialize(outerComposite,securityContext); } @POST - + @Path("/outer/number") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer number types", response = BigDecimal.class, tags={ "fake", }) @@ -97,7 +97,7 @@ public class FakeApi { return delegate.fakeOuterNumberSerialize(body,securityContext); } @POST - + @Path("/outer/string") @Produces({ "*/*" }) @io.swagger.annotations.ApiOperation(value = "", notes = "Test serialization of outer string types", response = String.class, tags={ "fake", }) @@ -109,7 +109,7 @@ public class FakeApi { return delegate.fakeOuterStringSerialize(body,securityContext); } @PUT - + @Path("/body-with-query-params") @Consumes({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "", notes = "", response = Void.class, tags={ "fake", }) @@ -186,7 +186,7 @@ public class FakeApi { return delegate.testEnumParameters(enumHeaderStringArray,enumHeaderString,enumQueryStringArray,enumQueryString,enumQueryInteger,enumQueryDouble,enumFormStringArray,enumFormString,securityContext); } @POST - + @Path("/inline-additionalProperties") @Consumes({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "test inline additionalProperties", notes = "", response = Void.class, tags={ "fake", }) @@ -198,7 +198,7 @@ public class FakeApi { return delegate.testInlineAdditionalProperties(requestBody,securityContext); } @GET - + @Path("/jsonFormData") @Consumes({ "application/x-www-form-urlencoded" }) @io.swagger.annotations.ApiOperation(value = "test json serialization of form data", notes = "", response = Void.class, tags={ "fake", }) diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/PetApi.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/PetApi.java index 03aafa4190..d982292e30 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/PetApi.java @@ -74,7 +74,7 @@ public class PetApi { return delegate.addPet(pet,securityContext); } @DELETE - + @Path("/{petId}") @io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = { @@ -92,7 +92,7 @@ public class PetApi { return delegate.deletePet(petId,apiKey,securityContext); } @GET - + @Path("/findByStatus") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = { @@ -111,7 +111,7 @@ public class PetApi { return delegate.findPetsByStatus(status,securityContext); } @GET - + @Path("/findByTags") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = { @@ -130,7 +130,7 @@ public class PetApi { return delegate.findPetsByTags(tags,securityContext); } @GET - + @Path("/{petId}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { @@ -169,7 +169,7 @@ public class PetApi { return delegate.updatePet(pet,securityContext); } @POST - + @Path("/{petId}") @Consumes({ "application/x-www-form-urlencoded" }) @io.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = { @@ -188,7 +188,7 @@ public class PetApi { return delegate.updatePetWithForm(petId,name,status,securityContext); } @POST - + @Path("/{petId}/uploadImage") @Consumes({ "multipart/form-data" }) @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = { diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/StoreApi.java index b13f215a88..cb74fda310 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/StoreApi.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/StoreApi.java @@ -56,7 +56,7 @@ public class StoreApi { } @DELETE - + @Path("/order/{order_id}") @io.swagger.annotations.ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class, tags={ "store", }) @@ -70,7 +70,7 @@ public class StoreApi { return delegate.deleteOrder(orderId,securityContext); } @GET - + @Path("/inventory") @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = { @@ -83,7 +83,7 @@ public class StoreApi { return delegate.getInventory(securityContext); } @GET - + @Path("/order/{order_id}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", }) @@ -99,7 +99,7 @@ public class StoreApi { return delegate.getOrderById(orderId,securityContext); } @POST - + @Path("/order") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", }) diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/UserApi.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/UserApi.java index 64512acb6b..a99d03e8d3 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/UserApi.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/api/UserApi.java @@ -68,7 +68,7 @@ public class UserApi { return delegate.createUser(user,securityContext); } @POST - + @Path("/createWithArray") @io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @@ -80,7 +80,7 @@ public class UserApi { return delegate.createUsersWithArrayInput(user,securityContext); } @POST - + @Path("/createWithList") @io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @@ -92,7 +92,7 @@ public class UserApi { return delegate.createUsersWithListInput(user,securityContext); } @DELETE - + @Path("/{username}") @io.swagger.annotations.ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", }) @@ -106,7 +106,7 @@ public class UserApi { return delegate.deleteUser(username,securityContext); } @GET - + @Path("/{username}") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ "user", }) @@ -122,7 +122,7 @@ public class UserApi { return delegate.getUserByName(username,securityContext); } @GET - + @Path("/login") @Produces({ "application/xml", "application/json" }) @io.swagger.annotations.ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", }) @@ -137,7 +137,7 @@ public class UserApi { return delegate.loginUser(username,password,securityContext); } @GET - + @Path("/logout") @io.swagger.annotations.ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class, tags={ "user", }) @@ -148,7 +148,7 @@ public class UserApi { return delegate.logoutUser(securityContext); } @PUT - + @Path("/{username}") @io.swagger.annotations.ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })