Modify "postProcessOperations" for "jaxrs-cxf-client" (#7886)

* Fix sh script for 'jaxrs-cxf-client' and generate sample

* Modify "postProcessOperations" for "jaxrs-cxf-client"

* Update "jaxrs-cxf-client" sample
This commit is contained in:
Jérémie Bresson 2018-04-05 17:34:37 +02:00 committed by William Cheng
parent 3c5fb1d809
commit 386b9f432a
21 changed files with 58 additions and 288 deletions

View File

@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate --artifact-id "jaxrs-cxf-petstore-client" -t modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/ -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs-cxf -o samples/client/petstore/jaxrs-cxf-client/"
ags="$@ generate --artifact-id "jaxrs-cxf-petstore-client" -t modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/ -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs-cxf-client -o samples/client/petstore/jaxrs-cxf-client/"
java $JAVA_OPTS -jar $executable $ags

View File

@ -134,6 +134,10 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
return jaxrsPostProcessOperations(objs);
}
static Map<String, Object> jaxrsPostProcessOperations(Map<String, Object> objs) {
@SuppressWarnings("unchecked")
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if ( operations != null ) {

View File

@ -137,22 +137,7 @@ private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFClientCodege
@SuppressWarnings("unchecked")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
objs = super.postProcessOperations(objs);
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (operation.returnType == null) {
operation.returnType = "void";
// set vendorExtensions.x-java-is-response-void to true as
// returnType is set to "void"
operation.vendorExtensions.put("x-java-is-response-void", true);
}
}
}
return operations;
return AbstractJavaJAXRSServerCodegen.jaxrsPostProcessOperations(objs);
}
@Override

View File

