Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -388,6 +390,10 @@ public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

public void setUseFeignClient( boolean useFeignClient ) {
this.useFeignClient = useFeignClient;
}

public void setSkipDefaultInterface(boolean skipDefaultInterface) {
this.skipDefaultInterface = skipDefaultInterface;
}
Expand Down Expand Up @@ -585,6 +591,8 @@ public void processOpts() {

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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ public void testInitialConfigValues() throws Exception {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import kotlin.collections.List
import kotlin.collections.Map

@Validated
@RequestMapping("\${api.base-path:/v2}")
interface PetApi {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kotlin.collections.List
import kotlin.collections.Map

@Validated
@RequestMapping("\${api.base-path:/v2}")
interface StoreApi {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kotlin.collections.List
import kotlin.collections.Map

@Validated
@RequestMapping("\${api.base-path:/v2}")
interface UserApi {


Expand Down