1717
1818package org .openapitools .codegen .languages ;
1919
20- import com .google .common .collect .ImmutableMap ;
20+ import io .swagger .v3 .oas .models .Operation ;
21+ import java .io .File ;
22+ import java .util .ArrayList ;
23+ import java .util .EnumSet ;
24+ import java .util .HashMap ;
25+ import java .util .HashSet ;
26+ import java .util .List ;
27+ import java .util .Map ;
28+ import java .util .Objects ;
29+ import java .util .Set ;
2130import lombok .Getter ;
2231import lombok .Setter ;
2332import org .apache .commons .lang3 .StringUtils ;
24- import org .openapitools .codegen .*;
33+ import org .openapitools .codegen .CodegenConstants ;
34+ import org .openapitools .codegen .CodegenDiscriminator ;
35+ import org .openapitools .codegen .CodegenModel ;
36+ import org .openapitools .codegen .CodegenOperation ;
37+ import org .openapitools .codegen .CodegenParameter ;
38+ import org .openapitools .codegen .CodegenProperty ;
39+ import org .openapitools .codegen .CodegenResponse ;
40+ import org .openapitools .codegen .CodegenType ;
41+ import org .openapitools .codegen .SupportingFile ;
2542import org .openapitools .codegen .languages .features .BeanValidationFeatures ;
26- import org .openapitools .codegen .meta .features .*;
43+ import org .openapitools .codegen .meta .features .DocumentationFeature ;
44+ import org .openapitools .codegen .meta .features .GlobalFeature ;
45+ import org .openapitools .codegen .meta .features .ParameterFeature ;
46+ import org .openapitools .codegen .meta .features .SchemaSupportFeature ;
47+ import org .openapitools .codegen .meta .features .SecurityFeature ;
48+ import org .openapitools .codegen .meta .features .WireFormatFeature ;
2749import org .openapitools .codegen .model .ModelMap ;
2850import org .openapitools .codegen .model .ModelsMap ;
2951import org .openapitools .codegen .model .OperationMap ;
3355import org .slf4j .Logger ;
3456import org .slf4j .LoggerFactory ;
3557
36- import java .io .File ;
37- import java .util .*;
58+ import static org .openapitools .codegen .languages .KotlinServerCodegen .Constants .USE_TAGS ;
3859
3960public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures {
4061
@@ -64,7 +85,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
6485 private Boolean metricsFeatureEnabled = true ;
6586 private boolean interfaceOnly = false ;
6687 private boolean useBeanValidation = false ;
67- private boolean useTags = false ;
88+ private boolean useTags = true ;
6889 private boolean useCoroutines = false ;
6990 private boolean useMutiny = false ;
7091 private boolean returnResponse = false ;
@@ -74,38 +95,6 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
7495 @ Setter
7596 private boolean fixJacksonJsonTypeInfoInheritance = true ;
7697
77- // This is here to potentially warn the user when an option is not supported by the target framework.
78- private Map <String , List <String >> optionsSupportedPerFramework = new ImmutableMap .Builder <String , List <String >>()
79- .put (Constants .KTOR , Arrays .asList (
80- Constants .AUTOMATIC_HEAD_REQUESTS ,
81- Constants .CONDITIONAL_HEADERS ,
82- Constants .HSTS ,
83- Constants .CORS ,
84- Constants .COMPRESSION ,
85- Constants .RESOURCES ,
86- Constants .METRICS ,
87- Constants .OMIT_GRADLE_WRAPPER
88- ))
89- .put (Constants .KTOR2 , Arrays .asList (
90- Constants .AUTOMATIC_HEAD_REQUESTS ,
91- Constants .CONDITIONAL_HEADERS ,
92- Constants .HSTS ,
93- Constants .CORS ,
94- Constants .COMPRESSION ,
95- Constants .RESOURCES ,
96- Constants .METRICS ,
97- Constants .OMIT_GRADLE_WRAPPER
98- ))
99- .put (Constants .JAXRS_SPEC , Arrays .asList (
100- USE_BEANVALIDATION ,
101- USE_TAGS ,
102- Constants .USE_COROUTINES ,
103- Constants .USE_MUTINY ,
104- Constants .RETURN_RESPONSE ,
105- Constants .INTERFACE_ONLY
106- ))
107- .build ();
108-
10998 /**
11099 * Constructs an instance of `KotlinServerCodegen`.
111100 */
@@ -172,7 +161,7 @@ public KotlinServerCodegen() {
172161 addSwitch (Constants .METRICS , Constants .METRICS_DESC , getMetricsFeatureEnabled ());
173162 addSwitch (Constants .INTERFACE_ONLY , Constants .INTERFACE_ONLY_DESC , interfaceOnly );
174163 addSwitch (USE_BEANVALIDATION , Constants .USE_BEANVALIDATION_DESC , useBeanValidation );
175- addSwitch (USE_TAGS , USE_TAGS_DESC , useTags );
164+ addSwitch (USE_TAGS , Constants . USE_TAGS_DESC , useTags );
176165 addSwitch (Constants .USE_COROUTINES , Constants .USE_COROUTINES_DESC , useCoroutines );
177166 addSwitch (Constants .USE_MUTINY , Constants .USE_MUTINY_DESC , useMutiny );
178167 addSwitch (Constants .RETURN_RESPONSE , Constants .RETURN_RESPONSE_DESC , returnResponse );
@@ -405,6 +394,8 @@ public static class Constants {
405394 public static final String IS_KTOR = "isKtor" ;
406395 public static final String FIX_JACKSON_JSON_TYPE_INFO_INHERITANCE = "fixJacksonJsonTypeInfoInheritance" ;
407396 public static final String FIX_JACKSON_JSON_TYPE_INFO_INHERITANCE_DESC = "When true (default), ensures Jackson polymorphism works correctly by: (1) always setting visible=true on @JsonTypeInfo, and (2) adding the discriminator property to child models with appropriate default values. When false, visible is only set to true if all children already define the discriminator property." ;
397+ public static final String USE_TAGS = "useTags" ;
398+ public static final String USE_TAGS_DESC = "use tags for creating interface and controller classnames." ;
408399 }
409400
410401 @ Override
@@ -702,32 +693,40 @@ public void postProcess() {
702693 System .out .println ("################################################################################" );
703694 }
704695
696+ @ Override
697+ public void addOperationToGroup (String tag , String resourcePath , Operation operation , CodegenOperation co , Map <String , List <CodegenOperation >> operations ) {
698+ if (useTags ) {
699+ super .addOperationToGroup (tag , resourcePath , operation , co , operations );
700+ return ;
701+ }
702+
703+ String basePath = StringUtils .substringBefore (resourcePath .startsWith ("/" ) ? resourcePath .substring (1 ) : resourcePath , "/" );
704+ if (StringUtils .isEmpty (basePath ) || basePath .chars ().anyMatch (ch -> ch == '{' || ch == '}' )) {
705+ basePath = "default" ;
706+ }
707+ super .addOperationToGroup (basePath , resourcePath , operation , co , operations );
708+ }
709+
705710 @ Override
706711 public OperationsMap postProcessOperationsWithModels (OperationsMap objs , List <ModelMap > allModels ) {
707712 OperationMap operations = objs .getOperations ();
708- // For JAXRS_SPEC library, compute commonPath when useTags=true, otherwise default to "/"
713+ // For JAXRS_SPEC library, compute commonPath for all library modes
709714 if (operations != null && Objects .equals (library , Constants .JAXRS_SPEC )) {
710- if (useTags ) {
711- String commonPath = null ;
712- List <CodegenOperation > ops = operations .getOperation ();
713- for (CodegenOperation operation : ops ) {
714- if (commonPath == null ) {
715- commonPath = operation .path ;
716- } else {
717- commonPath = getCommonPath (commonPath , operation .path );
718- }
719- }
720- for (CodegenOperation co : ops ) {
721- co .path = StringUtils .removeStart (co .path , commonPath );
722- co .subresourceOperation = co .path .length () > 1 ;
723- }
724- objs .put ("commonPath" , "/" .equals (commonPath ) ? StringUtils .EMPTY : commonPath );
725- } else {
726- for (CodegenOperation co : operations .getOperation ()) {
727- co .subresourceOperation = !co .path .isEmpty ();
715+ List <CodegenOperation > ops = operations .getOperation ();
716+ // Compute commonPath from operations in this group (called once per API class)
717+ String commonPath = null ;
718+ for (CodegenOperation operation : ops ) {
719+ if (commonPath == null ) {
720+ commonPath = operation .path ;
721+ } else {
722+ commonPath = getCommonPath (commonPath , operation .path );
728723 }
729- objs .put ("commonPath" , "/" );
730724 }
725+ for (CodegenOperation co : ops ) {
726+ co .path = StringUtils .removeStart (co .path , commonPath );
727+ co .subresourceOperation = co .path .length () > 1 ;
728+ }
729+ objs .put ("commonPath" , "/" .equals (commonPath ) ? StringUtils .EMPTY : commonPath );
731730 }
732731 // The following processing breaks the JAX-RS spec, so we only do this for the other libs.
733732 if (operations != null && !Objects .equals (library , Constants .JAXRS_SPEC )) {
@@ -801,8 +800,8 @@ private boolean isJavalin() {
801800 */
802801 private boolean usesJacksonSerialization () {
803802 return Constants .JAVALIN5 .equals (library ) ||
804- Constants .JAVALIN6 .equals (library ) ||
805- Constants .JAXRS_SPEC .equals (library );
803+ Constants .JAVALIN6 .equals (library ) ||
804+ Constants .JAXRS_SPEC .equals (library );
806805 }
807806
808807 private boolean isKtor2Or3 () {
0 commit comments