Skip to content

Commit a3589cd

Browse files
committed
updated java okhttp gson sample
1 parent 17a55cb commit a3589cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1474
-769
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.6-SNAPSHOT
1+
3.0.11-SNAPSHOT
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# AllPetsResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OneOfAllPetsResponseItems
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OneOfSinglePetResponsePet
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Method | HTTP request | Description
88
[**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
99
[**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
1010
[**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
11+
[**getAllPets**](PetApi.md#getAllPets) | **GET** /allPets |
1112
[**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID
13+
[**getRandomPet**](PetApi.md#getRandomPet) | **GET** /randomPet |
1214
[**updatePet**](PetApi.md#updatePet) | **PUT** /pet | Update an existing pet
1315
[**updatePetWithForm**](PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
1416
[**uploadFile**](PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
@@ -221,6 +223,45 @@ Name | Type | Description | Notes
221223
- **Content-Type**: Not defined
222224
- **Accept**: application/xml, application/json
223225

226+
<a name="getAllPets"></a>
227+
# **getAllPets**
228+
> AllPetsResponse getAllPets()
229+
230+
231+
232+
### Example
233+
```java
234+
// Import classes:
235+
//import io.swagger.client.ApiException;
236+
//import io.swagger.client.api.PetApi;
237+
238+
239+
PetApi apiInstance = new PetApi();
240+
try {
241+
AllPetsResponse result = apiInstance.getAllPets();
242+
System.out.println(result);
243+
} catch (ApiException e) {
244+
System.err.println("Exception when calling PetApi#getAllPets");
245+
e.printStackTrace();
246+
}
247+
```
248+
249+
### Parameters
250+
This endpoint does not need any parameter.
251+
252+
### Return type
253+
254+
[**AllPetsResponse**](AllPetsResponse.md)
255+
256+
### Authorization
257+
258+
No authorization required
259+
260+
### HTTP request headers
261+
262+
- **Content-Type**: Not defined
263+
- **Accept**: application/json
264+
224265
<a name="getPetById"></a>
225266
# **getPetById**
226267
> Pet getPetById(petId)
@@ -276,6 +317,45 @@ Name | Type | Description | Notes
276317
- **Content-Type**: Not defined
277318
- **Accept**: application/xml, application/json
278319

320+
<a name="getRandomPet"></a>
321+
# **getRandomPet**
322+
> SinglePetResponse getRandomPet()
323+
324+
325+
326+
### Example
327+
```java
328+
// Import classes:
329+
//import io.swagger.client.ApiException;
330+
//import io.swagger.client.api.PetApi;
331+
332+
333+
PetApi apiInstance = new PetApi();
334+
try {
335+
SinglePetResponse result = apiInstance.getRandomPet();
336+
System.out.println(result);
337+
} catch (ApiException e) {
338+
System.err.println("Exception when calling PetApi#getRandomPet");
339+
e.printStackTrace();
340+
}
341+
```
342+
343+
### Parameters
344+
This endpoint does not need any parameter.
345+
346+
### Return type
347+
348+
[**SinglePetResponse**](SinglePetResponse.md)
349+
350+
### Authorization
351+
352+
No authorization required
353+
354+
### HTTP request headers
355+
356+
- **Content-Type**: Not defined
357+
- **Accept**: application/json
358+
279359
<a name="updatePet"></a>
280360
# **updatePet**
281361
> updatePet(body)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SinglePetResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**pet** | [**OneOfSinglePetResponsePet**](.md) | | [optional]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This endpoint does not need any parameter.
9393

9494
### Return type
9595

96-
[**Map&lt;String, Integer&gt;**](Map.md)
96+
**Map&lt;String, Integer&gt;**
9797

9898
### Authorization
9999

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import com.google.gson.Gson;
1616
import com.google.gson.GsonBuilder;
1717
import com.google.gson.JsonElement;
18+
import com.google.gson.JsonObject;
1819
import io.gsonfire.GsonFireBuilder;
20+
import io.gsonfire.PostProcessor;
1921
import io.gsonfire.TypeSelector;
2022
import com.google.gson.JsonParseException;
2123
import com.google.gson.TypeAdapter;
@@ -61,6 +63,28 @@ public Class<? extends Animal> getClassForElement(JsonElement readElement) {
6163
getDiscriminatorValue(readElement, "className"));
6264
}
6365
})
66+
.registerPostProcessor(Animal.class, new PostProcessor<Animal>() {
67+
@Override
68+
public void postDeserialize(Animal result, JsonElement src, Gson gson) {
69+
70+
}
71+
72+
@Override
73+
public void postSerialize(JsonElement result, Animal src, Gson gson) {
74+
Map<Class<? extends Animal>, String> discriminatorValueByClass = new HashMap<>();
75+
76+
discriminatorValueByClass.put(Cat.class, "Cat");
77+
discriminatorValueByClass.put(Dog.class, "Dog");
78+
discriminatorValueByClass.put(Animal.class, "Animal");
79+
if(result instanceof JsonObject)
80+
{
81+
if(!((JsonObject) result).has("className"))
82+
{
83+
((JsonObject) result).addProperty("className", discriminatorValueByClass.get(src.getClass()));
84+
}
85+
}
86+
}
87+
})
6488
;
6589
return fireBuilder.createGsonBuilder();
6690
}

0 commit comments

Comments
 (0)