forked from loafle/openapi-generator-original
[Kotlin][Spring]ctbarnev_bugfix-13488-remove-request-mapping-from-for-Kotlin-spring-c… (#15898)
* ctbarnev_bugfix-13488-remove-request-mapping-from-for-Kotlin-spring-cloud * ctbarnev_bugfix-13488-remove-request-mapping-from-for-Kotlin-spring-cloud * Undo formatting code * Undo formatting code * Undo formatting code * ctbarnev_bugfix-13488-remove-request-mapping-from-for-Kotlin-spring-cloud * Undo formatting code * Undo formatting code * Cleanup --------- Co-authored-by: c.t.vanbarneveld <corne.van.barneveld@rws.nl>
This commit is contained in:
parent
b1b8acee48
commit
b2280e23f7
@ -95,6 +95,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
public static final String REACTIVE = "reactive";
|
||||
public static final String INTERFACE_ONLY = "interfaceOnly";
|
||||
public static final String USE_FEIGN_CLIENT_URL = "useFeignClientUrl";
|
||||
public static final String USE_FEIGN_CLIENT = "useFeignClient";
|
||||
public static final String DELEGATE_PATTERN = "delegatePattern";
|
||||
public static final String USE_TAGS = "useTags";
|
||||
public static final String BEAN_QUALIFIERS = "beanQualifiers";
|
||||
@ -116,6 +117,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
private boolean reactive = false;
|
||||
private boolean interfaceOnly = false;
|
||||
protected boolean useFeignClientUrl = true;
|
||||
protected boolean useFeignClient = false;
|
||||
private boolean delegatePattern = false;
|
||||
protected boolean useTags = false;
|
||||
private boolean beanQualifiers = false;
|
||||
@ -388,6 +390,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
public void setUseFeignClient( boolean useFeignClient ) {
|
||||
this.useFeignClient = useFeignClient;
|
||||
}
|
||||
|
||||
public void setSkipDefaultInterface(boolean skipDefaultInterface) {
|
||||
this.skipDefaultInterface = skipDefaultInterface;
|
||||
}
|
||||
@ -585,6 +591,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
|
||||
if (library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
this.setInterfaceOnly(true);
|
||||
this.setUseFeignClient(true);
|
||||
additionalProperties.put(USE_FEIGN_CLIENT, true);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_FEIGN_CLIENT_URL)) {
|
||||
|
@ -58,9 +58,11 @@ import kotlin.collections.Map
|
||||
{{#swagger1AnnotationLibrary}}
|
||||
@Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API")
|
||||
{{/swagger1AnnotationLibrary}}
|
||||
{{^useFeignClient}}
|
||||
{{=<% %>=}}
|
||||
@RequestMapping("\${api.base-path:<%contextPath%>}")
|
||||
<%={{ }}=%>
|
||||
{{/useFeignClient}}
|
||||
{{#operations}}
|
||||
interface {{classname}} {
|
||||
{{#isDelegate}}
|
||||
|
@ -77,6 +77,26 @@ public class KotlinSpringServerCodegenTest {
|
||||
Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRequestMappingAnnotation() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.setLibrary("spring-cloud");
|
||||
|
||||
new DefaultGenerator().opts(new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/feat13488_use_kotlinSpring_with_springCloud.yaml"))
|
||||
.config(codegen))
|
||||
.generate();
|
||||
|
||||
// Check that the @RequestMapping annotation is not generated in the Api file
|
||||
assertFileNotContains(
|
||||
Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
||||
"@RequestMapping(\"\\${api.base-path"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettersForConfigValues() throws Exception {
|
||||
|
@ -0,0 +1,19 @@
|
||||
openapi: "3.0.1"
|
||||
info:
|
||||
title: test
|
||||
version: "1.0"
|
||||
|
||||
paths:
|
||||
|
||||
/api/v1/test/{id}:
|
||||
get:
|
||||
tags: [Test v1]
|
||||
operationId: test1
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
@ -30,7 +30,6 @@ import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Validated
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
interface PetApi {
|
||||
|
||||
|
||||
|
@ -29,7 +29,6 @@ import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Validated
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
interface StoreApi {
|
||||
|
||||
|
||||
|
@ -29,7 +29,6 @@ import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Validated
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
interface UserApi {
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user