Skip to content

Commit 282f359

Browse files
committed
Update PetStore sample
1 parent 72b1749 commit 282f359

File tree

6 files changed

+376
-2
lines changed

6 files changed

+376
-2
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# DefaultApi
2+
3+
All URIs are relative to *http://petstore.swagger.io:80/v2*
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**testBodyWithQueryParams**](DefaultApi.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params |
8+
9+
10+
<a name="testBodyWithQueryParams"></a>
11+
# **testBodyWithQueryParams**
12+
> testBodyWithQueryParams(body, query)
13+
14+
15+
16+
### Example
17+
```java
18+
// Import classes:
19+
//import io.swagger.client.ApiException;
20+
//import io.swagger.client.api.DefaultApi;
21+
22+
23+
DefaultApi apiInstance = new DefaultApi();
24+
User body = new User(); // User |
25+
String query = "query_example"; // String |
26+
try {
27+
apiInstance.testBodyWithQueryParams(body, query);
28+
} catch (ApiException e) {
29+
System.err.println("Exception when calling DefaultApi#testBodyWithQueryParams");
30+
e.printStackTrace();
31+
}
32+
```
33+
34+
### Parameters
35+
36+
Name | Type | Description | Notes
37+
------------- | ------------- | ------------- | -------------
38+
**body** | [**User**](User.md)| |
39+
**query** | **String**| |
40+
41+
### Return type
42+
43+
null (empty response body)
44+
45+
### Authorization
46+
47+
No authorization required
48+
49+
### HTTP request headers
50+
51+
- **Content-Type**: application/json
52+
- **Accept**: Not defined
53+

samples/client/petstore/java/okhttp-gson/docs/EnumTest.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**enumString** | [**EnumStringEnum**](#EnumStringEnum) | | [optional]
8+
**enumStringRequired** | [**EnumStringRequiredEnum**](#EnumStringRequiredEnum) | |
89
**enumInteger** | [**EnumIntegerEnum**](#EnumIntegerEnum) | | [optional]
910
**enumNumber** | [**EnumNumberEnum**](#EnumNumberEnum) | | [optional]
1011
**outerEnum** | [**OuterEnum**](OuterEnum.md) | | [optional]
@@ -19,6 +20,15 @@ LOWER | &quot;lower&quot;
1920
EMPTY | &quot;&quot;
2021

2122

23+
<a name="EnumStringRequiredEnum"></a>
24+
## Enum: EnumStringRequiredEnum
25+
Name | Value
26+
---- | -----
27+
UPPER | &quot;UPPER&quot;
28+
LOWER | &quot;lower&quot;
29+
EMPTY | &quot;&quot;
30+
31+
2232
<a name="EnumIntegerEnum"></a>
2333
## Enum: EnumIntegerEnum
2434
Name | Value

samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/JSON.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public Class getClassForElement(JsonElement readElement) {
6464
}
6565
})
6666
;
67-
return fireBuilder.createGsonBuilder();
67+
GsonBuilder builder = fireBuilder.createGsonBuilder();
68+
return builder;
6869
}
6970

7071
private static String getDiscriminatorValue(JsonElement readElement, String discriminatorField) {
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* Swagger Petstore
3+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator program.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
14+
package io.swagger.client.api;
15+
16+
import io.swagger.client.ApiCallback;
17+
import io.swagger.client.ApiClient;
18+
import io.swagger.client.ApiException;
19+
import io.swagger.client.ApiResponse;
20+
import io.swagger.client.Configuration;
21+
import io.swagger.client.Pair;
22+
import io.swagger.client.ProgressRequestBody;
23+
import io.swagger.client.ProgressResponseBody;
24+
25+
import com.google.gson.reflect.TypeToken;
26+
27+
import java.io.IOException;
28+
29+
30+
import io.swagger.client.model.User;
31+
32+
import java.lang.reflect.Type;
33+
import java.util.ArrayList;
34+
import java.util.HashMap;
35+
import java.util.List;
36+
import java.util.Map;
37+
38+
public class DefaultApi {
39+
private ApiClient apiClient;
40+
41+
public DefaultApi() {
42+
this(Configuration.getDefaultApiClient());
43+
}
44+
45+
public DefaultApi(ApiClient apiClient) {
46+
this.apiClient = apiClient;
47+
}
48+
49+
public ApiClient getApiClient() {
50+
return apiClient;
51+
}
52+
53+
public void setApiClient(ApiClient apiClient) {
54+
this.apiClient = apiClient;
55+
}
56+
57+
/**
58+
* Build call for testBodyWithQueryParams
59+
* @param body (required)
60+
* @param query (required)
61+
* @param progressListener Progress listener
62+
* @param progressRequestListener Progress request listener
63+
* @return Call to execute
64+
* @throws ApiException If fail to serialize the request body object
65+
*/
66+
public com.squareup.okhttp.Call testBodyWithQueryParamsCall(User body, String query, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
67+
Object localVarPostBody = body;
68+
69+
// create path and map variables
70+
String localVarPath = "/fake/body-with-query-params";
71+
72+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
73+
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
74+
if (query != null)
75+
localVarQueryParams.addAll(apiClient.parameterToPair("query", query));
76+
77+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
78+
79+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
80+
81+
final String[] localVarAccepts = {
82+
83+
};
84+
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
85+
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
86+
87+
final String[] localVarContentTypes = {
88+
"application/json"
89+
};
90+
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
91+
localVarHeaderParams.put("Content-Type", localVarContentType);
92+
93+
if(progressListener != null) {
94+
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
95+
@Override
96+
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
97+
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
98+
return originalResponse.newBuilder()
99+
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
100+
.build();
101+
}
102+
});
103+
}
104+
105+
String[] localVarAuthNames = new String[] { };
106+
return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
107+
}
108+
109+
@SuppressWarnings("rawtypes")
110+
private com.squareup.okhttp.Call testBodyWithQueryParamsValidateBeforeCall(User body, String query, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
111+
112+
// verify the required parameter 'body' is set
113+
if (body == null) {
114+
throw new ApiException("Missing the required parameter 'body' when calling testBodyWithQueryParams(Async)");
115+
}
116+
117+
// verify the required parameter 'query' is set
118+
if (query == null) {
119+
throw new ApiException("Missing the required parameter 'query' when calling testBodyWithQueryParams(Async)");
120+
}
121+
122+
123+
com.squareup.okhttp.Call call = testBodyWithQueryParamsCall(body, query, progressListener, progressRequestListener);
124+
return call;
125+
126+
}
127+
128+
/**
129+
*
130+
*
131+
* @param body (required)
132+
* @param query (required)
133+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
134+
*/
135+
public void testBodyWithQueryParams(User body, String query) throws ApiException {
136+
testBodyWithQueryParamsWithHttpInfo(body, query);
137+
}
138+
139+
/**
140+
*
141+
*
142+
* @param body (required)
143+
* @param query (required)
144+
* @return ApiResponse&lt;Void&gt;
145+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
146+
*/
147+
public ApiResponse<Void> testBodyWithQueryParamsWithHttpInfo(User body, String query) throws ApiException {
148+
com.squareup.okhttp.Call call = testBodyWithQueryParamsValidateBeforeCall(body, query, null, null);
149+
return apiClient.execute(call);
150+
}
151+
152+
/**
153+
* (asynchronously)
154+
*
155+
* @param body (required)
156+
* @param query (required)
157+
* @param callback The callback to be executed when the API call finishes
158+
* @return The request call
159+
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
160+
*/
161+
public com.squareup.okhttp.Call testBodyWithQueryParamsAsync(User body, String query, final ApiCallback<Void> callback) throws ApiException {
162+
163+
ProgressResponseBody.ProgressListener progressListener = null;
164+
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
165+
166+
if (callback != null) {
167+
progressListener = new ProgressResponseBody.ProgressListener() {
168+
@Override
169+
public void update(long bytesRead, long contentLength, boolean done) {
170+
callback.onDownloadProgress(bytesRead, contentLength, done);
171+
}
172+
};
173+
174+
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
175+
@Override
176+
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
177+
callback.onUploadProgress(bytesWritten, contentLength, done);
178+
}
179+
};
180+
}
181+
182+
com.squareup.okhttp.Call call = testBodyWithQueryParamsValidateBeforeCall(body, query, progressListener, progressRequestListener);
183+
apiClient.executeAsync(call, callback);
184+
return call;
185+
}
186+
}

samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/EnumTest.java

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,58 @@ public EnumStringEnum read(final JsonReader jsonReader) throws IOException {
8282
@SerializedName("enum_string")
8383
private EnumStringEnum enumString = null;
8484

85+
/**
86+
* Gets or Sets enumStringRequired
87+
*/
88+
@JsonAdapter(EnumStringRequiredEnum.Adapter.class)
89+
public enum EnumStringRequiredEnum {
90+
UPPER("UPPER"),
91+
92+
LOWER("lower"),
93+
94+
EMPTY("");
95+
96+
private String value;
97+
98+
EnumStringRequiredEnum(String value) {
99+
this.value = value;
100+
}
101+
102+
public String getValue() {
103+
return value;
104+
}
105+
106+
@Override
107+
public String toString() {
108+
return String.valueOf(value);
109+
}
110+
111+
public static EnumStringRequiredEnum fromValue(String text) {
112+
for (EnumStringRequiredEnum b : EnumStringRequiredEnum.values()) {
113+
if (String.valueOf(b.value).equals(text)) {
114+
return b;
115+
}
116+
}
117+
return null;
118+
}
119+
120+
public static class Adapter extends TypeAdapter<EnumStringRequiredEnum> {
121+
@Override
122+
public void write(final JsonWriter jsonWriter, final EnumStringRequiredEnum enumeration) throws IOException {
123+
jsonWriter.value(enumeration.getValue());
124+
}
125+
126+
@Override
127+
public EnumStringRequiredEnum read(final JsonReader jsonReader) throws IOException {
128+
String value = jsonReader.nextString();
129+
return EnumStringRequiredEnum.fromValue(String.valueOf(value));
130+
}
131+
}
132+
}
133+
134+
@SerializedName("enum_string_required")
135+
private EnumStringRequiredEnum enumStringRequired = null;
136+
85137
/**
86138
* Gets or Sets enumInteger
87139
*/
@@ -203,6 +255,24 @@ public void setEnumString(EnumStringEnum enumString) {
203255
this.enumString = enumString;
204256
}
205257

258+
public EnumTest enumStringRequired(EnumStringRequiredEnum enumStringRequired) {
259+
this.enumStringRequired = enumStringRequired;
260+
return this;
261+
}
262+
263+
/**
264+
* Get enumStringRequired
265+
* @return enumStringRequired
266+
**/
267+
@ApiModelProperty(required = true, value = "")
268+
public EnumStringRequiredEnum getEnumStringRequired() {
269+
return enumStringRequired;
270+
}
271+
272+
public void setEnumStringRequired(EnumStringRequiredEnum enumStringRequired) {
273+
this.enumStringRequired = enumStringRequired;
274+
}
275+
206276
public EnumTest enumInteger(EnumIntegerEnum enumInteger) {
207277
this.enumInteger = enumInteger;
208278
return this;
@@ -268,14 +338,15 @@ public boolean equals(java.lang.Object o) {
268338
}
269339
EnumTest enumTest = (EnumTest) o;
270340
return Objects.equals(this.enumString, enumTest.enumString) &&
341+
Objects.equals(this.enumStringRequired, enumTest.enumStringRequired) &&
271342
Objects.equals(this.enumInteger, enumTest.enumInteger) &&
272343
Objects.equals(this.enumNumber, enumTest.enumNumber) &&
273344
Objects.equals(this.outerEnum, enumTest.outerEnum);
274345
}
275346

276347
@Override
277348
public int hashCode() {
278-
return Objects.hash(enumString, enumInteger, enumNumber, outerEnum);
349+
return Objects.hash(enumString, enumStringRequired, enumInteger, enumNumber, outerEnum);
279350
}
280351

281352

@@ -285,6 +356,7 @@ public String toString() {
285356
sb.append("class EnumTest {\n");
286357

287358
sb.append(" enumString: ").append(toIndentedString(enumString)).append("\n");
359+
sb.append(" enumStringRequired: ").append(toIndentedString(enumStringRequired)).append("\n");
288360
sb.append(" enumInteger: ").append(toIndentedString(enumInteger)).append("\n");
289361
sb.append(" enumNumber: ").append(toIndentedString(enumNumber)).append("\n");
290362
sb.append(" outerEnum: ").append(toIndentedString(outerEnum)).append("\n");

0 commit comments

Comments
 (0)