Skip to content

Commit 23dae2b

Browse files
authored
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
1 parent 46c2c30 commit 23dae2b

111 files changed

Lines changed: 80 additions & 304 deletions

File tree

Some content is hidden

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

.github/workflows/samples-java-play-framework.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- samples/server/petstore/java-play-framework-fake-endpoints
2424
- samples/server/petstore/java-play-framework-fake-endpoints-with-security
2525
- samples/server/petstore/java-play-framework-no-bean-validation
26-
- samples/server/petstore/java-play-framework-no-exception-handling
26+
- samples/server/petstore/java-play-framework-no-excp-handling
2727
- samples/server/petstore/java-play-framework-no-interface
2828
- samples/server/petstore/java-play-framework-no-nullable
2929
- samples/server/petstore/java-play-framework-no-swagger-ui

.github/workflows/samples-spring.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- samples/openapi3/server/petstore/springboot-delegate
4343
- samples/openapi3/server/petstore/spring-boot-oneof
4444
- samples/server/petstore/spring-boot-nullable-set
45-
- samples/server/petstore/spring-boot-defaultInterface-unhandledException
45+
- samples/server/petstore/spring-boot-defaultInterface-unhandledExcp
4646
- samples/server/petstore/springboot
4747
- samples/server/petstore/springboot-beanvalidation
4848
- samples/server/petstore/springboot-builtin-validation

bin/configs/java-play-framework-no-exception-handling.yaml renamed to bin/configs/java-play-framework-no-excp-handling-.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generatorName: java-play-framework
2-
outputDir: samples/server/petstore/java-play-framework-no-exception-handling
2+
outputDir: samples/server/petstore/java-play-framework-no-excp-handling
33
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
44
templateDir: modules/openapi-generator/src/main/resources/JavaPlayFramework
55
additionalProperties:

bin/configs/spring-boot-defaultInterface-unhandledException.yaml renamed to bin/configs/spring-boot-defaultInterface-unhandledExcp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generatorName: spring
2-
outputDir: samples/server/petstore/spring-boot-defaultInterface-unhandledException
2+
outputDir: samples/server/petstore/spring-boot-defaultInterface-unhandledExcp
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml
44
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
55
additionalProperties:

bin/generate-samples.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ else
6060

6161
# shellcheck disable=SC2086
6262
# shellcheck disable=SC2068
63-
java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]}
63+
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
64+
echo "Found exception(s) when running the generator(s) to update the samples."
65+
export GENERATE_ERROR=1
66+
fi
6467
fi
6568

69+
if [[ -n "$GENERATE_ERROR" ]]; then
70+
echo "Found exception(s) when running the generator(s) to update the samples."
71+
# UNCOMMENT LATER
72+
#exit 1
73+
fi

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature-oneof-primitive-types.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,9 +2798,8 @@ components:
27982798
format: float32
27992799
- type: object
28002800
$ref: '#/components/schemas/MixedSubId'
2801-
28022801
description: Mixed anyOf types for testing
28032802
MixedSubId:
28042803
properties:
28052804
id:
2806-
type: string
2805+
type: string

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2856,7 +2856,6 @@ components:
28562856
format: float32
28572857
- type: object
28582858
$ref: '#/components/schemas/MixedSubId'
2859-
28602859
description: Mixed anyOf types for testing
28612860
MixedSubId:
28622861
properties:

modules/openapi-generator/src/test/resources/3_0/enum-implements.yaml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,64 @@ paths:
1717
type: array
1818
items:
1919
$ref: '#/components/schemas/Pony'
20+
/fake/null-request-body:
21+
get:
22+
summary: to ensure null request body wont' throw exception
23+
operationId: null-request-body
24+
parameters:
25+
- name: Accept-Language
26+
in: header
27+
schema:
28+
type: string
29+
example: application/json
30+
requestBody:
31+
content:
32+
text/plain:
33+
examples:
34+
Generar Orden por External ID:
35+
value: |-
36+
{
37+
"external_reference": "{{external_order_ref}}",
38+
"notification_url": "www.yourserver.com/yourendpoint",
39+
"sponsor_id": 446566691,
40+
"items": [
41+
{
42+
"title": "Papas frita",
43+
"currency_id": "{{currency_id}}",
44+
"unit_price": 6000,
45+
"quantity": 1
46+
},
47+
{
48+
"title": "Gaseosa",
49+
"currency_id": "{{currency_id}}",
50+
"unit_price": 3000,
51+
"quantity": 1
52+
}
53+
]/*,
54+
"taxes": [
55+
{
56+
"value": 0,
57+
"type": "IVA"
58+
}
59+
]*/
60+
}
61+
responses:
62+
'200':
63+
description: ''
64+
/myExample:
65+
get:
66+
responses:
67+
'200':
68+
description: Response
69+
content:
70+
application/json:
71+
schema:
72+
oneOf:
73+
- type: array
74+
items:
75+
"$ref": "#/components/schemas/OneOf1"
76+
- type: object
77+
"$ref": "#/components/schemas/OneOf1"
2078
components:
2179
schemas:
2280
Pony:
@@ -30,4 +88,9 @@ components:
3088
enum:
3189
- Earth
3290
- Pegasi
33-
- Unicorn
91+
- Unicorn
92+
OneOf1:
93+
type: object
94+
properties:
95+
message1:
96+
type: string

modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-okhttp-gson.yaml

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,52 +1297,6 @@ paths:
12971297
responses:
12981298
200:
12991299
description: OK
1300-
/fake/null-request-body:
1301-
get:
1302-
tags:
1303-
- another_fake
1304-
summary: null request body
1305-
operationId: null-request-body
1306-
parameters:
1307-
- name: Accept-Language
1308-
in: header
1309-
schema:
1310-
type: string
1311-
example: application/json
1312-
requestBody:
1313-
content:
1314-
text/plain:
1315-
examples:
1316-
Generar Orden por External ID:
1317-
value: |-
1318-
{
1319-
"external_reference": "{{external_order_ref}}",
1320-
"notification_url": "www.yourserver.com/yourendpoint",
1321-
"sponsor_id": 446566691,
1322-
"items": [
1323-
{
1324-
"title": "Papas frita",
1325-
"currency_id": "{{currency_id}}",
1326-
"unit_price": 6000,
1327-
"quantity": 1
1328-
},
1329-
{
1330-
"title": "Gaseosa",
1331-
"currency_id": "{{currency_id}}",
1332-
"unit_price": 3000,
1333-
"quantity": 1
1334-
}
1335-
]/*,
1336-
"taxes": [
1337-
{
1338-
"value": 0,
1339-
"type": "IVA"
1340-
}
1341-
]*/
1342-
}
1343-
responses:
1344-
'200':
1345-
description: ''
13461300
'/fake/pet/{petId}/uploadImage':
13471301
post:
13481302
tags:

modules/openapi-generator/src/test/resources/3_0/oneOf_array.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ paths:
1515
- type: array
1616
items:
1717
"$ref": "#/components/schemas/OneOf1"
18-
- type: object
19-
"$ref": "#/components/schemas/OneOf1"
18+
- "$ref": "#/components/schemas/OneOf1"
2019
components:
2120
schemas:
2221
OneOf1:
2322
type: object
2423
properties:
2524
message1:
26-
type: string
25+
type: string

0 commit comments

Comments
 (0)