Improve sample update with better exception handling (#22670)

* refactor java tests

* better exception handling when updating samples

* update samples to avoid using exception

* fix tests

* update

* update
This commit is contained in:
William Cheng
2026-01-11 18:52:29 +08:00
committed by GitHub
parent 46c2c30f47
commit 23dae2bcd8
111 changed files with 80 additions and 304 deletions

View File

@@ -23,7 +23,7 @@ jobs:
- samples/server/petstore/java-play-framework-fake-endpoints
- samples/server/petstore/java-play-framework-fake-endpoints-with-security
- samples/server/petstore/java-play-framework-no-bean-validation
- samples/server/petstore/java-play-framework-no-exception-handling
- samples/server/petstore/java-play-framework-no-excp-handling
- samples/server/petstore/java-play-framework-no-interface
- samples/server/petstore/java-play-framework-no-nullable
- samples/server/petstore/java-play-framework-no-swagger-ui

View File

@@ -42,7 +42,7 @@ jobs:
- samples/openapi3/server/petstore/springboot-delegate
- samples/openapi3/server/petstore/spring-boot-oneof
- samples/server/petstore/spring-boot-nullable-set
- samples/server/petstore/spring-boot-defaultInterface-unhandledException
- samples/server/petstore/spring-boot-defaultInterface-unhandledExcp
- samples/server/petstore/springboot
- samples/server/petstore/springboot-beanvalidation
- samples/server/petstore/springboot-builtin-validation

View File

@@ -1,5 +1,5 @@
generatorName: java-play-framework
outputDir: samples/server/petstore/java-play-framework-no-exception-handling
outputDir: samples/server/petstore/java-play-framework-no-excp-handling
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaPlayFramework
additionalProperties:

View File

@@ -1,5 +1,5 @@
generatorName: spring
outputDir: samples/server/petstore/spring-boot-defaultInterface-unhandledException
outputDir: samples/server/petstore/spring-boot-defaultInterface-unhandledExcp
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:

View File

@@ -60,6 +60,14 @@ else
# shellcheck disable=SC2086
# shellcheck disable=SC2068
java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]}
if java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]} 2>&1 | tee /dev/pts/0 | grep -q -i "exception"; then
echo "Found exception(s) when running the generator(s) to update the samples."
export GENERATE_ERROR=1
fi
fi
if [[ -n "$GENERATE_ERROR" ]]; then
echo "Found exception(s) when running the generator(s) to update the samples."
# UNCOMMENT LATER
#exit 1
fi

View File

@@ -2798,9 +2798,8 @@ components:
format: float32
- type: object
$ref: '#/components/schemas/MixedSubId'
description: Mixed anyOf types for testing
MixedSubId:
properties:
id:
type: string
type: string

View File

@@ -2856,7 +2856,6 @@ components:
format: float32
- type: object
$ref: '#/components/schemas/MixedSubId'
description: Mixed anyOf types for testing
MixedSubId:
properties:

View File

@@ -17,6 +17,64 @@ paths:
type: array
items:
$ref: '#/components/schemas/Pony'
/fake/null-request-body:
get:
summary: to ensure null request body wont' throw exception
operationId: null-request-body
parameters:
- name: Accept-Language
in: header
schema:
type: string
example: application/json
requestBody:
content:
text/plain:
examples:
Generar Orden por External ID:
value: |-
{
"external_reference": "{{external_order_ref}}",
"notification_url": "www.yourserver.com/yourendpoint",
"sponsor_id": 446566691,
"items": [
{
"title": "Papas frita",
"currency_id": "{{currency_id}}",
"unit_price": 6000,
"quantity": 1
},
{
"title": "Gaseosa",
"currency_id": "{{currency_id}}",
"unit_price": 3000,
"quantity": 1
}
]/*,
"taxes": [
{
"value": 0,
"type": "IVA"
}
]*/
}
responses:
'200':
description: ''
/myExample:
get:
responses:
'200':
description: Response
content:
application/json:
schema:
oneOf:
- type: array
items:
"$ref": "#/components/schemas/OneOf1"
- type: object
"$ref": "#/components/schemas/OneOf1"
components:
schemas:
Pony:
@@ -30,4 +88,9 @@ components:
enum:
- Earth
- Pegasi
- Unicorn
- Unicorn
OneOf1:
type: object
properties:
message1:
type: string

