[Java][Spring] fix reactive method with only implicit headers (#15019) (fix #14907)

This commit is contained in:
Oleh Kurpiak
2023-03-24 11:32:04 +02:00
committed by GitHub
parent a601002451
commit d1f92acaea
3 changed files with 86 additions and 0 deletions

View File

@@ -2287,6 +2287,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
operation.allParams.add(p);
}
}
operation.hasParams = !operation.allParams.isEmpty();
}
private boolean shouldBeImplicitHeader(CodegenParameter parameter) {

View File

@@ -915,6 +915,37 @@ public class SpringCodegenTest {
assertFileNotContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/SomeApiDelegate.java"), "Mono<DummyRequest>");
}
@Test
public void shouldGenerateValidCodeForReactiveControllerWithoutParams_issue14907() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/bugs/issue_14907.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(SpringCodegen.REACTIVE, "true");
codegen.additionalProperties().put(USE_TAGS, "true");
codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8");
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
codegen.additionalProperties().put(SKIP_DEFAULT_INTERFACE, "true");
codegen.additionalProperties().put(IMPLICIT_HEADERS, "true");
codegen.additionalProperties().put(OPENAPI_NULLABLE, "false");
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));
JavaFileAssert.assertThat(files.get("ConsentControllerApi.java"))
.assertMethod("readAgreements", "ServerWebExchange");
}
@Test
public void shouldEscapeReservedKeyWordsForRequestParameters_7506_Regression() throws Exception {
final SpringCodegen codegen = new SpringCodegen();

View File

@@ -0,0 +1,54 @@
openapi: 3.0.1
info:
title: TEST
description: |-
## TEST
version: 1.0.0
servers:
- url: /v3
description: Major version of service
tags:
- name: consent-controller
description: Consent API
paths:
/agreements:
parameters:
- $ref: '#/components/parameters/x-client-ismobile'
get:
tags:
- consent-controller
operationId: readAgreements
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/ListResponseResponseAgreement'
components:
schemas:
ResponseAgreement:
type: object
properties:
agreementId:
type: string
ListResponseResponseAgreement:
type: object
properties:
list:
type: array
items:
$ref: '#/components/schemas/ResponseAgreement'
parameters:
x-client-ismobile:
name: x-client-ismobile
in: header
description: |
blabla
schema:
type: boolean
required: false