mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
updated java example
This commit is contained in:
parent
8e8e5308b6
commit
930b1ea0ea
@ -2,6 +2,7 @@ package com.wordnik.petstore.api;
|
||||
|
||||
import com.wordnik.client.ApiException;
|
||||
import com.wordnik.client.ApiInvoker;
|
||||
import java.io.File;
|
||||
import com.wordnik.petstore.model.Pet;
|
||||
import java.util.*;
|
||||
|
||||
@ -21,7 +22,7 @@ public class PetApi {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public Pet getPetById (String petId) throws ApiException {
|
||||
public Pet getPetById (Long petId) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
@ -83,6 +84,95 @@ public class PetApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null || body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "PATCH", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void uploadFile (String additionalMetadata, File body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/uploadImage".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void addPet (Pet body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
@ -164,7 +254,7 @@ public class PetApi {
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@ -197,7 +287,7 @@ public class PetApi {
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "array", Pet.class);
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
@ -1,15 +1,10 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
public class Category {
|
||||
private String name = null;
|
||||
/* Category unique identifier */
|
||||
private Long id = null;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* Name of the category */
|
||||
private String name = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -17,12 +12,19 @@ public class Category {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Category {\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -2,11 +2,15 @@ package com.wordnik.petstore.model;
|
||||
|
||||
import java.util.Date;
|
||||
public class Order {
|
||||
/* Unique identifier for the order */
|
||||
private Long id = null;
|
||||
/* Order Status */
|
||||
private String status = null;
|
||||
/* ID of pet being ordered */
|
||||
private Long petId = null;
|
||||
/* Number of pets ordered */
|
||||
private Integer quantity = null;
|
||||
/* Status of the order */
|
||||
private String status = null;
|
||||
/* Date shipped, only if it has been */
|
||||
private Date shipDate = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -15,13 +19,6 @@ public class Order {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getPetId() {
|
||||
return petId;
|
||||
}
|
||||
@ -36,6 +33,13 @@ public class Order {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
@ -48,9 +52,9 @@ public class Order {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Order {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" status: ").append(status).append("\n");
|
||||
sb.append(" petId: ").append(petId).append("\n");
|
||||
sb.append(" quantity: ").append(quantity).append("\n");
|
||||
sb.append(" status: ").append(status).append("\n");
|
||||
sb.append(" shipDate: ").append(shipDate).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
|
@ -4,13 +4,32 @@ import java.util.*;
|
||||
import com.wordnik.petstore.model.Category;
|
||||
import com.wordnik.petstore.model.Tag;
|
||||
public class Pet {
|
||||
private String name = null;
|
||||
/* Unique identifier for the Pet */
|
||||
private Long id = null;
|
||||
/* Category the pet is in */
|
||||
private Category category = null;
|
||||
/* Friendly name of the pet */
|
||||
private String name = null;
|
||||
/* Image URLs */
|
||||
private List<String> photoUrls = new ArrayList<String>();
|
||||
/* Tags assigned to this pet */
|
||||
private List<Tag> tags = new ArrayList<Tag>();
|
||||
/* pet status in the store */
|
||||
private String status = null;
|
||||
private List<String> photoUrls = new ArrayList<String>();
|
||||
private Category category = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -18,11 +37,11 @@ public class Pet {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
public List<String> getPhotoUrls() {
|
||||
return photoUrls;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
public void setPhotoUrls(List<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
@ -39,30 +58,16 @@ public class Pet {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<String> getPhotoUrls() {
|
||||
return photoUrls;
|
||||
}
|
||||
public void setPhotoUrls(List<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Pet {\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" category: ").append(category).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append(" photoUrls: ").append(photoUrls).append("\n");
|
||||
sb.append(" tags: ").append(tags).append("\n");
|
||||
sb.append(" status: ").append(status).append("\n");
|
||||
sb.append(" photoUrls: ").append(photoUrls).append("\n");
|
||||
sb.append(" category: ").append(category).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -1,15 +1,10 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
public class Tag {
|
||||
private String name = null;
|
||||
/* Unique identifier for the tag */
|
||||
private Long id = null;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* Friendly name for the tag */
|
||||
private String name = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -17,12 +12,19 @@ public class Tag {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Tag {\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -1,12 +1,19 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
public class User {
|
||||
/* Unique identifier for the user */
|
||||
private Long id = null;
|
||||
private String firstName = null;
|
||||
/* Unique username */
|
||||
private String username = null;
|
||||
/* First name of the user */
|
||||
private String firstName = null;
|
||||
/* Last name of the user */
|
||||
private String lastName = null;
|
||||
/* Email address of the user */
|
||||
private String email = null;
|
||||
/* Password name of the user */
|
||||
private String password = null;
|
||||
/* Phone number of the user */
|
||||
private String phone = null;
|
||||
/* User Status */
|
||||
private Integer userStatus = null;
|
||||
@ -17,13 +24,6 @@ public class User {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@ -31,6 +31,13 @@ public class User {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
@ -71,8 +78,8 @@ public class User {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class User {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" firstName: ").append(firstName).append("\n");
|
||||
sb.append(" username: ").append(username).append("\n");
|
||||
sb.append(" firstName: ").append(firstName).append("\n");
|
||||
sb.append(" lastName: ").append(lastName).append("\n");
|
||||
sb.append(" email: ").append(email).append("\n");
|
||||
sb.append(" password: ").append(password).append("\n");
|
||||
|
@ -78,6 +78,7 @@ class BasicJavaGenerator extends BasicGenerator {
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map(
|
||||
"File" -> "java.io.File",
|
||||
"Date" -> "java.util.Date",
|
||||
"Array" -> "java.util.*",
|
||||
"ArrayList" -> "java.util.*",
|
||||
|
Loading…
Reference in New Issue
Block a user