Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import java.util.Optional;
{{#async}}
import java.util.concurrent.CompletableFuture;
{{/async}}
{{#returnSuccessCode}}
import java.util.concurrent.atomic.AtomicInteger;
{{/returnSuccessCode}}
import {{javaxPackage}}.annotation.Generated;

{{#operations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5575,4 +5575,36 @@ public void testGenericReturnTypeWhenNotUsingResponseEntity_issue1096() throws I
.toFileAssert()
.assertMethod("findPetsByStatus").hasReturnType("List<Pet>");
}

@Test
public void testHasRestControllerDoesNotHaveController_issue21156() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_1/issue_21156.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());
codegen.setLibrary("spring-boot");

codegen.additionalProperties().put(INTERFACE_ONLY, "false");
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
codegen.additionalProperties().put(SPRING_CONTROLLER, "true");
codegen.additionalProperties().put(RETURN_SUCCESS_CODE, "true");

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();
generator.setGenerateMetadata(false); // skip metadata generation
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");

Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("TestApiDelegate.java"));
javaFileAssert
.hasImports("java.util.concurrent.atomic.AtomicInteger");
}
}
45 changes: 45 additions & 0 deletions modules/openapi-generator/src/test/resources/3_1/issue_21156.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
openapi: 3.1.1
info:
title: Test Bug
version: 1.0.0
servers:
- url: https://where.am.i
paths:
/test/bug:
post:
operationId: testRequest
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/TestRequest'
responses:
'200':
description: Test request successful
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'500':
$ref: '#/components/responses/InternalServerError'
components:
schemas:
TestRequest:
properties:
test:
type: string
TestResponse:
properties:
test:
type: string
ErrorResponse:
properties:
error:
type: string
responses:
InternalServerError:
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Internal server error
Loading