Skip to content

Commit 4872ef3

Browse files
committed
Add test case for referenced callbacks during unused schemas computation
It was not possible to add it in OpenAPITools#1232 because of issue swagger-api/swagger-parser#879
1 parent 39045d0 commit 4872ef3

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class ModelUtilsTest {
4444
public void testGetAllUsedSchemas() {
4545
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/unusedSchemas.yaml", null, new ParseOptions()).getOpenAPI();
4646
List<String> allUsedSchemas = ModelUtils.getAllUsedSchemas(openAPI);
47-
Assert.assertEquals(allUsedSchemas.size(), 30);
47+
Assert.assertEquals(allUsedSchemas.size(), 32);
4848

4949
Assert.assertTrue(allUsedSchemas.contains("SomeObjShared"), "contains 'SomeObjShared'");
5050
Assert.assertTrue(allUsedSchemas.contains("SomeObj1"), "contains 'UnusedObj1'");
@@ -76,6 +76,8 @@ public void testGetAllUsedSchemas() {
7676
Assert.assertTrue(allUsedSchemas.contains("OtherObj20"), "contains 'OtherObj20'");
7777
Assert.assertTrue(allUsedSchemas.contains("PingDataInput21"), "contains 'PingDataInput21'");
7878
Assert.assertTrue(allUsedSchemas.contains("PingDataOutput21"), "contains 'PingDataOutput21'");
79+
Assert.assertTrue(allUsedSchemas.contains("SInput22"), "contains 'SInput22'");
80+
Assert.assertTrue(allUsedSchemas.contains("SOutput22"), "contains 'SInput22'");
7981
}
8082

8183
@Test

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@ paths:
263263
application/json:
264264
schema:
265265
$ref: '#/components/schemas/PingDataOutput21'
266+
/some/p22:
267+
post:
268+
operationId: op22
269+
parameters:
270+
- name: callbackUrl
271+
in: query
272+
required: true
273+
schema:
274+
type: string
275+
format: uri
276+
example: https://some-server.com
277+
responses:
278+
'201':
279+
description: OK
280+
callbacks:
281+
sharedCallback:
282+
$ref: "#/components/callbacks/sharedCallback22"
266283
components:
267284
schemas:
268285
UnusedObj1:
@@ -507,6 +524,20 @@ components:
507524
type: integer
508525
reply:
509526
type: String
527+
SInput22:
528+
type: object
529+
properties:
530+
uuid:
531+
type: String
532+
request:
533+
type: String
534+
SOutput22:
535+
type: object
536+
properties:
537+
uuid:
538+
type: String
539+
response:
540+
type: String
510541
SomeObjShared:
511542
type: object
512543
properties:
@@ -560,4 +591,20 @@ components:
560591
in: query
561592
schema:
562593
$ref: '#/components/schemas/SomeObj11'
594+
callbacks:
595+
sharedCallback22:
596+
'{$request.query.callbackUrl}/shared':
597+
post:
598+
requestBody:
599+
content:
600+
application/json:
601+
schema:
602+
$ref: '#/components/schemas/SInput22'
603+
responses:
604+
'200':
605+
description: Ok
606+
content:
607+
application/json:
608+
schema:
609+
$ref: '#/components/schemas/SOutput22'
563610

0 commit comments

Comments
 (0)