mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
[Java][Play] update CI (travis) to cover Play framework petstore server (#5130)
* add test to cover play framework * add sample for java play framework * add script to test only if running sdk8 for play petstore
This commit is contained in:
parent
26ae4c3a99
commit
6708cc50eb
12
pom.xml
12
pom.xml
@ -772,6 +772,7 @@
|
||||
<module>samples/client/petstore/jaxrs-cxf-client</module>
|
||||
<module>samples/client/petstore/javascript</module>
|
||||
<module>samples/client/petstore/python</module>
|
||||
<module>samples/client/petstore/spring-cloud</module>
|
||||
<module>samples/client/petstore/scala</module>
|
||||
<module>samples/client/petstore/typescript-fetch/builds/default</module>
|
||||
<module>samples/client/petstore/typescript-fetch/builds/es6-target</module>
|
||||
@ -784,20 +785,19 @@
|
||||
<!--module>samples/client/petstore/swift/SwaggerClientTests</module-->
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/java-inflector</module>
|
||||
<module>samples/server/petstore/undertow</module>
|
||||
<module>samples/server/petstore/java-play-framework</module>
|
||||
<module>samples/server/petstore/jaxrs/jersey1</module>
|
||||
<module>samples/server/petstore/jaxrs/jersey2</module>
|
||||
<module>samples/server/petstore/jaxrs-resteasy/default</module>
|
||||
<module>samples/server/petstore/jaxrs-resteasy/joda</module>
|
||||
<module>samples/server/petstore/scalatra</module>
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
<module>samples/client/petstore/spring-cloud</module>
|
||||
<module>samples/server/petstore/springboot</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf-annotated-base-path</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf-cdi</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf-non-spring-app</module>
|
||||
|
||||
<module>samples/server/petstore/scalatra</module>
|
||||
<module>samples/server/petstore/spring-mvc</module>
|
||||
<module>samples/server/petstore/springboot</module>
|
||||
<module>samples/server/petstore/undertow</module>
|
||||
<!--<module>samples/server/petstore/java-msf4j</module> note: JDK8 only -->
|
||||
</modules>
|
||||
</profile>
|
||||
|
@ -0,0 +1,23 @@
|
||||
# Swagger Codegen Ignore
|
||||
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
8
samples/server/petstore/java-play-framework/LICENSE
Normal file
8
samples/server/petstore/java-play-framework/LICENSE
Normal file
@ -0,0 +1,8 @@
|
||||
This software is licensed under the Apache 2 license, quoted below.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with
|
||||
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License.
|
4
samples/server/petstore/java-play-framework/README
Normal file
4
samples/server/petstore/java-play-framework/README
Normal file
@ -0,0 +1,4 @@
|
||||
This is your new Play application
|
||||
=================================
|
||||
|
||||
This file will be packaged with your application when using `activator dist`.
|
@ -0,0 +1,96 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.validation.constraints.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
/**
|
||||
* Category
|
||||
*/
|
||||
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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,222 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.constraints.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
/**
|
||||
* Order
|
||||
*/
|
||||
|
||||
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 = null;
|
||||
|
||||
public Order id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
* @return id
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "Order 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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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,237 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import apimodels.Category;
|
||||
import apimodels.Tag;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
/**
|
||||
* Pet
|
||||
*/
|
||||
|
||||
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 = new ArrayList<Tag>();
|
||||
|
||||
/**
|
||||
* 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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(example = "doggie", required = true, value = "")
|
||||
@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
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
@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) {
|
||||
this.tags.add(tagsItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tags
|
||||
* @return tags
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "pet status in the store")
|
||||
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,96 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.validation.constraints.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
/**
|
||||
* Tag
|
||||
*/
|
||||
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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,234 @@
|
||||
package apimodels;
|
||||
|
||||
import java.util.Objects;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.validation.constraints.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
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
|
||||
**/
|
||||
@ApiModelProperty(value = "User Status")
|
||||
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(String.format("/assets/lib/swagger-ui/index.html?/url=%s/api-docs", ""));
|
||||
}
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.File;
|
||||
import apimodels.Pet;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
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 javafx.util.Pair;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
@Api(value = "Pet", description = "the Pet API")
|
||||
public class PetApiController extends Controller {
|
||||
|
||||
private PetApiControllerImp imp;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private PetApiController(PetApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Add a new pet to the store", notes = "", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 405, message = "Invalid input") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "Pet object that needs to be added to the store", dataType = "apimodels.Pet", paramType = "body")
|
||||
})
|
||||
public Result addPet() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.addPet(body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Deletes a pet", notes = "", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 400, message = "Invalid pet value") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "api_key", value = "", dataType = "String", paramType = "header")
|
||||
})
|
||||
public Result deletePet(@ApiParam(value = "Pet id to delete", required = true ) Long petId) {
|
||||
String valueapiKey = request().getHeader("api_key");
|
||||
String apiKey;
|
||||
if (valueapiKey != null) {
|
||||
apiKey = (String)valueapiKey;
|
||||
|
||||
} else {
|
||||
apiKey = "";
|
||||
}
|
||||
imp.deletePet(petId, apiKey);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
|
||||
@ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "status", value = "Status values that need to be considered for filter", defaultValue = "available", dataType = "List<String>", paramType = "query")
|
||||
})
|
||||
public Result findPetsByStatus() {
|
||||
//TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130
|
||||
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
|
||||
//WIP when both bugs will be fixed
|
||||
//List<Pair> statusPair = SwaggerUtils.parameterToPairs("multi", "status", request().getQueryString("status"));
|
||||
List<String> status = new ArrayList<String>();
|
||||
//for (Pair pair : statusPair) {
|
||||
// status.add(pair.getValue());
|
||||
//}
|
||||
List<Pet> obj = imp.findPetsByStatus(status);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
|
||||
@ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tags", value = "Tags to filter by", dataType = "List<String>", paramType = "query")
|
||||
})
|
||||
public Result findPetsByTags() {
|
||||
//TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130
|
||||
//TODO: Tt seems it is not detected that it's a list based on the collectionFormat field?
|
||||
//WIP when both bugs will be fixed
|
||||
//List<Pair> tagsPair = SwaggerUtils.parameterToPairs("multi", "tags", request().getQueryString("tags"));
|
||||
List<String> tags = new ArrayList<String>();
|
||||
//for (Pair pair : tagsPair) {
|
||||
// tags.add(pair.getValue());
|
||||
//}
|
||||
List<Pet> obj = imp.findPetsByTags(tags);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class, authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
}),
|
||||
@Authorization(value = "api_key")
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class),
|
||||
@ApiResponse(code = 404, message = "Pet not found", response = Pet.class) })
|
||||
@ApiImplicitParams({
|
||||
|
||||
})
|
||||
public Result getPetById(@ApiParam(value = "ID of pet that needs to be fetched", required = true ) Long petId) {
|
||||
Pet obj = imp.getPetById(petId);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Update an existing pet", notes = "", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Pet not found"),
|
||||
@ApiResponse(code = 405, message = "Validation exception") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "Pet object that needs to be added to the store", dataType = "apimodels.Pet", paramType = "body")
|
||||
})
|
||||
public Result updatePet() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Pet body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Pet.class);
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.updatePet(body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Updates a pet in the store with form data", notes = "", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 405, message = "Invalid input") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "Updated name of the pet", dataType = "String", paramType = "form"),
|
||||
@ApiImplicitParam(name = "status", value = "Updated status of the pet", dataType = "String", paramType = "form")
|
||||
})
|
||||
public Result updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true ) String petId) {
|
||||
String valuename = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0];
|
||||
String name;
|
||||
if (valuename != null) {
|
||||
name = (String)valuename;
|
||||
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
String valuestatus = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("status"))[0];
|
||||
String status;
|
||||
if (valuestatus != null) {
|
||||
status = (String)valuestatus;
|
||||
|
||||
} else {
|
||||
status = "";
|
||||
}
|
||||
imp.updatePetWithForm(petId, name, status);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "uploads an image", notes = "", authorizations = {
|
||||
@Authorization(value = "petstore_auth", scopes = {
|
||||
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 0, message = "successful operation") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "additionalMetadata", value = "Additional data to pass to server", dataType = "String", paramType = "form"),
|
||||
@ApiImplicitParam(name = "file", value = "file to upload", dataType = "apimodels.File", paramType = "form")
|
||||
})
|
||||
public Result uploadFile(@ApiParam(value = "ID of pet to update", required = true ) Long petId) {
|
||||
String valueadditionalMetadata = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0];
|
||||
String additionalMetadata;
|
||||
if (valueadditionalMetadata != null) {
|
||||
additionalMetadata = (String)valueadditionalMetadata;
|
||||
|
||||
} else {
|
||||
additionalMetadata = "";
|
||||
}
|
||||
Http.MultipartFormData.FilePart file = request().body().asMultipartFormData().getFile("file");
|
||||
imp.uploadFile(petId, additionalMetadata, file);
|
||||
|
||||
return ok();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.File;
|
||||
import apimodels.Pet;
|
||||
|
||||
import play.mvc.Http;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
public class PetApiControllerImp {
|
||||
void addPet(Pet body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void deletePet( Long petId, String apiKey) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
List<Pet> findPetsByStatus( List<String> status) {
|
||||
//Do your magic!!!
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
List<Pet> findPetsByTags( List<String> tags) {
|
||||
//Do your magic!!!
|
||||
return new ArrayList<Pet>();
|
||||
}
|
||||
|
||||
Pet getPetById( Long petId) {
|
||||
//Do your magic!!!
|
||||
return new Pet();
|
||||
}
|
||||
|
||||
void updatePet(Pet body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void updatePetWithForm( String petId, String name, String status) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void uploadFile( Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package controllers;
|
||||
|
||||
import java.io.File;
|
||||
import apimodels.Pet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import play.mvc.Http;
|
||||
|
||||
public interface PetApiControllerImpInterface {
|
||||
void addPet(Pet body);
|
||||
|
||||
void deletePet( Long petId, String apiKey);
|
||||
|
||||
List<Pet> findPetsByStatus( List<String> status);
|
||||
|
||||
List<Pet> findPetsByTags( List<String> tags);
|
||||
|
||||
Pet getPetById( Long petId);
|
||||
|
||||
void updatePet(Pet body);
|
||||
|
||||
void updatePetWithForm( String petId, String name, String status);
|
||||
|
||||
void uploadFile( Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file);
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.Map;
|
||||
import apimodels.Order;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
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 javafx.util.Pair;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
@Api(value = "Store", description = "the Store API")
|
||||
public class StoreApiController extends Controller {
|
||||
|
||||
private StoreApiControllerImp imp;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private StoreApiController(StoreApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied"),
|
||||
@ApiResponse(code = 404, message = "Order not found") })
|
||||
@ApiImplicitParams({
|
||||
|
||||
})
|
||||
public Result deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true ) String orderId) {
|
||||
imp.deleteOrder(orderId);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = {
|
||||
@Authorization(value = "api_key")
|
||||
}, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Integer.class) })
|
||||
public Result getInventory() {
|
||||
Map<String, Integer> obj = imp.getInventory();
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
|
||||
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class),
|
||||
@ApiResponse(code = 404, message = "Order not found", response = Order.class) })
|
||||
@ApiImplicitParams({
|
||||
|
||||
})
|
||||
public Result getOrderById(@ApiParam(value = "ID of pet that needs to be fetched", required = true ) String orderId) {
|
||||
Order obj = imp.getOrderById(orderId);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
|
||||
@ApiResponse(code = 400, message = "Invalid Order", response = Order.class) })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "order placed for purchasing the pet", dataType = "apimodels.Order", paramType = "body")
|
||||
})
|
||||
public Result placeOrder() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
Order body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), Order.class);
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
Order obj = imp.placeOrder(body);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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 class StoreApiControllerImp {
|
||||
void deleteOrder( String orderId) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
Map<String, Integer> getInventory() {
|
||||
//Do your magic!!!
|
||||
return new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
Order getOrderById( String orderId) {
|
||||
//Do your magic!!!
|
||||
return new Order();
|
||||
}
|
||||
|
||||
Order placeOrder(Order body) {
|
||||
//Do your magic!!!
|
||||
return new Order();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.Map;
|
||||
import apimodels.Order;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface StoreApiControllerImpInterface {
|
||||
void deleteOrder( String orderId);
|
||||
|
||||
Map<String, Integer> getInventory();
|
||||
|
||||
Order getOrderById( String orderId);
|
||||
|
||||
Order placeOrder(Order body);
|
||||
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.List;
|
||||
import apimodels.User;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
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 javafx.util.Pair;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
@Api(value = "User", description = "the User API")
|
||||
public class UserApiController extends Controller {
|
||||
|
||||
private UserApiControllerImp imp;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@Inject
|
||||
private UserApiController(UserApiControllerImp imp) {
|
||||
this.imp = imp;
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 0, message = "successful operation") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "Created user object", dataType = "apimodels.User", paramType = "body")
|
||||
})
|
||||
public Result createUser() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.createUser(body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Creates list of users with given input array", notes = "", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 0, message = "successful operation") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "List of user object", dataType = "List<User>", paramType = "body")
|
||||
})
|
||||
public Result createUsersWithArrayInput() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
List<User> body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), new TypeReference<List<List<User>>>(){});
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.createUsersWithArrayInput(body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Creates list of users with given input array", notes = "", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 0, message = "successful operation") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "List of user object", dataType = "List<User>", paramType = "body")
|
||||
})
|
||||
public Result createUsersWithListInput() throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
List<User> body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), new TypeReference<List<List<User>>>(){});
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.createUsersWithListInput(body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 400, message = "Invalid username supplied"),
|
||||
@ApiResponse(code = 404, message = "User not found") })
|
||||
@ApiImplicitParams({
|
||||
|
||||
})
|
||||
public Result deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true ) String username) {
|
||||
imp.deleteUser(username);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = User.class),
|
||||
@ApiResponse(code = 400, message = "Invalid username supplied", response = User.class),
|
||||
@ApiResponse(code = 404, message = "User not found", response = User.class) })
|
||||
@ApiImplicitParams({
|
||||
|
||||
})
|
||||
public Result getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ", required = true ) String username) {
|
||||
User obj = imp.getUserByName(username);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "successful operation", response = String.class),
|
||||
@ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "username", value = "The user name for login", dataType = "String", paramType = "query"),
|
||||
@ApiImplicitParam(name = "password", value = "The password for login in clear text", dataType = "String", paramType = "query")
|
||||
})
|
||||
public Result loginUser() {
|
||||
String valueusername = request().getQueryString("username");
|
||||
String username;
|
||||
if (valueusername != null) {
|
||||
username = (String)valueusername;
|
||||
|
||||
} else {
|
||||
username = "";
|
||||
}
|
||||
String valuepassword = request().getQueryString("password");
|
||||
String password;
|
||||
if (valuepassword != null) {
|
||||
password = (String)valuepassword;
|
||||
|
||||
} else {
|
||||
password = "";
|
||||
}
|
||||
String obj = imp.loginUser(username, password);
|
||||
JsonNode result = mapper.valueToTree(obj);
|
||||
return ok(result);
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Logs out current logged in user session", notes = "", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 0, message = "successful operation") })
|
||||
public Result logoutUser() {
|
||||
imp.logoutUser();
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", tags={ })
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 400, message = "Invalid user supplied"),
|
||||
@ApiResponse(code = 404, message = "User not found") })
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "body", value = "Updated user object", dataType = "apimodels.User", paramType = "body")
|
||||
})
|
||||
public Result updateUser(@ApiParam(value = "name that need to be deleted", required = true ) String username) throws IOException {
|
||||
JsonNode nodebody = request().body().asJson();
|
||||
User body;
|
||||
if (nodebody != null) {
|
||||
body = mapper.readValue(nodebody.toString(), User.class);
|
||||
|
||||
} else {
|
||||
body = null;
|
||||
}
|
||||
imp.updateUser(username, body);
|
||||
|
||||
return ok();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
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 class UserApiControllerImp {
|
||||
void createUser(User body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void createUsersWithArrayInput(List<User> body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void createUsersWithListInput(List<User> body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void deleteUser( String username) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
User getUserByName( String username) {
|
||||
//Do your magic!!!
|
||||
return new User();
|
||||
}
|
||||
|
||||
String loginUser( String username, String password) {
|
||||
//Do your magic!!!
|
||||
return new String();
|
||||
}
|
||||
|
||||
void logoutUser() {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
void updateUser( String username, User body) {
|
||||
//Do your magic!!!
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package controllers;
|
||||
|
||||
import java.util.List;
|
||||
import apimodels.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
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( String username, String password);
|
||||
|
||||
void logoutUser();
|
||||
|
||||
void updateUser( String username, User body);
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package swagger;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class SwaggerUtils {
|
||||
|
||||
/**
|
||||
* Format to {@code Pair} objects.
|
||||
*
|
||||
* @param collectionFormat collection format (e.g. csv, tsv)
|
||||
* @param name Name
|
||||
* @param value Value
|
||||
* @return A list of Pair objects
|
||||
*/
|
||||
public static List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*
|
||||
* @param param Parameter
|
||||
* @return String representation of the parameter
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given Date object into string (Datetime format).
|
||||
*
|
||||
* @param date Date object
|
||||
* @return Formatted datetime in string representation
|
||||
*/
|
||||
public static String formatDatetime(Date date) {
|
||||
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date);
|
||||
}
|
||||
}
|
16
samples/server/petstore/java-play-framework/build.sbt
Normal file
16
samples/server/petstore/java-play-framework/build.sbt
Normal file
@ -0,0 +1,16 @@
|
||||
name := """swagger-java-playframework"""
|
||||
|
||||
version := "1.0-SNAPSHOT"
|
||||
|
||||
lazy val root = (project in file(".")).enablePlugins(PlayJava)
|
||||
|
||||
scalaVersion := "2.11.7"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
javaJdbc,
|
||||
cache,
|
||||
javaWs,
|
||||
"io.swagger" %% "swagger-play2" % "1.5.3",
|
||||
"org.webjars" % "swagger-ui" % "2.2.8",
|
||||
"javax.validation" % "validation-api" % "1.1.0.Final"
|
||||
)
|
@ -0,0 +1,361 @@
|
||||
springfox.documentation.swagger.v2.path=/api-docs
|
||||
server.contextPath=/
|
||||
server.port=9000
|
||||
spring.jackson.date-format=io.swagger.RFC3339DateFormat
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
|
||||
# This is the main configuration file for the application.
|
||||
# https://www.playframework.com/documentation/latest/ConfigFile
|
||||
# ~~~~~
|
||||
# Play uses HOCON as its configuration file format. HOCON has a number
|
||||
# of advantages over other config formats, but there are two things that
|
||||
# can be used when modifying settings.
|
||||
#
|
||||
# You can include other configuration files in this main application.conf file:
|
||||
#include "extra-config.conf"
|
||||
#
|
||||
# You can declare variables and substitute for them:
|
||||
#mykey = ${some.value}
|
||||
#
|
||||
# And if an environment variable exists when there is no other subsitution, then
|
||||
# HOCON will fall back to substituting environment variable:
|
||||
#mykey = ${JAVA_HOME}
|
||||
|
||||
## Akka
|
||||
# https://www.playframework.com/documentation/latest/ScalaAkka#Configuration
|
||||
# https://www.playframework.com/documentation/latest/JavaAkka#Configuration
|
||||
# ~~~~~
|
||||
# Play uses Akka internally and exposes Akka Streams and actors in Websockets and
|
||||
# other streaming HTTP responses.
|
||||
akka {
|
||||
# "akka.log-config-on-start" is extraordinarly useful because it log the complete
|
||||
# configuration at INFO level, including defaults and overrides, so it s worth
|
||||
# putting at the very top.
|
||||
#
|
||||
# Put the following in your conf/logback.xml file:
|
||||
#
|
||||
# <logger name="akka.actor" level="INFO" />
|
||||
#
|
||||
# And then uncomment this line to debug the configuration.
|
||||
#
|
||||
#log-config-on-start = true
|
||||
}
|
||||
|
||||
api.version="1.0"
|
||||
|
||||
## Secret key
|
||||
# http://www.playframework.com/documentation/latest/ApplicationSecret
|
||||
# ~~~~~
|
||||
# The secret key is used to sign Play's session cookie.
|
||||
# This must be changed for production, but we don't recommend you change it in this file.
|
||||
play.crypto.secret = "changeme"
|
||||
|
||||
## Modules
|
||||
# https://www.playframework.com/documentation/latest/Modules
|
||||
# ~~~~~
|
||||
# Control which modules are loaded when Play starts. Note that modules are
|
||||
# the replacement for "GlobalSettings", which are deprecated in 2.5.x.
|
||||
# Please see https://www.playframework.com/documentation/latest/GlobalSettings
|
||||
# for more information.
|
||||
#
|
||||
# You can also extend Play functionality by using one of the publically available
|
||||
# Play modules: https://playframework.com/documentation/latest/ModuleDirectory
|
||||
play.modules {
|
||||
# By default, Play will load any class called Module that is defined
|
||||
# in the root package (the "app" directory), or you can define them
|
||||
# explicitly below.
|
||||
# If there are any built-in modules that you want to disable, you can list them here.
|
||||
enabled += "play.modules.swagger.SwaggerModule"
|
||||
|
||||
# If there are any built-in modules that you want to disable, you can list them here.
|
||||
#disabled += ""
|
||||
}
|
||||
|
||||
## IDE
|
||||
# https://www.playframework.com/documentation/latest/IDE
|
||||
# ~~~~~
|
||||
# Depending on your IDE, you can add a hyperlink for errors that will jump you
|
||||
# directly to the code location in the IDE in dev mode. The following line makes
|
||||
# use of the IntelliJ IDEA REST interface:
|
||||
#play.editor="http://localhost:63342/api/file/?file=%s&line=%s"
|
||||
|
||||
## Internationalisation
|
||||
# https://www.playframework.com/documentation/latest/JavaI18N
|
||||
# https://www.playframework.com/documentation/latest/ScalaI18N
|
||||
# ~~~~~
|
||||
# Play comes with its own i18n settings, which allow the user's preferred language
|
||||
# to map through to internal messages, or allow the language to be stored in a cookie.
|
||||
play.i18n {
|
||||
# The application languages
|
||||
langs = [ "en" ]
|
||||
|
||||
# Whether the language cookie should be secure or not
|
||||
#langCookieSecure = true
|
||||
|
||||
# Whether the HTTP only attribute of the cookie should be set to true
|
||||
#langCookieHttpOnly = true
|
||||
}
|
||||
|
||||
## Play HTTP settings
|
||||
# ~~~~~
|
||||
play.http {
|
||||
## Router
|
||||
# https://www.playframework.com/documentation/latest/JavaRouting
|
||||
# https://www.playframework.com/documentation/latest/ScalaRouting
|
||||
# ~~~~~
|
||||
# Define the Router object to use for this application.
|
||||
# This router will be looked up first when the application is starting up,
|
||||
# so make sure this is the entry point.
|
||||
# Furthermore, it's assumed your route file is named properly.
|
||||
# So for an application router like `my.application.Router`,
|
||||
# you may need to define a router file `conf/my.application.routes`.
|
||||
# Default to Routes in the root package (aka "apps" folder) (and conf/routes)
|
||||
#router = my.application.Router
|
||||
|
||||
## Action Creator
|
||||
# https://www.playframework.com/documentation/latest/JavaActionCreator
|
||||
# ~~~~~
|
||||
#actionCreator = null
|
||||
|
||||
## ErrorHandler
|
||||
# https://www.playframework.com/documentation/latest/JavaRouting
|
||||
# https://www.playframework.com/documentation/latest/ScalaRouting
|
||||
# ~~~~~
|
||||
# If null, will attempt to load a class called ErrorHandler in the root package,
|
||||
#errorHandler = null
|
||||
|
||||
## Filters
|
||||
# https://www.playframework.com/documentation/latest/ScalaHttpFilters
|
||||
# https://www.playframework.com/documentation/latest/JavaHttpFilters
|
||||
# ~~~~~
|
||||
# Filters run code on every request. They can be used to perform
|
||||
# common logic for all your actions, e.g. adding common headers.
|
||||
# Defaults to "Filters" in the root package (aka "apps" folder)
|
||||
# Alternatively you can explicitly register a class here.
|
||||
#filters = my.application.Filters
|
||||
|
||||
## Session & Flash
|
||||
# https://www.playframework.com/documentation/latest/JavaSessionFlash
|
||||
# https://www.playframework.com/documentation/latest/ScalaSessionFlash
|
||||
# ~~~~~
|
||||
session {
|
||||
# Sets the cookie to be sent only over HTTPS.
|
||||
#secure = true
|
||||
|
||||
# Sets the cookie to be accessed only by the server.
|
||||
#httpOnly = true
|
||||
|
||||
# Sets the max-age field of the cookie to 5 minutes.
|
||||
# NOTE: this only sets when the browser will discard the cookie. Play will consider any
|
||||
# cookie value with a valid signature to be a valid session forever. To implement a server side session timeout,
|
||||
# you need to put a timestamp in the session and check it at regular intervals to possibly expire it.
|
||||
#maxAge = 300
|
||||
|
||||
# Sets the domain on the session cookie.
|
||||
#domain = "example.com"
|
||||
}
|
||||
|
||||
flash {
|
||||
# Sets the cookie to be sent only over HTTPS.
|
||||
#secure = true
|
||||
|
||||
# Sets the cookie to be accessed only by the server.
|
||||
#httpOnly = true
|
||||
}
|
||||
}
|
||||
|
||||
## Netty Provider
|
||||
# https://www.playframework.com/documentation/latest/SettingsNetty
|
||||
# ~~~~~
|
||||
play.server.netty {
|
||||
# Whether the Netty wire should be logged
|
||||
#log.wire = true
|
||||
|
||||
# If you run Play on Linux, you can use Netty's native socket transport
|
||||
# for higher performance with less garbage.
|
||||
#transport = "native"
|
||||
}
|
||||
|
||||
## WS (HTTP Client)
|
||||
# https://www.playframework.com/documentation/latest/ScalaWS#Configuring-WS
|
||||
# ~~~~~
|
||||
# The HTTP client primarily used for REST APIs. The default client can be
|
||||
# configured directly, but you can also create different client instances
|
||||
# with customized settings. You must enable this by adding to build.sbt:
|
||||
#
|
||||
# libraryDependencies += ws // or javaWs if using java
|
||||
#
|
||||
play.ws {
|
||||
# Sets HTTP requests not to follow 302 requests
|
||||
#followRedirects = false
|
||||
|
||||
# Sets the maximum number of open HTTP connections for the client.
|
||||
#ahc.maxConnectionsTotal = 50
|
||||
|
||||
## WS SSL
|
||||
# https://www.playframework.com/documentation/latest/WsSSL
|
||||
# ~~~~~
|
||||
ssl {
|
||||
# Configuring HTTPS with Play WS does not require programming. You can
|
||||
# set up both trustManager and keyManager for mutual authentication, and
|
||||
# turn on JSSE debugging in development with a reload.
|
||||
#debug.handshake = true
|
||||
#trustManager = {
|
||||
# stores = [
|
||||
# { type = "JKS", path = "exampletrust.jks" }
|
||||
# ]
|
||||
#}
|
||||
}
|
||||
}
|
||||
|
||||
## Cache
|
||||
# https://www.playframework.com/documentation/latest/JavaCache
|
||||
# https://www.playframework.com/documentation/latest/ScalaCache
|
||||
# ~~~~~
|
||||
# Play comes with an integrated cache API that can reduce the operational
|
||||
# overhead of repeated requests. You must enable this by adding to build.sbt:
|
||||
#
|
||||
# libraryDependencies += cache
|
||||
#
|
||||
play.cache {
|
||||
# If you want to bind several caches, you can bind the individually
|
||||
#bindCaches = ["db-cache", "user-cache", "session-cache"]
|
||||
}
|
||||
|
||||
## Filters
|
||||
# https://www.playframework.com/documentation/latest/Filters
|
||||
# ~~~~~
|
||||
# There are a number of built-in filters that can be enabled and configured
|
||||
# to give Play greater security. You must enable this by adding to build.sbt:
|
||||
#
|
||||
# libraryDependencies += filters
|
||||
#
|
||||
play.filters {
|
||||
## CORS filter configuration
|
||||
# https://www.playframework.com/documentation/latest/CorsFilter
|
||||
# ~~~~~
|
||||
# CORS is a protocol that allows web applications to make requests from the browser
|
||||
# across different domains.
|
||||
# NOTE: You MUST apply the CORS configuration before the CSRF filter, as CSRF has
|
||||
# dependencies on CORS settings.
|
||||
cors {
|
||||
# Filter paths by a whitelist of path prefixes
|
||||
#pathPrefixes = ["/some/path", ...]
|
||||
|
||||
# The allowed origins. If null, all origins are allowed.
|
||||
#allowedOrigins = ["http://www.example.com"]
|
||||
|
||||
# The allowed HTTP methods. If null, all methods are allowed
|
||||
#allowedHttpMethods = ["GET", "POST"]
|
||||
}
|
||||
|
||||
## CSRF Filter
|
||||
# https://www.playframework.com/documentation/latest/ScalaCsrf#Applying-a-global-CSRF-filter
|
||||
# https://www.playframework.com/documentation/latest/JavaCsrf#Applying-a-global-CSRF-filter
|
||||
# ~~~~~
|
||||
# Play supports multiple methods for verifying that a request is not a CSRF request.
|
||||
# The primary mechanism is a CSRF token. This token gets placed either in the query string
|
||||
# or body of every form submitted, and also gets placed in the users session.
|
||||
# Play then verifies that both tokens are present and match.
|
||||
csrf {
|
||||
# Sets the cookie to be sent only over HTTPS
|
||||
#cookie.secure = true
|
||||
|
||||
# Defaults to CSRFErrorHandler in the root package.
|
||||
#errorHandler = MyCSRFErrorHandler
|
||||
}
|
||||
|
||||
## Security headers filter configuration
|
||||
# https://www.playframework.com/documentation/latest/SecurityHeaders
|
||||
# ~~~~~
|
||||
# Defines security headers that prevent XSS attacks.
|
||||
# If enabled, then all options are set to the below configuration by default:
|
||||
headers {
|
||||
# The X-Frame-Options header. If null, the header is not set.
|
||||
#frameOptions = "DENY"
|
||||
|
||||
# The X-XSS-Protection header. If null, the header is not set.
|
||||
#xssProtection = "1; mode=block"
|
||||
|
||||
# The X-Content-Type-Options header. If null, the header is not set.
|
||||
#contentTypeOptions = "nosniff"
|
||||
|
||||
# The X-Permitted-Cross-Domain-Policies header. If null, the header is not set.
|
||||
#permittedCrossDomainPolicies = "master-only"
|
||||
|
||||
# The Content-Security-Policy header. If null, the header is not set.
|
||||
#contentSecurityPolicy = "default-src 'self'"
|
||||
}
|
||||
|
||||
## Allowed hosts filter configuration
|
||||
# https://www.playframework.com/documentation/latest/AllowedHostsFilter
|
||||
# ~~~~~
|
||||
# Play provides a filter that lets you configure which hosts can access your application.
|
||||
# This is useful to prevent cache poisoning attacks.
|
||||
hosts {
|
||||
# Allow requests to example.com, its subdomains, and localhost:9000.
|
||||
#allowed = [".example.com", "localhost:9000"]
|
||||
}
|
||||
}
|
||||
|
||||
## Evolutions
|
||||
# https://www.playframework.com/documentation/latest/Evolutions
|
||||
# ~~~~~
|
||||
# Evolutions allows database scripts to be automatically run on startup in dev mode
|
||||
# for database migrations. You must enable this by adding to build.sbt:
|
||||
#
|
||||
# libraryDependencies += evolutions
|
||||
#
|
||||
play.evolutions {
|
||||
# You can disable evolutions for a specific datasource if necessary
|
||||
#db.default.enabled = false
|
||||
}
|
||||
|
||||
## Database Connection Pool
|
||||
# https://www.playframework.com/documentation/latest/SettingsJDBC
|
||||
# ~~~~~
|
||||
# Play doesn't require a JDBC database to run, but you can easily enable one.
|
||||
#
|
||||
# libraryDependencies += jdbc
|
||||
#
|
||||
play.db {
|
||||
# The combination of these two settings results in "db.default" as the
|
||||
# default JDBC pool:
|
||||
#config = "db"
|
||||
#default = "default"
|
||||
|
||||
# Play uses HikariCP as the default connection pool. You can override
|
||||
# settings by changing the prototype:
|
||||
prototype {
|
||||
# Sets a fixed JDBC connection pool size of 50
|
||||
#hikaricp.minimumIdle = 50
|
||||
#hikaricp.maximumPoolSize = 50
|
||||
}
|
||||
}
|
||||
|
||||
## JDBC Datasource
|
||||
# https://www.playframework.com/documentation/latest/JavaDatabase
|
||||
# https://www.playframework.com/documentation/latest/ScalaDatabase
|
||||
# ~~~~~
|
||||
# Once JDBC datasource is set up, you can work with several different
|
||||
# database options:
|
||||
#
|
||||
# Slick (Scala preferred option): https://www.playframework.com/documentation/latest/PlaySlick
|
||||
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
|
||||
# EBean: https://playframework.com/documentation/latest/JavaEbean
|
||||
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
|
||||
#
|
||||
db {
|
||||
# You can declare as many datasources as you want.
|
||||
# By convention, the default datasource is named `default`
|
||||
|
||||
# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
|
||||
#default.driver = org.h2.Driver
|
||||
#default.url = "jdbc:h2:mem:play"
|
||||
#default.username = sa
|
||||
#default.password = ""
|
||||
|
||||
# You can turn on SQL logging for any datasource
|
||||
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
|
||||
#default.logSql=true
|
||||
}
|
41
samples/server/petstore/java-play-framework/conf/logback.xml
Normal file
41
samples/server/petstore/java-play-framework/conf/logback.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
|
||||
<configuration>
|
||||
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>${application.home:-.}/logs/application.log</file>
|
||||
<encoder>
|
||||
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="FILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</appender>
|
||||
|
||||
<logger name="play" level="INFO" />
|
||||
<logger name="application" level="DEBUG" />
|
||||
|
||||
<!-- Off these ones as they are annoying, and anyway we manage configuration ourselves -->
|
||||
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
|
||||
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
|
||||
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
|
||||
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="ASYNCFILE" />
|
||||
<appender-ref ref="ASYNCSTDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
40
samples/server/petstore/java-play-framework/conf/routes
Normal file
40
samples/server/petstore/java-play-framework/conf/routes
Normal file
@ -0,0 +1,40 @@
|
||||
# Routes
|
||||
# This file defines all application routes (Higher priority routes first)
|
||||
# ~~~~
|
||||
|
||||
GET /api controllers.ApiDocController.api
|
||||
|
||||
|
||||
#Functions for Pet API
|
||||
POST /pet controllers.PetApiController.addPet()
|
||||
DELETE /pet/:petId controllers.PetApiController.deletePet(petId: Long)
|
||||
GET /pet/findByStatus controllers.PetApiController.findPetsByStatus()
|
||||
GET /pet/findByTags controllers.PetApiController.findPetsByTags()
|
||||
GET /pet/:petId controllers.PetApiController.getPetById(petId: Long)
|
||||
PUT /pet controllers.PetApiController.updatePet()
|
||||
POST /pet/:petId controllers.PetApiController.updatePetWithForm(petId: String)
|
||||
POST /pet/:petId/uploadImage controllers.PetApiController.uploadFile(petId: Long)
|
||||
|
||||
#Functions for Store API
|
||||
DELETE /store/order/:orderId controllers.StoreApiController.deleteOrder(orderId: String)
|
||||
GET /store/inventory controllers.StoreApiController.getInventory()
|
||||
GET /store/order/:orderId controllers.StoreApiController.getOrderById(orderId: String)
|
||||
POST /store/order controllers.StoreApiController.placeOrder()
|
||||
|
||||
#Functions for User API
|
||||
POST /user controllers.UserApiController.createUser()
|
||||
POST /user/createWithArray controllers.UserApiController.createUsersWithArrayInput()
|
||||
POST /user/createWithList controllers.UserApiController.createUsersWithListInput()
|
||||
DELETE /user/:username controllers.UserApiController.deleteUser(username: String)
|
||||
GET /user/:username controllers.UserApiController.getUserByName(username: String)
|
||||
GET /user/login controllers.UserApiController.loginUser()
|
||||
GET /user/logout controllers.UserApiController.logoutUser()
|
||||
PUT /user/:username controllers.UserApiController.updateUser(username: String)
|
||||
|
||||
# Map static resources from the /public folder to the /assets URL path
|
||||
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
|
||||
|
||||
GET /api-docs controllers.ApiHelpController.getResources
|
||||
GET /api-docs.json/Pet controllers.ApiHelpController.getResource(path = "/Pet")
|
||||
GET /api-docs.json/Store controllers.ApiHelpController.getResource(path = "/Store")
|
||||
GET /api-docs.json/User controllers.ApiHelpController.getResource(path = "/User")
|
43
samples/server/petstore/java-play-framework/pom.xml
Normal file
43
samples/server/petstore/java-play-framework/pom.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>PlayServerTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Play Petstore Server</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>Play Test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>./sbt_test_jdk8_only.sh</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
sbt.version=0.13.11
|
@ -0,0 +1,2 @@
|
||||
// The Play plugin
|
||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
|
11
samples/server/petstore/java-play-framework/sbt_test_jdk8_only.sh
Executable file
11
samples/server/petstore/java-play-framework/sbt_test_jdk8_only.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
java -version 2>&1 | grep "java version \"1.8"
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Running JDK8"
|
||||
sbt test
|
||||
else
|
||||
echo "Not running JDK8"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user