fix inner item (list, map) for play framework (#217)

This commit is contained in:
William Cheng 2018-04-24 19:02:10 +08:00 committed by GitHub
parent c8c316e41e
commit 2c6380c846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 664 additions and 528 deletions

View File

@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # 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" export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/openapi-generator/src/main/resources/JavaPlayFramework -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l java-play-framework -o samples/server/petstore/java-play-framework -DhideGenerationTimestamp=true" ags="generate -t modules/openapi-generator/src/main/resources/JavaPlayFramework -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l java-play-framework -o samples/server/petstore/java-play-framework -DhideGenerationTimestamp=true $@"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -69,12 +69,12 @@ public class {{classname}}Controller extends Controller {
{{#useBeanValidation}} {{#useBeanValidation}}
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
{{#isListContainer}} {{#isListContainer}}
for ({{{baseType}}} curItem : {{paramName}}) { for ({{{items.baseType}}} curItem : {{paramName}}) {
SwaggerUtils.validate(curItem); SwaggerUtils.validate(curItem);
} }
{{/isListContainer}} {{/isListContainer}}
{{#isMapContainer}} {{#isMapContainer}}
for (Map.Entry<String, {{{baseType}}}> entry : {{paramName}}.entrySet()) { for (Map.Entry<String, {{{items.baseType}}}> entry : {{paramName}}.entrySet()) {
SwaggerUtils.validate(entry.getValue()); SwaggerUtils.validate(entry.getValue());
} }
{{/isMapContainer}} {{/isMapContainer}}

View File

@ -1 +1 @@
2.4.0-SNAPSHOT 3.0.0-SNAPSHOT

View File

@ -10,6 +10,6 @@ public class ApiDocController extends Controller {
} }
public Result api() { public Result api() {
return redirect("/assets/lib/swagger-ui/index.html?/url=/assets/swagger.json"); return redirect("/assets/lib/swagger-ui/index.html?/url=/assets/openapi.json");
} }
} }

View File

@ -39,17 +39,17 @@ public class PetApiController extends Controller {
@ApiAction @ApiAction
public Result addPet() throws Exception { public Result addPet() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodepet = request().body().asJson();
Pet body; Pet pet;
if (nodebody != null) { if (nodepet != null) {
body = mapper.readValue(nodebody.toString(), Pet.class); pet = mapper.readValue(nodepet.toString(), Pet.class);
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body); SwaggerUtils.validate(pet);
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'Pet' parameter is required");
} }
imp.addPet(body); imp.addPet(pet);
return ok(); return ok();
} }
@ -126,17 +126,17 @@ public class PetApiController extends Controller {
@ApiAction @ApiAction
public Result updatePet() throws Exception { public Result updatePet() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodepet = request().body().asJson();
Pet body; Pet pet;
if (nodebody != null) { if (nodepet != null) {
body = mapper.readValue(nodebody.toString(), Pet.class); pet = mapper.readValue(nodepet.toString(), Pet.class);
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body); SwaggerUtils.validate(pet);
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'Pet' parameter is required");
} }
imp.updatePet(body); imp.updatePet(pet);
return ok(); return ok();
} }

View File

@ -13,7 +13,7 @@ import javax.validation.constraints.*;
public class PetApiControllerImp implements PetApiControllerImpInterface { public class PetApiControllerImp implements PetApiControllerImpInterface {
@Override @Override
public void addPet(Pet body) throws Exception { public void addPet(Pet pet) throws Exception {
//Do your magic!!! //Do your magic!!!
} }
@ -41,7 +41,7 @@ public class PetApiControllerImp implements PetApiControllerImpInterface {
} }
@Override @Override
public void updatePet(Pet body) throws Exception { public void updatePet(Pet pet) throws Exception {
//Do your magic!!! //Do your magic!!!
} }

View File

@ -13,7 +13,7 @@ import javax.validation.constraints.*;
@SuppressWarnings("RedundantThrows") @SuppressWarnings("RedundantThrows")
public interface PetApiControllerImpInterface { public interface PetApiControllerImpInterface {
void addPet(Pet body) throws Exception; void addPet(Pet pet) throws Exception;
void deletePet(Long petId, String apiKey) throws Exception; void deletePet(Long petId, String apiKey) throws Exception;
@ -23,7 +23,7 @@ public interface PetApiControllerImpInterface {
Pet getPetById(Long petId) throws Exception; Pet getPetById(Long petId) throws Exception;
void updatePet(Pet body) throws Exception; void updatePet(Pet pet) throws Exception;
void updatePetWithForm(Long petId, String name, String status) throws Exception; void updatePetWithForm(Long petId, String name, String status) throws Exception;

View File

@ -61,17 +61,17 @@ public class StoreApiController extends Controller {
@ApiAction @ApiAction
public Result placeOrder() throws Exception { public Result placeOrder() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodeorder = request().body().asJson();
Order body; Order order;
if (nodebody != null) { if (nodeorder != null) {
body = mapper.readValue(nodebody.toString(), Order.class); order = mapper.readValue(nodeorder.toString(), Order.class);
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body); SwaggerUtils.validate(order);
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'Order' parameter is required");
} }
Order obj = imp.placeOrder(body); Order obj = imp.placeOrder(order);
if (configuration.getBoolean("useOutputBeanValidation")) { if (configuration.getBoolean("useOutputBeanValidation")) {
SwaggerUtils.validate(obj); SwaggerUtils.validate(obj);
} }

View File

@ -29,7 +29,7 @@ public class StoreApiControllerImp implements StoreApiControllerImpInterface {
} }
@Override @Override
public Order placeOrder(Order body) throws Exception { public Order placeOrder(Order order) throws Exception {
//Do your magic!!! //Do your magic!!!
return new Order(); return new Order();
} }

View File

@ -18,6 +18,6 @@ public interface StoreApiControllerImpInterface {
Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception; Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception;
Order placeOrder(Order body) throws Exception; Order placeOrder(Order order) throws Exception;
} }

View File

@ -38,53 +38,53 @@ public class UserApiController extends Controller {
@ApiAction @ApiAction
public Result createUser() throws Exception { public Result createUser() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodeuser = request().body().asJson();
User body; User user;
if (nodebody != null) { if (nodeuser != null) {
body = mapper.readValue(nodebody.toString(), User.class); user = mapper.readValue(nodeuser.toString(), User.class);
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body); SwaggerUtils.validate(user);
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'User' parameter is required");
} }
imp.createUser(body); imp.createUser(user);
return ok(); return ok();
} }
@ApiAction @ApiAction
public Result createUsersWithArrayInput() throws Exception { public Result createUsersWithArrayInput() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodeuser = request().body().asJson();
List<User> body; List<User> user;
if (nodebody != null) { if (nodeuser != null) {
body = mapper.readValue(nodebody.toString(), new TypeReference<List<User>>(){}); user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
for (User curItem : body) { for (User curItem : user) {
SwaggerUtils.validate(curItem); SwaggerUtils.validate(curItem);
} }
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'User' parameter is required");
} }
imp.createUsersWithArrayInput(body); imp.createUsersWithArrayInput(user);
return ok(); return ok();
} }
@ApiAction @ApiAction
public Result createUsersWithListInput() throws Exception { public Result createUsersWithListInput() throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodeuser = request().body().asJson();
List<User> body; List<User> user;
if (nodebody != null) { if (nodeuser != null) {
body = mapper.readValue(nodebody.toString(), new TypeReference<List<User>>(){}); user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
for (User curItem : body) { for (User curItem : user) {
SwaggerUtils.validate(curItem); SwaggerUtils.validate(curItem);
} }
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'User' parameter is required");
} }
imp.createUsersWithListInput(body); imp.createUsersWithListInput(user);
return ok(); return ok();
} }
@ -133,17 +133,17 @@ public class UserApiController extends Controller {
@ApiAction @ApiAction
public Result updateUser(String username) throws Exception { public Result updateUser(String username) throws Exception {
JsonNode nodebody = request().body().asJson(); JsonNode nodeuser = request().body().asJson();
User body; User user;
if (nodebody != null) { if (nodeuser != null) {
body = mapper.readValue(nodebody.toString(), User.class); user = mapper.readValue(nodeuser.toString(), User.class);
if (configuration.getBoolean("useInputBeanValidation")) { if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body); SwaggerUtils.validate(user);
} }
} else { } else {
throw new IllegalArgumentException("'body' parameter is required"); throw new IllegalArgumentException("'User' parameter is required");
} }
imp.updateUser(username, body); imp.updateUser(username, user);
return ok(); return ok();
} }
} }

