forked from loafle/openapi-generator-original
[Play Framework] Regenerate the samples. It was very outdated (#3760)
* Generate the samples for Play Framework. It was very outdated * Add java-play-framework to the ensure-up-to-date script * Update samples
This commit is contained in:
committed by
GitHub
parent
e1116814c4
commit
f94ff32b0c
@@ -12,10 +12,10 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class Category {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
private String name;
|
||||
|
||||
public Category id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -12,13 +12,13 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class ModelApiResponse {
|
||||
@JsonProperty("code")
|
||||
private Integer code = null;
|
||||
private Integer code;
|
||||
|
||||
@JsonProperty("type")
|
||||
private String type = null;
|
||||
private String type;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message = null;
|
||||
private String message;
|
||||
|
||||
public ModelApiResponse code(Integer code) {
|
||||
this.code = code;
|
||||
|
||||
@@ -13,16 +13,16 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class Order {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("petId")
|
||||
private Long petId = null;
|
||||
private Long petId;
|
||||
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity = null;
|
||||
private Integer quantity;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
private OffsetDateTime shipDate;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
@@ -47,18 +47,18 @@ public class Order {
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static StatusEnum fromValue(String text) {
|
||||
public static StatusEnum fromValue(String value) {
|
||||
for (StatusEnum b : StatusEnum.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
if (b.value.equals(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty("status")
|
||||
private StatusEnum status = null;
|
||||
private StatusEnum status;
|
||||
|
||||
@JsonProperty("complete")
|
||||
private Boolean complete = false;
|
||||
|
||||
@@ -16,13 +16,13 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class Pet {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("category")
|
||||
private Category category = null;
|
||||
private Category category;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
private String name;
|
||||
|
||||
@JsonProperty("photoUrls")
|
||||
private List<String> photoUrls = new ArrayList<>();
|
||||
@@ -53,18 +53,18 @@ public class Pet {
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static StatusEnum fromValue(String text) {
|
||||
public static StatusEnum fromValue(String value) {
|
||||
for (StatusEnum b : StatusEnum.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
if (b.value.equals(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty("status")
|
||||
private StatusEnum status = null;
|
||||
private StatusEnum status;
|
||||
|
||||
public Pet id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -12,10 +12,10 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class Tag {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
private String name;
|
||||
|
||||
public Tag id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -12,28 +12,28 @@ import javax.validation.constraints.*;
|
||||
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
|
||||
public class User {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("username")
|
||||
private String username = null;
|
||||
private String username;
|
||||
|
||||
@JsonProperty("firstName")
|
||||
private String firstName = null;
|
||||
private String firstName;
|
||||
|
||||
@JsonProperty("lastName")
|
||||
private String lastName = null;
|
||||
private String lastName;
|
||||
|
||||
@JsonProperty("email")
|
||||
private String email = null;
|
||||
private String email;
|
||||
|
||||
@JsonProperty("password")
|
||||
private String password = null;
|
||||
private String password;
|
||||
|
||||
@JsonProperty("phone")
|
||||
private String phone = null;
|
||||
private String phone;
|
||||
|
||||
@JsonProperty("userStatus")
|
||||
private Integer userStatus = null;
|
||||
private Integer userStatus;
|
||||
|
||||
public User id(Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -17,9 +17,6 @@ import java.io.File;
|
||||
import openapitools.OpenAPIUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import play.Configuration;
|
||||
|
||||
@@ -41,25 +38,23 @@ public class PetApiController extends Controller {
|
||||
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> addPet() throws Exception {
|
||||
JsonNode nodepet = request().body().asJson();
|
||||
Pet pet;
|
||||
if (nodepet != null) {
|
||||
pet = mapper.readValue(nodepet.toString(), Pet.class);
|
||||
public Result addPet() throws Exception {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
OpenAPIUtils.validate(pet);
|
||||
OpenAPIUtils.validate(body);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'Pet' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.addPet(pet)
|
||||
return ok();
|
||||
});
|
||||
imp.addPet(body);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> deletePet(Long petId) throws Exception {
|
||||
public Result deletePet(Long petId) throws Exception {
|
||||
String valueapiKey = request().getHeader("api_key");
|
||||
String apiKey;
|
||||
if (valueapiKey != null) {
|
||||
@@ -67,14 +62,12 @@ public class PetApiController extends Controller {
|
||||
} else {
|
||||
apiKey = null;
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.deletePet(petId, apiKey)
|
||||
return ok();
|
||||
});
|
||||
imp.deletePet(petId, apiKey);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> findPetsByStatus() throws Exception {
|
||||
public Result findPetsByStatus() throws Exception {
|
||||
String[] statusArray = request().queryString().get("status");
|
||||
if (statusArray == null) {
|
||||
throw new IllegalArgumentException("'status' parameter is required");
|
||||
@@ -87,22 +80,18 @@ public class PetApiController extends Controller {
|
||||
status.add(curParam);
|
||||
}
|
||||
}
|
||||
CompletionStage<List<Pet>> stage = imp.findPetsByStatus(status).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
for (Pet curItem : obj) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByStatus(status);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
for (Pet curItem : obj) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> findPetsByTags() throws Exception {
|
||||
public Result findPetsByTags() throws Exception {
|
||||
String[] tagsArray = request().queryString().get("tags");
|
||||
if (tagsArray == null) {
|
||||
throw new IllegalArgumentException("'tags' parameter is required");
|
||||
@@ -115,93 +104,77 @@ public class PetApiController extends Controller {
|
||||
tags.add(curParam);
|
||||
}
|
||||
}
|
||||
CompletionStage<List<Pet>> stage = imp.findPetsByTags(tags).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
for (Pet curItem : obj) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByTags(tags);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
for (Pet curItem : obj) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> getPetById(Long petId) throws Exception {
|
||||
CompletionStage<Pet> stage = imp.getPetById(petId).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
public Result getPetById(Long petId) throws Exception {
|
||||
Pet obj = imp.getPetById(petId);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> updatePet() throws Exception {
|
||||
JsonNode nodepet = request().body().asJson();
|
||||
Pet pet;
|
||||
if (nodepet != null) {
|
||||
pet = mapper.readValue(nodepet.toString(), Pet.class);
|
||||
public Result updatePet() throws Exception {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
OpenAPIUtils.validate(pet);
|
||||
OpenAPIUtils.validate(body);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'Pet' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.updatePet(pet)
|
||||
return ok();
|
||||
});
|
||||
imp.updatePet(body);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> updatePetWithForm(Long petId) throws Exception {
|
||||
public Result updatePetWithForm(Long petId) throws Exception {
|
||||
String valuename = (request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
|
||||
String name;
|
||||
if (valuename != null) {
|
||||
name = valuename;
|
||||
} else {
|
||||
name = "null";
|
||||
name = null;
|
||||
}
|
||||
String valuestatus = (request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
|
||||
String status;
|
||||
if (valuestatus != null) {
|
||||
status = valuestatus;
|
||||
} else {
|
||||
status = "null";
|
||||
status = null;
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.updatePetWithForm(petId, name, status)
|
||||
return ok();
|
||||
});
|
||||
imp.updatePetWithForm(petId, name, status);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> uploadFile(Long petId) throws Exception {
|
||||
public Result uploadFile(Long petId) throws Exception {
|
||||
String valueadditionalMetadata = (request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
|
||||
String additionalMetadata;
|
||||
if (valueadditionalMetadata != null) {
|
||||
additionalMetadata = valueadditionalMetadata;
|
||||
} else {
|
||||
additionalMetadata = "null";
|
||||
additionalMetadata = null;
|
||||
}
|
||||
Http.MultipartFormData.FilePart file = request().body().asMultipartFormData().getFile("file");
|
||||
CompletionStage<ModelApiResponse> stage = imp.uploadFile(petId, additionalMetadata, file).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
ModelApiResponse obj = imp.uploadFile(petId, additionalMetadata, file);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.validation.constraints.*;
|
||||
|
||||
public class PetApiControllerImp implements PetApiControllerImpInterface {
|
||||
@Override
|
||||
public void addPet(Pet pet) throws Exception {
|
||||
public void addPet(Pet body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
@@ -23,31 +23,25 @@ public class PetApiControllerImp implements PetApiControllerImpInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<List<Pet>> findPetsByStatus( @NotNull List<String> status) throws Exception {
|
||||
public List<Pet> findPetsByStatus( @NotNull List<String> status) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new ArrayList<Pet>();
|
||||
});
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<List<Pet>> findPetsByTags( @NotNull List<String> tags) throws Exception {
|
||||
public List<Pet> findPetsByTags( @NotNull List<String> tags) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new ArrayList<Pet>();
|
||||
});
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Pet> getPetById(Long petId) throws Exception {
|
||||
public Pet getPetById(Long petId) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new Pet();
|
||||
});
|
||||
return new Pet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePet(Pet pet) throws Exception {
|
||||
public void updatePet(Pet body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
@@ -57,11 +51,9 @@ public class PetApiControllerImp implements PetApiControllerImpInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<ModelApiResponse> uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) throws Exception {
|
||||
public ModelApiResponse uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new ModelApiResponse();
|
||||
});
|
||||
return new ModelApiResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,27 +8,25 @@ import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public interface PetApiControllerImpInterface {
|
||||
void addPet(Pet pet) throws Exception;
|
||||
void addPet(Pet body) throws Exception;
|
||||
|
||||
void deletePet(Long petId, String apiKey) throws Exception;
|
||||
|
||||
CompletionStage<List<Pet>> findPetsByStatus( @NotNull List<String> status) throws Exception;
|
||||
List<Pet> findPetsByStatus( @NotNull List<String> status) throws Exception;
|
||||
|
||||
CompletionStage<List<Pet>> findPetsByTags( @NotNull List<String> tags) throws Exception;
|
||||
List<Pet> findPetsByTags( @NotNull List<String> tags) throws Exception;
|
||||
|
||||
CompletionStage<Pet> getPetById(Long petId) throws Exception;
|
||||
Pet getPetById(Long petId) throws Exception;
|
||||
|
||||
void updatePet(Pet pet) throws Exception;
|
||||
void updatePet(Pet body) throws Exception;
|
||||
|
||||
void updatePetWithForm(Long petId, String name, String status) throws Exception;
|
||||
|
||||
CompletionStage<ModelApiResponse> uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) throws Exception;
|
||||
ModelApiResponse uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ import java.io.File;
|
||||
import openapitools.OpenAPIUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import play.Configuration;
|
||||
|
||||
@@ -40,59 +37,45 @@ public class StoreApiController extends Controller {
|
||||
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> deleteOrder(String orderId) throws Exception {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.deleteOrder(orderId)
|
||||
return ok();
|
||||
});
|
||||
public Result deleteOrder(String orderId) throws Exception {
|
||||
imp.deleteOrder(orderId);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> getInventory() throws Exception {
|
||||
CompletionStage<Map<String, Integer>> stage = imp.getInventory().thenApply(obj -> {
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
public Result getInventory() throws Exception {
|
||||
Map<String, Integer> obj = imp.getInventory();
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {
|
||||
CompletionStage<Order> stage = imp.getOrderById(orderId).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
public Result getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {
|
||||
Order obj = imp.getOrderById(orderId);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> placeOrder() throws Exception {
|
||||
JsonNode nodeorder = request().body().asJson();
|
||||
Order order;
|
||||
if (nodeorder != null) {
|
||||
order = mapper.readValue(nodeorder.toString(), Order.class);
|
||||
public Result placeOrder() throws Exception {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Order body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Order.class);
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
OpenAPIUtils.validate(order);
|
||||
OpenAPIUtils.validate(body);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'Order' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
CompletionStage<Order> stage = imp.placeOrder(order).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
Order obj = imp.placeOrder(body);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,27 +17,21 @@ public class StoreApiControllerImp implements StoreApiControllerImpInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Map<String, Integer>> getInventory() throws Exception {
|
||||
public Map<String, Integer> getInventory() throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new HashMap<String, Integer>();
|
||||
});
|
||||
return new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Order> getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {
|
||||
public Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new Order();
|
||||
});
|
||||
return new Order();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Order> placeOrder(Order order) throws Exception {
|
||||
public Order placeOrder(Order body) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new Order();
|
||||
});
|
||||
return new Order();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@@ -16,10 +14,10 @@ import javax.validation.constraints.*;
|
||||
public interface StoreApiControllerImpInterface {
|
||||
void deleteOrder(String orderId) throws Exception;
|
||||
|
||||
CompletionStage<Map<String, Integer>> getInventory() throws Exception;
|
||||
Map<String, Integer> getInventory() throws Exception;
|
||||
|
||||
CompletionStage<Order> getOrderById( @Min(1) @Max(5)Long orderId) throws Exception;
|
||||
Order getOrderById( @Min(1) @Max(5)Long orderId) throws Exception;
|
||||
|
||||
CompletionStage<Order> placeOrder(Order order) throws Exception;
|
||||
Order placeOrder(Order body) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ import java.io.File;
|
||||
import openapitools.OpenAPIUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import play.Configuration;
|
||||
|
||||
@@ -40,87 +37,75 @@ public class UserApiController extends Controller {
|
||||
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> createUser() throws Exception {
|
||||
JsonNode nodeuser = request().body().asJson();
|
||||
User user;
|
||||
if (nodeuser != null) {
|
||||
user = mapper.readValue(nodeuser.toString(), User.class);
|
||||
public Result createUser() throws Exception {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
OpenAPIUtils.validate(user);
|
||||
OpenAPIUtils.validate(body);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'User' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.createUser(user)
|
||||
return ok();
|
||||
});
|
||||
imp.createUser(body);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> createUsersWithArrayInput() throws Exception {
|
||||
JsonNode nodeuser = request().body().asJson();
|
||||
List<User> user;
|
||||
if (nodeuser != null) {
|
||||
user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
|
||||
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>>(){});
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
for (User curItem : user) {
|
||||
for (User curItem : body) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'User' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.createUsersWithArrayInput(user)
|
||||
return ok();
|
||||
});
|
||||
imp.createUsersWithArrayInput(body);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> createUsersWithListInput() throws Exception {
|
||||
JsonNode nodeuser = request().body().asJson();
|
||||
List<User> user;
|
||||
if (nodeuser != null) {
|
||||
user = mapper.readValue(nodeuser.toString(), new TypeReference<List<User>>(){});
|
||||
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>>(){});
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
for (User curItem : user) {
|
||||
for (User curItem : body) {
|
||||
OpenAPIUtils.validate(curItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'User' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.createUsersWithListInput(user)
|
||||
return ok();
|
||||
});
|
||||
imp.createUsersWithListInput(body);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> deleteUser(String username) throws Exception {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.deleteUser(username)
|
||||
return ok();
|
||||
});
|
||||
public Result deleteUser(String username) throws Exception {
|
||||
imp.deleteUser(username);
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> getUserByName(String username) throws Exception {
|
||||
CompletionStage<User> stage = imp.getUserByName(username).thenApply(obj -> {
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
public Result getUserByName(String username) throws Exception {
|
||||
User obj = imp.getUserByName(username);
|
||||
if (configuration.getBoolean("useOutputBeanValidation")) {
|
||||
OpenAPIUtils.validate(obj);
|
||||
}
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> loginUser() throws Exception {
|
||||
public Result loginUser() throws Exception {
|
||||
String valueusername = request().getQueryString("username");
|
||||
String username;
|
||||
if (valueusername != null) {
|
||||
@@ -135,38 +120,30 @@ public class UserApiController extends Controller {
|
||||
} else {
|
||||
throw new IllegalArgumentException("'password' parameter is required");
|
||||
}
|
||||
CompletionStage<String> stage = imp.loginUser(username, password).thenApply(obj -> {
|
||||
return obj;
|
||||
});
|
||||
stage.thenApply(obj -> {
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
});
|
||||
String obj = imp.loginUser(username, password);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> logoutUser() throws Exception {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.logoutUser()
|
||||
return ok();
|
||||
});
|
||||
public Result logoutUser() throws Exception {
|
||||
imp.logoutUser();
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public CompletionStage<Result> updateUser(String username) throws Exception {
|
||||
JsonNode nodeuser = request().body().asJson();
|
||||
User user;
|
||||
if (nodeuser != null) {
|
||||
user = mapper.readValue(nodeuser.toString(), User.class);
|
||||
public Result updateUser(String username) throws Exception {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
if (configuration.getBoolean("useInputBeanValidation")) {
|
||||
OpenAPIUtils.validate(user);
|
||||
OpenAPIUtils.validate(body);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("'User' parameter is required");
|
||||
throw new IllegalArgumentException("'body' parameter is required");
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
imp.updateUser(username, user)
|
||||
return ok();
|
||||
});
|
||||
imp.updateUser(username, body);
|
||||
return ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,17 @@ import javax.validation.constraints.*;
|
||||
|
||||
public class UserApiControllerImp implements UserApiControllerImpInterface {
|
||||
@Override
|
||||
public void createUser(User user) throws Exception {
|
||||
public void createUser(User body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUsersWithArrayInput(List<User> user) throws Exception {
|
||||
public void createUsersWithArrayInput(List<User> body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUsersWithListInput(List<User> user) throws Exception {
|
||||
public void createUsersWithListInput(List<User> body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
@@ -32,19 +32,15 @@ public class UserApiControllerImp implements UserApiControllerImpInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<User> getUserByName(String username) throws Exception {
|
||||
public User getUserByName(String username) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new User();
|
||||
});
|
||||
return new User();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<String> loginUser( @NotNull String username, @NotNull String password) throws Exception {
|
||||
public String loginUser( @NotNull String username, @NotNull String password) throws Exception {
|
||||
//Do your magic!!!
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
return new String();
|
||||
});
|
||||
return new String();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +49,7 @@ public class UserApiControllerImp implements UserApiControllerImpInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(String username, User user) throws Exception {
|
||||
public void updateUser(String username, User body) throws Exception {
|
||||
//Do your magic!!!
|
||||
}
|
||||
|
||||
|
||||
@@ -7,27 +7,25 @@ import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public interface UserApiControllerImpInterface {
|
||||
void createUser(User user) throws Exception;
|
||||
void createUser(User body) throws Exception;
|
||||
|
||||
void createUsersWithArrayInput(List<User> user) throws Exception;
|
||||
void createUsersWithArrayInput(List<User> body) throws Exception;
|
||||
|
||||
void createUsersWithListInput(List<User> user) throws Exception;
|
||||
void createUsersWithListInput(List<User> body) throws Exception;
|
||||
|
||||
void deleteUser(String username) throws Exception;
|
||||
|
||||
CompletionStage<User> getUserByName(String username) throws Exception;
|
||||
User getUserByName(String username) throws Exception;
|
||||
|
||||
CompletionStage<String> loginUser( @NotNull String username, @NotNull String password) throws Exception;
|
||||
String loginUser( @NotNull String username, @NotNull String password) throws Exception;
|
||||
|
||||
void logoutUser() throws Exception;
|
||||
|
||||
void updateUser(String username, User user) throws Exception;
|
||||
void updateUser(String username, User body) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -98,6 +98,6 @@ public class OpenAPIUtils {
|
||||
}
|
||||
|
||||
public static String formatDatetime(Date date) {
|
||||
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date);
|
||||
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT).format(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user