Skip to content

Commit cda4b15

Browse files
committed
Add test for null response type conversion to void
Verify that OpenAPI 3.1 responses with `type: 'null'` are converted to void return types instead of generating a broken Null model import.
1 parent 9aa8ad9 commit cda4b15

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,35 @@ public void testNullableOneOfDoesNotImportNullModel() throws IOException {
469469
TestUtils.assertFileNotExists(Paths.get(output + "/models/Null.ts"));
470470
}
471471

472+
@Test(description = "Verify null response type is converted to void")
473+
public void testNullResponseTypeConvertedToVoid() throws IOException {
474+
File output = generate(
475+
Collections.emptyMap(),
476+
"src/test/resources/3_0/typescript-fetch/null-response.yaml"
477+
);
478+
479+
Path apiFile = Paths.get(output + "/apis/ItemsApi.ts");
480+
TestUtils.assertFileExists(apiFile);
481+
482+
// Should not import or reference a "Null" model
483+
TestUtils.assertFileNotContains(apiFile, "Null,");
484+
TestUtils.assertFileNotContains(apiFile, "NullFromJSON");
485+
TestUtils.assertFileNotContains(apiFile, "NullToJSON");
486+
487+
// Delete endpoint should use void return type
488+
TestUtils.assertFileContains(apiFile, "Promise<runtime.ApiResponse<void>>");
489+
TestUtils.assertFileContains(apiFile, "VoidApiResponse");
490+
491+
// Get endpoint should still use Item model
492+
TestUtils.assertFileContains(apiFile, "ItemFromJSON");
493+
TestUtils.assertFileContains(apiFile, "Promise<runtime.ApiResponse<Item>>");
494+
495+
// No Null.ts model should be generated
496+
TestUtils.assertFileNotExists(Paths.get(output + "/models/Null.ts"));
497+
// Item model should still exist
498+
TestUtils.assertFileExists(Paths.get(output + "/models/Item.ts"));
499+
}
500+
472501
@Test(description = "Verify validationAttributes works with withoutRuntimeChecks=true")
473502
public void testValidationAttributesWithWithoutRuntimeChecks() throws IOException {
474503
Map<String, Object> properties = new HashMap<>();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
openapi: 3.1.0
2+
info:
3+
version: 1.0.0
4+
title: testing null response type conversion to void
5+
paths:
6+
/items/{itemId}:
7+
delete:
8+
tags:
9+
- items
10+
operationId: deleteItem
11+
summary: Delete an item
12+
parameters:
13+
- name: itemId
14+
in: path
15+
required: true
16+
schema:
17+
type: string
18+
responses:
19+
'200':
20+
description: Item deleted successfully
21+
content:
22+
application/json:
23+
schema:
24+
type: 'null'
25+
get:
26+
tags:
27+
- items
28+
operationId: getItem
29+
summary: Get an item by ID
30+
parameters:
31+
- name: itemId
32+
in: path
33+
required: true
34+
schema:
35+
type: string
36+
responses:
37+
'200':
38+
description: OK
39+
content:
40+
application/json:
41+
schema:
42+
$ref: '#/components/schemas/Item'
43+
components:
44+
schemas:
45+
Item:
46+
type: object
47+
properties:
48+
id:
49+
type: string
50+
name:
51+
type: string
52+
required:
53+
- id
54+
- name

0 commit comments

Comments
 (0)