View File

@ -12,17 +12,17 @@ import javax.validation.constraints.*;
public class UserApiControllerImp implements UserApiControllerImpInterface { public class UserApiControllerImp implements UserApiControllerImpInterface {
@Override @Override
public void createUser(User body) throws Exception { public void createUser(User user) throws Exception {
//Do your magic!!! //Do your magic!!!
} }
@Override @Override
public void createUsersWithArrayInput(List<User> body) throws Exception { public void createUsersWithArrayInput(List<User> user) throws Exception {
//Do your magic!!! //Do your magic!!!
} }
@Override @Override
public void createUsersWithListInput(List<User> body) throws Exception { public void createUsersWithListInput(List<User> user) throws Exception {
//Do your magic!!! //Do your magic!!!
} }
@ -49,7 +49,7 @@ public class UserApiControllerImp implements UserApiControllerImpInterface {
} }
@Override @Override
public void updateUser(String username, User body) throws Exception { public void updateUser(String username, User user) throws Exception {
//Do your magic!!! //Do your magic!!!
} }

View File

@ -12,11 +12,11 @@ import javax.validation.constraints.*;
@SuppressWarnings("RedundantThrows") @SuppressWarnings("RedundantThrows")
public interface UserApiControllerImpInterface { public interface UserApiControllerImpInterface {
void createUser(User body) throws Exception; void createUser(User user) throws Exception;
void createUsersWithArrayInput(List<User> body) throws Exception; void createUsersWithArrayInput(List<User> user) throws Exception;
void createUsersWithListInput(List<User> body) throws Exception; void createUsersWithListInput(List<User> user) throws Exception;
void deleteUser(String username) throws Exception; void deleteUser(String username) throws Exception;
@ -26,6 +26,6 @@ public interface UserApiControllerImpInterface {
void logoutUser() throws Exception; void logoutUser() throws Exception;
void updateUser(String username, User body) throws Exception; void updateUser(String username, User user) throws Exception;
} }

View File

@ -1,4 +1,4 @@
name := """swagger-java-playframework""" name := """openapi-java-playframework"""
version := "1.0-SNAPSHOT" version := "1.0-SNAPSHOT"

File diff suppressed because it is too large Load Diff