Skip to content

Commit

Permalink
fix inner item (list, map) for play framework (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Apr 24, 2018
1 parent c8c316e commit 2c6380c
Show file tree
Hide file tree
Showing 15 changed files with 652 additions and 516 deletions.
2 changes: 1 addition & 1 deletion bin/java-play-framework-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 -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
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public class {{classname}}Controller extends Controller {
{{#useBeanValidation}}
if (configuration.getBoolean("useInputBeanValidation")) {
{{#isListContainer}}
for ({{{baseType}}} curItem : {{paramName}}) {
for ({{{items.baseType}}} curItem : {{paramName}}) {
SwaggerUtils.validate(curItem);
}
{{/isListContainer}}
{{#isMapContainer}}
for (Map.Entry<String, {{{baseType}}}> entry : {{paramName}}.entrySet()) {
for (Map.Entry<String, {{{items.baseType}}}> entry : {{paramName}}.entrySet()) {
SwaggerUtils.validate(entry.getValue());
}
{{/isMapContainer}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0-SNAPSHOT
3.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ private ApiDocController() {
}

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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ private PetApiController(Configuration configuration, PetApiControllerImpInterfa

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

Expand Down Expand Up @@ -126,17 +126,17 @@ public Result getPetById(Long petId) throws Exception {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class PetApiControllerImp implements PetApiControllerImpInterface {
@Override
public void addPet(Pet body) throws Exception {
public void addPet(Pet pet) throws Exception {
//Do your magic!!!
}

Expand Down Expand Up @@ -41,7 +41,7 @@ public Pet getPetById(Long petId) throws Exception {
}

@Override
public void updatePet(Pet body) throws Exception {
public void updatePet(Pet pet) throws Exception {
//Do your magic!!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@SuppressWarnings("RedundantThrows")
public interface PetApiControllerImpInterface {
void addPet(Pet body) throws Exception;
void addPet(Pet pet) throws Exception;

void deletePet(Long petId, String apiKey) throws Exception;

Expand All @@ -23,7 +23,7 @@ public interface PetApiControllerImpInterface {

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ public Result getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {

@ApiAction
public Result placeOrder() throws Exception {
JsonNode nodebody = request().body().asJson();
Order body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), Order.class);
JsonNode nodeorder = request().body().asJson();
Order order;
if (nodeorder != null) {
order = mapper.readValue(nodeorder.toString(), Order.class);
if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body);
SwaggerUtils.validate(order);
}
} 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")) {
SwaggerUtils.validate(obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {
}

@Override
public Order placeOrder(Order body) throws Exception {
public Order placeOrder(Order order) throws Exception {
//Do your magic!!!
return new Order();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public interface StoreApiControllerImpInterface {

Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception;

Order placeOrder(Order body) throws Exception;
Order placeOrder(Order order) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,53 @@ private UserApiController(Configuration configuration, UserApiControllerImpInter

@ApiAction
public Result createUser() throws Exception {
JsonNode nodebody = request().body().asJson();
User body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), User.class);
JsonNode nodeuser = request().body().asJson();
User user;
if (nodeuser != null) {
user = mapper.readValue(nodeuser.toString(), User.class);
if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body);
SwaggerUtils.validate(user);
}
} else {
throw new IllegalArgumentException("'body' parameter is required");
throw new IllegalArgumentException("'User' parameter is required");
}
imp.createUser(body);
imp.createUser(user);
return ok();
}

@ApiAction
public Result createUsersWithArrayInput() throws Exception {
JsonNode nodebody = request().body().asJson();
List<User> body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), new TypeReference<List<User>>(){});
JsonNode nodeuser = request().body().asJson();
List<User> user;
if (nodeuser != null) {
user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
if (configuration.getBoolean("useInputBeanValidation")) {
for (User curItem : body) {
for (User curItem : user) {
SwaggerUtils.validate(curItem);
}
}
} else {
throw new IllegalArgumentException("'body' parameter is required");
throw new IllegalArgumentException("'User' parameter is required");
}
imp.createUsersWithArrayInput(body);
imp.createUsersWithArrayInput(user);
return ok();
}

@ApiAction
public Result createUsersWithListInput() throws Exception {
JsonNode nodebody = request().body().asJson();
List<User> body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), new TypeReference<List<User>>(){});
JsonNode nodeuser = request().body().asJson();
List<User> user;
if (nodeuser != null) {
user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
if (configuration.getBoolean("useInputBeanValidation")) {
for (User curItem : body) {
for (User curItem : user) {
SwaggerUtils.validate(curItem);
}
}
} else {
throw new IllegalArgumentException("'body' parameter is required");
throw new IllegalArgumentException("'User' parameter is required");
}
imp.createUsersWithListInput(body);
imp.createUsersWithListInput(user);
return ok();
}

Expand Down Expand Up @@ -133,17 +133,17 @@ public Result logoutUser() throws Exception {

@ApiAction
public Result updateUser(String username) throws Exception {
JsonNode nodebody = request().body().asJson();
User body;
if (nodebody != null) {
body = mapper.readValue(nodebody.toString(), User.class);
JsonNode nodeuser = request().body().asJson();
User user;
if (nodeuser != null) {
user = mapper.readValue(nodeuser.toString(), User.class);
if (configuration.getBoolean("useInputBeanValidation")) {
SwaggerUtils.validate(body);
SwaggerUtils.validate(user);
}
} 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

public class UserApiControllerImp implements UserApiControllerImpInterface {
@Override
public void createUser(User body) throws Exception {
public void createUser(User user) throws Exception {
//Do your magic!!!
}

@Override
public void createUsersWithArrayInput(List<User> body) throws Exception {
public void createUsersWithArrayInput(List<User> user) throws Exception {
//Do your magic!!!
}

@Override
public void createUsersWithListInput(List<User> body) throws Exception {
public void createUsersWithListInput(List<User> user) throws Exception {
//Do your magic!!!
}

Expand All @@ -49,7 +49,7 @@ public void logoutUser() throws Exception {
}

@Override
public void updateUser(String username, User body) throws Exception {
public void updateUser(String username, User user) throws Exception {
//Do your magic!!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

@SuppressWarnings("RedundantThrows")
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;

Expand All @@ -26,6 +26,6 @@ public interface UserApiControllerImpInterface {

void logoutUser() throws Exception;

void updateUser(String username, User body) throws Exception;
void updateUser(String username, User user) throws Exception;

}
2 changes: 1 addition & 1 deletion samples/server/petstore/java-play-framework/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name := """swagger-java-playframework"""
name := """openapi-java-playframework"""

version := "1.0-SNAPSHOT"

Expand Down
Loading

0 comments on commit 2c6380c

Please sign in to comment.