forked from loafle/openapi-generator-original
Issue 5497: Support the use of tags in the delegated Spring Kotlin generator. (#5499)
Co-authored-by: Jim Schubert <james.schubert@gmail.com>
This commit is contained in:
parent
7baa72eefa
commit
057c4294de
@ -33,6 +33,7 @@ sidebar_label: kotlin-spring
|
||||
|swaggerAnnotations|generate swagger annotations to go alongside controllers and models| |false|
|
||||
|title|server title name or client service name| |OpenAPI Kotlin Spring|
|
||||
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
|
||||
|useTags|Whether to use tags for creating interface and controller class names| |false|
|
||||
|
||||
## IMPORT MAPPING
|
||||
|
||||
|
@ -66,6 +66,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
public static final String REACTIVE = "reactive";
|
||||
public static final String INTERFACE_ONLY = "interfaceOnly";
|
||||
public static final String DELEGATE_PATTERN = "delegatePattern";
|
||||
public static final String USE_TAGS = "useTags";
|
||||
|
||||
private String basePackage;
|
||||
private String invokerPackage;
|
||||
@ -81,6 +82,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
private boolean reactive = false;
|
||||
private boolean interfaceOnly = false;
|
||||
private boolean delegatePattern = false;
|
||||
protected boolean useTags = false;
|
||||
|
||||
public KotlinSpringServerCodegen() {
|
||||
super();
|
||||
@ -152,6 +154,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
addSwitch(REACTIVE, "use coroutines for reactive behavior", reactive);
|
||||
addSwitch(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly);
|
||||
addSwitch(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern);
|
||||
addSwitch(USE_TAGS, "Whether to use tags for creating interface and controller class names", useTags);
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
|
||||
setLibrary(SPRING_BOOT);
|
||||
|
||||
@ -245,6 +248,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
this.delegatePattern = delegatePattern;
|
||||
}
|
||||
|
||||
public void setUseTags(boolean useTags) {
|
||||
this.useTags = useTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
@ -369,6 +376,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_TAGS)) {
|
||||
this.setUseTags(Boolean.parseBoolean(additionalProperties.get(USE_TAGS).toString()));
|
||||
}
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".kt");
|
||||
|
||||
if (!this.interfaceOnly && this.delegatePattern) {
|
||||
@ -440,7 +451,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
if (library.equals(SPRING_BOOT) && this.delegatePattern) {
|
||||
if (library.equals(SPRING_BOOT) && !useTags) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.openapitools.codegen.kotlin.spring;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.collect.testing.Helpers;
|
||||
import io.swagger.parser.OpenAPIParser;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
@ -21,6 +22,7 @@ import org.testng.annotations.Test;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class KotlinSpringServerCodegenTest {
|
||||
|
||||
@ -183,4 +185,28 @@ public class KotlinSpringServerCodegenTest {
|
||||
|
||||
Assert.assertTrue(codegen.supportingFiles().stream().anyMatch(supportingFile -> supportingFile.templateFile.equals("apiUtil.mustache")));
|
||||
}
|
||||
|
||||
@Test(description = "test delegate with tags")
|
||||
public void delegateWithTags() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); //may be move to /build
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true);
|
||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true);
|
||||
|
||||
List<File> files = new DefaultGenerator()
|
||||
.opts(
|
||||
new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue5497-use-tags-kotlin.yaml"))
|
||||
.config(codegen)
|
||||
)
|
||||
.generate();
|
||||
|
||||
Helpers.assertContainsAllOf(files,
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"),
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiController.kt"),
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
openapi: "3.0.1"
|
||||
info:
|
||||
title: test
|
||||
version: "1.0"
|
||||
|
||||
paths:
|
||||
|
||||
/api/v1/test:
|
||||
get:
|
||||
tags: [Test v1]
|
||||
operationId: test1
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
|
||||
/api/v2/test:
|
||||
get:
|
||||
tags: [Test v2]
|
||||
operationId: test2
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
@ -1 +1 @@
|
||||
4.3.1-SNAPSHOT
|
||||
4.3.1-SNAPSHOT
|
||||
|
@ -39,7 +39,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Pet", description = "The Pet API")
|
||||
@Api(value = "pet", description = "The pet API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class PetApiController(@Autowired(required = true) val service: PetApiService) {
|
||||
|
||||
|
@ -38,7 +38,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Store", description = "The Store API")
|
||||
@Api(value = "store", description = "The store API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class StoreApiController(@Autowired(required = true) val service: StoreApiService) {
|
||||
|
||||
|
@ -38,7 +38,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "User", description = "The User API")
|
||||
@Api(value = "user", description = "The user API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class UserApiController(@Autowired(required = true) val service: UserApiService) {
|
||||
|
||||
|
@ -40,7 +40,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Pet", description = "The Pet API")
|
||||
@Api(value = "pet", description = "The pet API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class PetApiController(@Autowired(required = true) val service: PetApiService) {
|
||||
|
||||
|
@ -39,7 +39,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Store", description = "The Store API")
|
||||
@Api(value = "store", description = "The store API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class StoreApiController(@Autowired(required = true) val service: StoreApiService) {
|
||||
|
||||
|
@ -39,7 +39,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "User", description = "The User API")
|
||||
@Api(value = "user", description = "The user API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class UserApiController(@Autowired(required = true) val service: UserApiService) {
|
||||
|
||||
|
@ -39,7 +39,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Pet", description = "The Pet API")
|
||||
@Api(value = "pet", description = "The pet API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class PetApiController(@Autowired(required = true) val service: PetApiService) {
|
||||
|
||||
|
@ -38,7 +38,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "Store", description = "The Store API")
|
||||
@Api(value = "store", description = "The store API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class StoreApiController(@Autowired(required = true) val service: StoreApiService) {
|
||||
|
||||
|
@ -38,7 +38,7 @@ import kotlin.collections.Map
|
||||
|
||||
@RestController
|
||||
@Validated
|
||||
@Api(value = "User", description = "The User API")
|
||||
@Api(value = "user", description = "The user API")
|
||||
@RequestMapping("\${api.base-path:/v2}")
|
||||
class UserApiController(@Autowired(required = true) val service: UserApiService) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user