mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 08:46:55 +00:00
committed by
wing328
parent
f00e6b349e
commit
bca35f6645
@@ -0,0 +1,92 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* A category for a pet
|
||||
*/
|
||||
|
||||
public class Category {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
|
||||
public Category id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Category name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return name
|
||||
**/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Category category = (Category) o;
|
||||
return Objects.equals(this.id, category.id) &&
|
||||
Objects.equals(this.name, category.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Category {\n");
|
||||
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
*/
|
||||
|
||||
public class ModelApiResponse {
|
||||
@JsonProperty("code")
|
||||
private Integer code = null;
|
||||
|
||||
@JsonProperty("type")
|
||||
private String type = null;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message = null;
|
||||
|
||||
public ModelApiResponse code(Integer code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get code
|
||||
* @return code
|
||||
**/
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ModelApiResponse type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type
|
||||
* @return type
|
||||
**/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ModelApiResponse message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message
|
||||
* @return message
|
||||
**/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ModelApiResponse _apiResponse = (ModelApiResponse) o;
|
||||
return Objects.equals(this.code, _apiResponse.code) &&
|
||||
Objects.equals(this.type, _apiResponse.type) &&
|
||||
Objects.equals(this.message, _apiResponse.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(code, type, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ModelApiResponse {\n");
|
||||
|
||||
sb.append(" code: ").append(toIndentedString(code)).append("\n");
|
||||
sb.append(" type: ").append(toIndentedString(type)).append("\n");
|
||||
sb.append(" message: ").append(toIndentedString(message)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.time.OffsetDateTime;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* An order for a pets from the pet store
|
||||
*/
|
||||
|
||||
public class Order {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
|
||||
@JsonProperty("petId")
|
||||
private Long petId = null;
|
||||
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity = null;
|
||||
|
||||
@JsonProperty("shipDate")
|
||||
private OffsetDateTime shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
*/
|
||||
public enum StatusEnum {
|
||||
PLACED("placed"),
|
||||
|
||||
APPROVED("approved"),
|
||||
|
||||
DELIVERED("delivered");
|
||||
|
||||
private String value;
|
||||
|
||||
StatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static StatusEnum fromValue(String text) {
|
||||
for (StatusEnum b : StatusEnum.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty("status")
|
||||
private StatusEnum status = null;
|
||||
|
||||
@JsonProperty("complete")
|
||||
private Boolean complete = false;
|
||||
|
||||
public Order id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Order petId(Long petId) {
|
||||
this.petId = petId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get petId
|
||||
* @return petId
|
||||
**/
|
||||
public Long getPetId() {
|
||||
return petId;
|
||||
}
|
||||
|
||||
public void setPetId(Long petId) {
|
||||
this.petId = petId;
|
||||
}
|
||||
|
||||
public Order quantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get quantity
|
||||
* @return quantity
|
||||
**/
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public Order shipDate(OffsetDateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shipDate
|
||||
* @return shipDate
|
||||
**/
|
||||
public OffsetDateTime getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
|
||||
public void setShipDate(OffsetDateTime shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
public Order status(StatusEnum status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* @return status
|
||||
**/
|
||||
public StatusEnum getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(StatusEnum status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Order complete(Boolean complete) {
|
||||
this.complete = complete;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get complete
|
||||
* @return complete
|
||||
**/
|
||||
public Boolean getComplete() {
|
||||
return complete;
|
||||
}
|
||||
|
||||
public void setComplete(Boolean complete) {
|
||||
this.complete = complete;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Order order = (Order) o;
|
||||
return Objects.equals(this.id, order.id) &&
|
||||
Objects.equals(this.petId, order.petId) &&
|
||||
Objects.equals(this.quantity, order.quantity) &&
|
||||
Objects.equals(this.shipDate, order.shipDate) &&
|
||||
Objects.equals(this.status, order.status) &&
|
||||
Objects.equals(this.complete, order.complete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, petId, quantity, shipDate, status, complete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Order {\n");
|
||||
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" petId: ").append(toIndentedString(petId)).append("\n");
|
||||
sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n");
|
||||
sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n");
|
||||
sb.append(" status: ").append(toIndentedString(status)).append("\n");
|
||||
sb.append(" complete: ").append(toIndentedString(complete)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import apimodels.Category;
|
||||
import apimodels.Tag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* A pet for sale in the pet store
|
||||
*/
|
||||
|
||||
public class Pet {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
|
||||
@JsonProperty("category")
|
||||
private Category category = null;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
|
||||
@JsonProperty("photoUrls")
|
||||
private List<String> photoUrls = new ArrayList<String>();
|
||||
|
||||
@JsonProperty("tags")
|
||||
private List<Tag> tags = null;
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
public enum StatusEnum {
|
||||
AVAILABLE("available"),
|
||||
|
||||
PENDING("pending"),
|
||||
|
||||
SOLD("sold");
|
||||
|
||||
private String value;
|
||||
|
||||
StatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static StatusEnum fromValue(String text) {
|
||||
for (StatusEnum b : StatusEnum.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty("status")
|
||||
private StatusEnum status = null;
|
||||
|
||||
public Pet id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Pet category(Category category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get category
|
||||
* @return category
|
||||
**/
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Pet name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return name
|
||||
**/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Pet photoUrls(List<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pet addPhotoUrlsItem(String photoUrlsItem) {
|
||||
this.photoUrls.add(photoUrlsItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get photoUrls
|
||||
* @return photoUrls
|
||||
**/
|
||||
@NotNull
|
||||
public List<String> getPhotoUrls() {
|
||||
return photoUrls;
|
||||
}
|
||||
|
||||
public void setPhotoUrls(List<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
}
|
||||
|
||||
public Pet tags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pet addTagsItem(Tag tagsItem) {
|
||||
if (this.tags == null) {
|
||||
this.tags = new ArrayList<Tag>();
|
||||
}
|
||||
this.tags.add(tagsItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tags
|
||||
* @return tags
|
||||
**/
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public Pet status(StatusEnum status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* @return status
|
||||
**/
|
||||
public StatusEnum getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(StatusEnum status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Pet pet = (Pet) o;
|
||||
return Objects.equals(this.id, pet.id) &&
|
||||
Objects.equals(this.category, pet.category) &&
|
||||
Objects.equals(this.name, pet.name) &&
|
||||
Objects.equals(this.photoUrls, pet.photoUrls) &&
|
||||
Objects.equals(this.tags, pet.tags) &&
|
||||
Objects.equals(this.status, pet.status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, category, name, photoUrls, tags, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Pet {\n");
|
||||
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" category: ").append(toIndentedString(category)).append("\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n");
|
||||
sb.append(" tags: ").append(toIndentedString(tags)).append("\n");
|
||||
sb.append(" status: ").append(toIndentedString(status)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* A tag for a pet
|
||||
*/
|
||||
|
||||
public class Tag {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
|
||||
public Tag id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Tag name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return name
|
||||
**/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Tag tag = (Tag) o;
|
||||
return Objects.equals(this.id, tag.id) &&
|
||||
Objects.equals(this.name, tag.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Tag {\n");
|
||||
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import javax.validation.constraints.*;
|
||||
/**
|
||||
* A User who is purchasing from the pet store
|
||||
*/
|
||||
|
||||
public class User {
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
|
||||
@JsonProperty("username")
|
||||
private String username = null;
|
||||
|
||||
@JsonProperty("firstName")
|
||||
private String firstName = null;
|
||||
|
||||
@JsonProperty("lastName")
|
||||
private String lastName = null;
|
||||
|
||||
@JsonProperty("email")
|
||||
private String email = null;
|
||||
|
||||
@JsonProperty("password")
|
||||
private String password = null;
|
||||
|
||||
@JsonProperty("phone")
|
||||
private String phone = null;
|
||||
|
||||
@JsonProperty("userStatus")
|
||||
private Integer userStatus = null;
|
||||
|
||||
public User id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User username(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get username
|
||||
* @return username
|
||||
**/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public User firstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get firstName
|
||||
* @return firstName
|
||||
**/
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public User lastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lastName
|
||||
* @return lastName
|
||||
**/
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public User email(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email
|
||||
* @return email
|
||||
**/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public User password(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get password
|
||||
* @return password
|
||||
**/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public User phone(String phone) {
|
||||
this.phone = phone;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get phone
|
||||
* @return phone
|
||||
**/
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public User userStatus(Integer userStatus) {
|
||||
this.userStatus = userStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* User Status
|
||||
* @return userStatus
|
||||
**/
|
||||
public Integer getUserStatus() {
|
||||
return userStatus;
|
||||
}
|
||||
|
||||
public void setUserStatus(Integer userStatus) {
|
||||
this.userStatus = userStatus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
User user = (User) o;
|
||||
return Objects.equals(this.id, user.id) &&
|
||||
Objects.equals(this.username, user.username) &&
|
||||
Objects.equals(this.firstName, user.firstName) &&
|
||||
Objects.equals(this.lastName, user.lastName) &&
|
||||
Objects.equals(this.email, user.email) &&
|
||||
Objects.equals(this.password, user.password) &&
|
||||
Objects.equals(this.phone, user.phone) &&
|
||||
Objects.equals(this.userStatus, user.userStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class User {\n");
|
||||
|
||||
sb.append(" id: ").append(toIndentedString(id)).append("\n");
|
||||
sb.append(" username: ").append(toIndentedString(username)).append("\n");
|
||||
sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n");
|
||||
sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n");
|
||||
sb.append(" email: ").append(toIndentedString(email)).append("\n");
|
||||
sb.append(" password: ").append(toIndentedString(password)).append("\n");
|
||||
sb.append(" phone: ").append(toIndentedString(phone)).append("\n");
|
||||
sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package controllers;
|
||||
|
||||
import javax.inject.*;
|
||||
import play.mvc.*;
|
||||
|
||||
public class ApiDocController extends Controller {
|
||||
|
||||
@Inject
|
||||
private ApiDocController() {
|
||||
}
|
||||
|
||||
public Result api() {
|
||||
return redirect("/assets/lib/swagger-ui/index.html?/url=/assets/swagger.json");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.InputStream;
|
||||
import apimodels.ModelApiResponse;
|
||||
import apimodels.Pet;
|
||||
|
||||
import play.mvc.Controller;
|
||||
import play.mvc.Result;
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import swagger.SwaggerUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import swagger.SwaggerUtils.ApiAction;
|
||||
|
||||
|
||||
public class PetApiController extends Controller {
|
||||
|
||||
private final PetApiControllerImp imp;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private PetApiController(PetApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiAction
|
||||
public Result addPet() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
|
||||
imp.addPet(body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result deletePet(Long petId) {
|
||||
String valueapiKey = request().getHeader("api_key");
|
||||
String apiKey;
|
||||
if (valueapiKey != null) {
|
||||
apiKey = (String)valueapiKey;
|
||||
|
||||
} else {
|
||||
apiKey = null;
|
||||
}
|
||||
imp.deletePet(petId, apiKey);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result findPetsByStatus() {
|
||||
List<String> statusList = SwaggerUtils.parametersToList("csv", request().queryString().get("status"));
|
||||
List<String> status = new ArrayList<String>();
|
||||
for (String curParam : statusList) {
|
||||
//noinspection UseBulkOperation
|
||||
status.add(curParam);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByStatus(status);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result findPetsByTags() {
|
||||
List<String> tagsList = SwaggerUtils.parametersToList("csv", request().queryString().get("tags"));
|
||||
List<String> tags = new ArrayList<String>();
|
||||
for (String curParam : tagsList) {
|
||||
//noinspection UseBulkOperation
|
||||
tags.add(curParam);
|
||||
}
|
||||
List<Pet> obj = imp.findPetsByTags(tags);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result getPetById(Long petId) {
|
||||
Pet obj = imp.getPetById(petId);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result updatePet() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
|
||||
imp.updatePet(body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result updatePetWithForm(Long petId) {
|
||||
String valuename = (request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
|
||||
String name;
|
||||
if (valuename != null) {
|
||||
name = (String)valuename;
|
||||
|
||||
} else {
|
||||
name = null;
|
||||
}
|
||||
String valuestatus = (request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
|
||||
String status;
|
||||
if (valuestatus != null) {
|
||||
status = (String)valuestatus;
|
||||
|
||||
} else {
|
||||
status = null;
|
||||
}
|
||||
imp.updatePetWithForm(petId, name, status);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result uploadFile(Long petId) {
|
||||
String valueadditionalMetadata = (request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
|
||||
String additionalMetadata;
|
||||
if (valueadditionalMetadata != null) {
|
||||
additionalMetadata = (String)valueadditionalMetadata;
|
||||
|
||||
} else {
|
||||
additionalMetadata = null;
|
||||
}
|
||||
Http.MultipartFormData.FilePart file = request().body().asMultipartFormData().getFile("file");
|
||||
ModelApiResponse obj = imp.uploadFile(petId, additionalMetadata, file);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.InputStream;
|
||||
import apimodels.ModelApiResponse;
|
||||
import apimodels.Pet;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileInputStream;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public class PetApiControllerImp implements PetApiControllerImpInterface {
|
||||
@Override
|
||||
public void addPet(Pet body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePet(Long petId, String apiKey) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pet> findPetsByStatus( @NotNull List<String> status) {
|
||||
//Do your magic!!!
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pet> findPetsByTags( @NotNull List<String> tags) {
|
||||
//Do your magic!!!
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pet getPetById(Long petId) {
|
||||
//Do your magic!!!
|
||||
return new Pet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePet(Pet body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePetWithForm(Long petId, String name, String status) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelApiResponse uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) {
|
||||
//Do your magic!!!
|
||||
return new ModelApiResponse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.InputStream;
|
||||
import apimodels.ModelApiResponse;
|
||||
import apimodels.Pet;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public interface PetApiControllerImpInterface {
|
||||
void addPet(Pet body) ;
|
||||
|
||||
void deletePet(Long petId, String apiKey) ;
|
||||
|
||||
List<Pet> findPetsByStatus( @NotNull List<String> status) ;
|
||||
|
||||
List<Pet> findPetsByTags( @NotNull List<String> tags) ;
|
||||
|
||||
Pet getPetById(Long petId) ;
|
||||
|
||||
void updatePet(Pet body) ;
|
||||
|
||||
void updatePetWithForm(Long petId, String name, String status) ;
|
||||
|
||||
ModelApiResponse uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.Map;
|
||||
import apimodels.Order;
|
||||
|
||||
import play.mvc.Controller;
|
||||
import play.mvc.Result;
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import swagger.SwaggerUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import swagger.SwaggerUtils.ApiAction;
|
||||
|
||||
|
||||
public class StoreApiController extends Controller {
|
||||
|
||||
private final StoreApiControllerImp imp;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private StoreApiController(StoreApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiAction
|
||||
public Result deleteOrder(String orderId) {
|
||||
imp.deleteOrder(orderId);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result getInventory() {
|
||||
Map<String, Integer> obj = imp.getInventory();
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result getOrderById( @Min(1) @Max(5)Long orderId) {
|
||||
Order obj = imp.getOrderById(orderId);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result placeOrder() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Order body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), Order.class);
|
||||
|
||||
Order obj = imp.placeOrder(body);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.Map;
|
||||
import apimodels.Order;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileInputStream;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public class StoreApiControllerImp implements StoreApiControllerImpInterface {
|
||||
@Override
|
||||
public void deleteOrder(String orderId) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getInventory() {
|
||||
//Do your magic!!!
|
||||
return new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getOrderById( @Min(1) @Max(5)Long orderId) {
|
||||
//Do your magic!!!
|
||||
return new Order();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order placeOrder(Order body) {
|
||||
//Do your magic!!!
|
||||
return new Order();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.Map;
|
||||
import apimodels.Order;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public interface StoreApiControllerImpInterface {
|
||||
void deleteOrder(String orderId) ;
|
||||
|
||||
Map<String, Integer> getInventory() ;
|
||||
|
||||
Order getOrderById( @Min(1) @Max(5)Long orderId) ;
|
||||
|
||||
Order placeOrder(Order body) ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.List;
|
||||
import apimodels.User;
|
||||
|
||||
import play.mvc.Controller;
|
||||
import play.mvc.Result;
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import swagger.SwaggerUtils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import swagger.SwaggerUtils.ApiAction;
|
||||
|
||||
|
||||
public class UserApiController extends Controller {
|
||||
|
||||
private final UserApiControllerImp imp;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private UserApiController(UserApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiAction
|
||||
public Result createUser() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
|
||||
imp.createUser(body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result createUsersWithArrayInput() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
List<User> body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), new TypeReference<List<List<User>>>(){});
|
||||
|
||||
imp.createUsersWithArrayInput(body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result createUsersWithListInput() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
List<User> body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), new TypeReference<List<List<User>>>(){});
|
||||
|
||||
imp.createUsersWithListInput(body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result deleteUser(String username) {
|
||||
imp.deleteUser(username);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result getUserByName(String username) {
|
||||
User obj = imp.getUserByName(username);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result loginUser() {
|
||||
String valueusername = request().getQueryString("username");
|
||||
String username;
|
||||
|
||||
username = (String)valueusername;
|
||||
|
||||
String valuepassword = request().getQueryString("password");
|
||||
String password;
|
||||
|
||||
password = (String)valuepassword;
|
||||
|
||||
String obj = imp.loginUser(username, password);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result logoutUser() {
|
||||
imp.logoutUser();
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
|
||||
@ApiAction
|
||||
public Result updateUser(String username) throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
|
||||
imp.updateUser(username, body);
|
||||
|
||||
return ok();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.List;
|
||||
import apimodels.User;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileInputStream;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public class UserApiControllerImp implements UserApiControllerImpInterface {
|
||||
@Override
|
||||
public void createUser(User body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUsersWithArrayInput(List<User> body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUsersWithListInput(List<User> body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(String username) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByName(String username) {
|
||||
//Do your magic!!!
|
||||
return new User();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loginUser( @NotNull String username, @NotNull String password) {
|
||||
//Do your magic!!!
|
||||
return new String();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logoutUser() {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(String username, User body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.List;
|
||||
import apimodels.User;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public interface UserApiControllerImpInterface {
|
||||
void createUser(User body) ;
|
||||
|
||||
void createUsersWithArrayInput(List<User> body) ;
|
||||
|
||||
void createUsersWithListInput(List<User> body) ;
|
||||
|
||||
void deleteUser(String username) ;
|
||||
|
||||
User getUserByName(String username) ;
|
||||
|
||||
String loginUser( @NotNull String username, @NotNull String password) ;
|
||||
|
||||
void logoutUser() ;
|
||||
|
||||
void updateUser(String username, User body) ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package swagger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import play.mvc.Action;
|
||||
import play.mvc.Http;
|
||||
import play.mvc.Result;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
public class ApiCall extends Action<SwaggerUtils.ApiAction> {
|
||||
|
||||
@Inject
|
||||
private ApiCall() {}
|
||||
|
||||
public CompletionStage<Result> call(Http.Context ctx) {
|
||||
try {
|
||||
//TODO: Do stuff you want to handle with each API call (metrics, logging, etc..)
|
||||
return delegate.call(ctx);
|
||||
} catch (Throwable t) {
|
||||
//TODO: log the error in your metric
|
||||
|
||||
//We rethrow this error so it will be caught in the ErrorHandler
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package swagger;
|
||||
|
||||
import play.mvc.With;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class SwaggerUtils {
|
||||
|
||||
@With(ApiCall.class)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ApiAction {
|
||||
}
|
||||
|
||||
public static List<String> parametersToList(String collectionFormat, String[] values){
|
||||
List<String> params = new ArrayList<>();
|
||||
|
||||
if (values == null) {
|
||||
return params;
|
||||
}
|
||||
|
||||
if (values.length >= 1 && collectionFormat.equals("multi")) {
|
||||
params.addAll(Arrays.asList(values));
|
||||
} else {
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
switch(collectionFormat) {
|
||||
case "csv": {
|
||||
delimiter = ",";
|
||||
break;
|
||||
}
|
||||
case "ssv": {
|
||||
delimiter = " ";
|
||||
break;
|
||||
}
|
||||
case "tsv": {
|
||||
delimiter = "\t";
|
||||
break;
|
||||
}
|
||||
case "pipes": {
|
||||
delimiter = "|";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
params = Arrays.asList(values[0].split(delimiter));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public static String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDatetime((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (Object o : (Collection)param) {
|
||||
if (b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDatetime(Date date) {
|
||||
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user