@ -21,5 +21,3 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
**/impl/*

View File

@ -1 +1 @@
2.3.1-SNAPSHOT
2.4.0-SNAPSHOT

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>jaxrs-cxf-petstore-client</artifactId>
<packaging>war</packaging>
<packaging>jar</packaging>
<name>jaxrs-cxf-petstore-client</name>
<description>This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters.</description>
<version>1.0.0</version>
@ -33,7 +33,7 @@
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<httpConnector>
<port>8080</port>
<port></port>
<idleTimeout>60000</idleTimeout>
</httpConnector>
</configuration>
@ -77,15 +77,6 @@
</execution>
</executions>
</plugin>
<!-- build WAR file -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
@ -113,13 +104,6 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${beanvalidation-version}</version>
<scope>provided</scope>
</dependency>
<!-- CXF Client -->
<dependency>
<groupId>org.apache.cxf</groupId>
@ -141,12 +125,6 @@
<version>${cxf-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>${cxf-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
@ -169,7 +147,6 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson-jaxrs-version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
@ -190,7 +167,6 @@
<junit-version>4.12</junit-version>
<logback-version>1.1.7</logback-version>
<servlet-api-version>2.5</servlet-api-version>
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
<cxf-version>3.2.1</cxf-version>
<jackson-jaxrs-version>2.9.1</jackson-jaxrs-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -18,8 +18,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*;
import javax.validation.Valid;
/**
* Swagger Petstore
@ -41,10 +39,10 @@ public interface PetApi {
@Path("/pet")
@Consumes({ "application/json", "application/xml" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a new pet to the store", tags={ "pet", })
@ApiOperation(value = "Add a new pet to the store", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") })
public void addPet(@Valid Pet body);
public void addPet(Pet body);
/**
* Deletes a pet
@ -55,7 +53,7 @@ public interface PetApi {
@DELETE
@Path("/pet/{petId}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Deletes a pet", tags={ "pet", })
@ApiOperation(value = "Deletes a pet", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid pet value") })
public void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey);
@ -69,11 +67,11 @@ public interface PetApi {
@GET
@Path("/pet/findByStatus")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Finds Pets by status", tags={ "pet", })
@ApiOperation(value = "Finds Pets by status", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
@ApiResponse(code = 400, message = "Invalid status value") })
public List<Pet> findPetsByStatus(@QueryParam("status") @NotNull List<String> status);
public List<Pet> findPetsByStatus(@QueryParam("status")List<String> status);
/**
* Finds Pets by tags
@ -84,11 +82,11 @@ public interface PetApi {
@GET
@Path("/pet/findByTags")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Finds Pets by tags", tags={ "pet", })
@ApiOperation(value = "Finds Pets by tags", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
@ApiResponse(code = 400, message = "Invalid tag value") })
public List<Pet> findPetsByTags(@QueryParam("tags") @NotNull List<String> tags);
public List<Pet> findPetsByTags(@QueryParam("tags")List<String> tags);
/**
* Find pet by ID
@ -99,7 +97,7 @@ public interface PetApi {
@GET
@Path("/pet/{petId}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Find pet by ID", tags={ "pet", })
@ApiOperation(value = "Find pet by ID", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ -116,12 +114,12 @@ public interface PetApi {
@Path("/pet")
@Consumes({ "application/json", "application/xml" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update an existing pet", tags={ "pet", })
@ApiOperation(value = "Update an existing pet", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Pet not found"),
@ApiResponse(code = 405, message = "Validation exception") })
public void updatePet(@Valid Pet body);
public void updatePet(Pet body);
/**
* Updates a pet in the store with form data
@ -133,7 +131,7 @@ public interface PetApi {
@Path("/pet/{petId}")
@Consumes({ "application/x-www-form-urlencoded" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Updates a pet in the store with form data", tags={ "pet", })
@ApiOperation(value = "Updates a pet in the store with form data", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") })
public void updatePetWithForm(@PathParam("petId") Long petId, @Multipart(value = "name", required = false) String name, @Multipart(value = "status", required = false) String status);
@ -148,7 +146,7 @@ public interface PetApi {
@Path("/pet/{petId}/uploadImage")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@ApiOperation(value = "uploads an image", tags={ "pet" })
@ApiOperation(value = "uploads an image", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
public ModelApiResponse uploadFile(@PathParam("petId") Long petId, @Multipart(value = "additionalMetadata", required = false) String additionalMetadata, @Multipart(value = "file" , required = false) Attachment fileDetail);

View File

@ -1,6 +1,5 @@
package io.swagger.api;
import java.util.Map;
import io.swagger.model.Order;
import java.io.InputStream;
@ -17,8 +16,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*;
import javax.validation.Valid;
/**
* Swagger Petstore
@ -39,7 +36,7 @@ public interface StoreApi {
@DELETE
@Path("/store/order/{orderId}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Delete purchase order by ID", tags={ "store", })
@ApiOperation(value = "Delete purchase order by ID", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Order not found") })
@ -54,7 +51,7 @@ public interface StoreApi {
@GET
@Path("/store/inventory")
@Produces({ "application/json" })
@ApiOperation(value = "Returns pet inventories by status", tags={ "store", })
@ApiOperation(value = "Returns pet inventories by status", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Map.class, responseContainer = "Map") })
public Map<String, Integer> getInventory();
@ -68,12 +65,12 @@ public interface StoreApi {
@GET
@Path("/store/order/{orderId}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Find purchase order by ID", tags={ "store", })
@ApiOperation(value = "Find purchase order by ID", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Order not found") })
public Order getOrderById(@PathParam("orderId") @Min(1) @Max(5) Long orderId);
public Order getOrderById(@PathParam("orderId") Long orderId);
/**
* Place an order for a pet
@ -84,10 +81,10 @@ public interface StoreApi {
@POST
@Path("/store/order")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Place an order for a pet", tags={ "store" })
@ApiOperation(value = "Place an order for a pet", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid Order") })
public Order placeOrder(@Valid Order body);
public Order placeOrder(Order body);
}

View File

@ -1,6 +1,5 @@
package io.swagger.api;
import java.util.List;
import io.swagger.model.User;
import java.io.InputStream;
@ -17,8 +16,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*;
import javax.validation.Valid;
/**
* Swagger Petstore
@ -39,10 +36,10 @@ public interface UserApi {
@POST
@Path("/user")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Create user", tags={ "user", })
@ApiOperation(value = "Create user", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") })
public void createUser(@Valid User body);
public void createUser(User body);
/**
* Creates list of users with given input array
@ -53,10 +50,10 @@ public interface UserApi {
@POST
@Path("/user/createWithArray")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Creates list of users with given input array", tags={ "user", })
@ApiOperation(value = "Creates list of users with given input array", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") })
public void createUsersWithArrayInput(@Valid List<User> body);
public void createUsersWithArrayInput(List<User> body);
/**
* Creates list of users with given input array
@ -67,10 +64,10 @@ public interface UserApi {
@POST
@Path("/user/createWithList")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Creates list of users with given input array", tags={ "user", })
@ApiOperation(value = "Creates list of users with given input array", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") })
public void createUsersWithListInput(@Valid List<User> body);
public void createUsersWithListInput(List<User> body);
/**
* Delete user
@ -81,7 +78,7 @@ public interface UserApi {
@DELETE
@Path("/user/{username}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Delete user", tags={ "user", })
@ApiOperation(value = "Delete user", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid username supplied"),
@ApiResponse(code = 404, message = "User not found") })
@ -96,7 +93,7 @@ public interface UserApi {
@GET
@Path("/user/{username}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get user by user name", tags={ "user", })
@ApiOperation(value = "Get user by user name", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = User.class),
@ApiResponse(code = 400, message = "Invalid username supplied"),
@ -112,11 +109,11 @@ public interface UserApi {
@GET
@Path("/user/login")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Logs user into the system", tags={ "user", })
@ApiOperation(value = "Logs user into the system", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 400, message = "Invalid username/password supplied") })
public String loginUser(@QueryParam("username") @NotNull String username, @QueryParam("password") @NotNull String password);
public String loginUser(@QueryParam("username")String username, @QueryParam("password")String password);
/**
* Logs out current logged in user session
@ -127,7 +124,7 @@ public interface UserApi {
@GET
@Path("/user/logout")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Logs out current logged in user session", tags={ "user", })
@ApiOperation(value = "Logs out current logged in user session", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") })
public void logoutUser();
@ -141,10 +138,10 @@ public interface UserApi {
@PUT
@Path("/user/{username}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Updated user", tags={ "user" })
@ApiOperation(value = "Updated user", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid user supplied"),
@ApiResponse(code = 404, message = "User not found") })
public void updateUser(@PathParam("username") String username, @Valid User body);
public void updateUser(@PathParam("username") String username, User body);
}

View File

@ -1,7 +1,6 @@
package io.swagger.model;
import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;

View File

@ -1,7 +1,6 @@
package io.swagger.model;
import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;

View File

@ -2,7 +2,6 @@ package io.swagger.model;
import io.swagger.annotations.ApiModel;
import java.util.Date;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;

View File

@ -5,7 +5,6 @@ import io.swagger.model.Category;
import io.swagger.model.Tag;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;
@ -117,7 +116,6 @@ public enum StatusEnum {
* @return name
**/
@JsonProperty("name")
@NotNull
public String getName() {
return name;
}
@ -136,7 +134,6 @@ public enum StatusEnum {
* @return photoUrls
**/
@JsonProperty("photoUrls")
@NotNull
public List<String> getPhotoUrls() {
return photoUrls;
}

View File

@ -1,7 +1,6 @@
package io.swagger.model;
import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;

View File

@ -1,7 +1,6 @@
package io.swagger.model;
import io.swagger.annotations.ApiModel;
import javax.validation.constraints.*;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlElement;

View File

@ -1,71 +0,0 @@
package io.swagger.api.impl;
import io.swagger.api.*;
import java.io.File;
import io.swagger.model.ModelApiResponse;
import io.swagger.model.Pet;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
import org.apache.cxf.jaxrs.ext.multipart.*;
import io.swagger.annotations.Api;
public class PetApiServiceImpl implements PetApi {
public void addPet(Pet body) {
// TODO: Implement...
}
public void deletePet(Long petId, String apiKey) {
// TODO: Implement...
}
public List<Pet> findPetsByStatus(List<String> status) {
// TODO: Implement...
return null;
}
public List<Pet> findPetsByTags(List<String> tags) {
// TODO: Implement...
return null;
}
public Pet getPetById(Long petId) {
// TODO: Implement...
return null;
}
public void updatePet(Pet body) {
// TODO: Implement...
}
public void updatePetWithForm(Long petId, String name, String status) {
// TODO: Implement...
}
public ModelApiResponse uploadFile(Long petId, String additionalMetadata, Attachment fileDetail) {
// TODO: Implement...
return null;
}
}

View File

@ -1,46 +0,0 @@
package io.swagger.api.impl;
import io.swagger.api.*;
import java.util.Map;
import io.swagger.model.Order;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
import org.apache.cxf.jaxrs.ext.multipart.*;
import io.swagger.annotations.Api;
public class StoreApiServiceImpl implements StoreApi {
public void deleteOrder(String orderId) {
// TODO: Implement...
}
public Map<String, Integer> getInventory() {
// TODO: Implement...
return null;
}
public Order getOrderById(Long orderId) {
// TODO: Implement...
return null;
}
public Order placeOrder(Order body) {
// TODO: Implement...
return null;
}
}

View File

@ -1,70 +0,0 @@
package io.swagger.api.impl;
import io.swagger.api.*;
import java.util.List;
import io.swagger.model.User;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.apache.cxf.jaxrs.model.wadl.Description;
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
import org.apache.cxf.jaxrs.ext.multipart.*;
import io.swagger.annotations.Api;
public class UserApiServiceImpl implements UserApi {
public void createUser(User body) {
// TODO: Implement...
}
public void createUsersWithArrayInput(List<User> body) {
// TODO: Implement...
}
public void createUsersWithListInput(List<User> body) {
// TODO: Implement...
}
public void deleteUser(String username) {
// TODO: Implement...
}
public User getUserByName(String username) {
// TODO: Implement...
return null;
}
public String loginUser(String username, String password) {
// TODO: Implement...
return null;
}
public void logoutUser() {
// TODO: Implement...
}
public void updateUser(String username, User body) {
// TODO: Implement...
}
}

View File

@ -49,6 +49,10 @@ import java.util.Map;
/**
* Swagger Petstore
*
* <p>This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* API tests for PetApi
*/
public class PetApiTest {

View File

@ -25,7 +25,6 @@
package io.swagger.api;
import java.util.Map;
import io.swagger.model.Order;
import org.junit.Test;
import org.junit.Before;
@ -48,6 +47,10 @@ import java.util.Map;
/**
* Swagger Petstore
*
* <p>This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* API tests for StoreApi
*/
public class StoreApiTest {

View File

@ -25,7 +25,6 @@
package io.swagger.api;
import java.util.List;
import io.swagger.model.User;
import org.junit.Test;
import org.junit.Before;
@ -48,6 +47,10 @@ import java.util.Map;
/**
* Swagger Petstore
*
* <p>This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* API tests for UserApi
*/
public class UserApiTest {