Skip to content

Commit 911fe67

Browse files
committed
Fix test: scope RequestOpts assertion to interface section
The previous test used indexOf("}") to find the interface end, which matched the } inside @throws {RequiredError} JSDoc instead of the actual closing brace. Use the class declaration position as the boundary instead.
1 parent 9b2afbc commit 911fe67

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,18 @@ public void testRequestOptsInInterfaceByDefault() throws IOException {
468468
Path apiFile = Paths.get(output + "/apis/PetControllerApi.ts");
469469
TestUtils.assertFileExists(apiFile);
470470

471+
// Read file content and split into interface and class sections
472+
String content = new String(Files.readAllBytes(apiFile));
473+
int interfaceStart = content.indexOf("export interface PetControllerApiInterface");
474+
int classStart = content.indexOf("export class PetControllerApi");
475+
String interfaceSection = content.substring(interfaceStart, classStart);
476+
471477
// Interface should contain RequestOpts methods
472-
TestUtils.assertFileContains(apiFile, "export interface PetControllerApiInterface");
473-
TestUtils.assertFileContains(apiFile, "addPetRequestOpts(");
478+
assertThat(interfaceSection).contains("addPetRequestOpts(");
474479

475480
// Class should also contain RequestOpts methods
476-
TestUtils.assertFileContains(apiFile, "async addPetRequestOpts(");
481+
String classSection = content.substring(classStart);
482+
assertThat(classSection).contains("async addPetRequestOpts(");
477483
}
478484

479485
@Test(description = "Verify withRequestOptsInInterface=false excludes RequestOpts from interface but keeps them on class")
@@ -490,14 +496,13 @@ public void testRequestOptsNotInInterfaceWhenDisabled() throws IOException {
490496
// Read file content and split into interface and class sections
491497
String content = new String(Files.readAllBytes(apiFile));
492498
int interfaceStart = content.indexOf("export interface PetControllerApiInterface");
493-
int interfaceEnd = content.indexOf("}", interfaceStart);
494-
String interfaceSection = content.substring(interfaceStart, interfaceEnd);
499+
int classStart = content.indexOf("export class PetControllerApi");
500+
String interfaceSection = content.substring(interfaceStart, classStart);
495501

496502
// Interface should NOT contain RequestOpts methods
497503
assertThat(interfaceSection).doesNotContain("RequestOpts");
498504

499505
// Class should still contain RequestOpts methods
500-
int classStart = content.indexOf("export class PetControllerApi");
501506
String classSection = content.substring(classStart);
502507
assertThat(classSection).contains("async addPetRequestOpts(");
503508
}

0 commit comments

Comments
 (0)