View File

@@ -1297,52 +1297,6 @@ paths:
responses:
200:
description: OK
/fake/null-request-body:
get:
tags:
- another_fake
summary: null request body
operationId: null-request-body
parameters:
- name: Accept-Language
in: header
schema:
type: string
example: application/json
requestBody:
content:
text/plain:
examples:
Generar Orden por External ID:
value: |-
{
"external_reference": "{{external_order_ref}}",
"notification_url": "www.yourserver.com/yourendpoint",
"sponsor_id": 446566691,
"items": [
{
"title": "Papas frita",
"currency_id": "{{currency_id}}",
"unit_price": 6000,
"quantity": 1
},
{
"title": "Gaseosa",
"currency_id": "{{currency_id}}",
"unit_price": 3000,
"quantity": 1
}
]/*,
"taxes": [
{
"value": 0,
"type": "IVA"
}
]*/
}
responses:
'200':
description: ''
'/fake/pet/{petId}/uploadImage':
post:
tags:

View File

@@ -15,12 +15,11 @@ paths:
- type: array
items:
"$ref": "#/components/schemas/OneOf1"
- type: object
"$ref": "#/components/schemas/OneOf1"
- "$ref": "#/components/schemas/OneOf1"
components:
schemas:
OneOf1:
type: object
properties:
message1:
type: string
type: string

View File

@@ -117,7 +117,6 @@ Class | Method | HTTP request | Description
*AnotherFakeApi* | [**call123testSpecialTags**](docs/AnotherFakeApi.md#call123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags
*AnotherFakeApi* | [**getParameterArrayNumber**](docs/AnotherFakeApi.md#getParameterArrayNumber) | **GET** /fake/parameter-array-number | parameter array number default value
*AnotherFakeApi* | [**getParameterStringNumber**](docs/AnotherFakeApi.md#getParameterStringNumber) | **GET** /fake/parameter-string-number | parameter string number
*AnotherFakeApi* | [**nullRequestBody**](docs/AnotherFakeApi.md#nullRequestBody) | **GET** /fake/null-request-body | null request body
*DefaultApi* | [**fakeAnyOfWIthSameErasureGet**](docs/DefaultApi.md#fakeAnyOfWIthSameErasureGet) | **GET** /fake/anyOfWIthSameErasure |
*DefaultApi* | [**fakeFreeFormQueryParametersGet**](docs/DefaultApi.md#fakeFreeFormQueryParametersGet) | **GET** /fake/free-form-query-parameters |
*DefaultApi* | [**fakeOneOfWIthSameErasureGet**](docs/DefaultApi.md#fakeOneOfWIthSameErasureGet) | **GET** /fake/oneOfWIthSameErasure |

View File

@@ -1404,57 +1404,6 @@ paths:
- another_fake
x-accepts:
- application/json
/fake/null-request-body:
get:
operationId: null-request-body
parameters:
- explode: false
in: header
name: Accept-Language
required: false
schema:
example: application/json
type: string
style: simple
requestBody:
content:
text/plain:
examples:
Generar Orden por External ID:
value: |-
{
"external_reference": "{{external_order_ref}}",
"notification_url": "www.yourserver.com/yourendpoint",
"sponsor_id": 446566691,
"items": [
{
"title": "Papas frita",
"currency_id": "{{currency_id}}",
"unit_price": 6000,
"quantity": 1
},
{
"title": "Gaseosa",
"currency_id": "{{currency_id}}",
"unit_price": 3000,
"quantity": 1
}
]/*,
"taxes": [
{
"value": 0,
"type": "IVA"
}
]*/
}
responses:
"200":
description: ""
summary: null request body
tags:
- another_fake
x-accepts:
- application/json
/fake/pet/{petId}/uploadImage:
post:
description: ""

View File

@@ -7,7 +7,6 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| [**call123testSpecialTags**](AnotherFakeApi.md#call123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags |
| [**getParameterArrayNumber**](AnotherFakeApi.md#getParameterArrayNumber) | **GET** /fake/parameter-array-number | parameter array number default value |
| [**getParameterStringNumber**](AnotherFakeApi.md#getParameterStringNumber) | **GET** /fake/parameter-string-number | parameter string number |
| [**nullRequestBody**](AnotherFakeApi.md#nullRequestBody) | **GET** /fake/null-request-body | null request body |
<a id="call123testSpecialTags"></a>
@@ -190,62 +189,3 @@ No authorization required
|-------------|-------------|------------------|
| **200** | OK | - |
<a id="nullRequestBody"></a>
# **nullRequestBody**
> nullRequestBody(acceptLanguage)
null request body
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.AnotherFakeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
AnotherFakeApi apiInstance = new AnotherFakeApi(defaultClient);
String acceptLanguage = "application/json"; // String |
try {
apiInstance.nullRequestBody(acceptLanguage);
} catch (ApiException e) {
System.err.println("Exception when calling AnotherFakeApi#nullRequestBody");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **acceptLanguage** | **String**| | [optional] |
### Return type
null (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: text/plain
- **Accept**: Not defined
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | | - |

View File

@@ -452,126 +452,4 @@ public class AnotherFakeApi {
localVarApiClient.executeAsync(localVarCall, _callback);
return localVarCall;
}
/**
* Build call for nullRequestBody
* @param acceptLanguage (optional)
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call nullRequestBodyCall(@javax.annotation.Nullable String acceptLanguage, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
// Determine Base Path to Use
if (localCustomBaseUrl != null){
basePath = localCustomBaseUrl;
} else if ( localBasePaths.length > 0 ) {
basePath = localBasePaths[localHostIndex];
} else {
basePath = null;
}
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/fake/null-request-body";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {
"text/plain"
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}
if (acceptLanguage != null) {
localVarHeaderParams.put("Accept-Language", localVarApiClient.parameterToString(acceptLanguage));
}
String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call nullRequestBodyValidateBeforeCall(@javax.annotation.Nullable String acceptLanguage, final ApiCallback _callback) throws ApiException {
return nullRequestBodyCall(acceptLanguage, _callback);
}
/**
* null request body
*
* @param acceptLanguage (optional)
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public void nullRequestBody(@javax.annotation.Nullable String acceptLanguage) throws ApiException {
nullRequestBodyWithHttpInfo(acceptLanguage);
}
/**
* null request body
*
* @param acceptLanguage (optional)
* @return ApiResponse&lt;Void&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public ApiResponse<Void> nullRequestBodyWithHttpInfo(@javax.annotation.Nullable String acceptLanguage) throws ApiException {
okhttp3.Call localVarCall = nullRequestBodyValidateBeforeCall(acceptLanguage, null);
return localVarApiClient.execute(localVarCall);
}
/**
* null request body (asynchronously)
*
* @param acceptLanguage (optional)
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table border="1">
<caption>Response Details</caption>
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> </td><td> - </td></tr>
</table>
*/
public okhttp3.Call nullRequestBodyAsync(@javax.annotation.Nullable String acceptLanguage, final ApiCallback<Void> _callback) throws ApiException {
okhttp3.Call localVarCall = nullRequestBodyValidateBeforeCall(acceptLanguage, _callback);
localVarApiClient.executeAsync(localVarCall, _callback);
return localVarCall;
}
}

View File

@@ -70,16 +70,4 @@ public class AnotherFakeApiTest {
// TODO: test validations
}
/**
* null request body
*
* @throws ApiException if the Api call fails
*/
@Test
public void nullRequestBodyTest() throws ApiException {
String acceptLanguage = null;
api.nullRequestBody(acceptLanguage);
// TODO: test validations
}
}

Some files were not shown because too many files have changed in this diff Show More