3030import org .openapitools .codegen .*;
3131import org .openapitools .codegen .model .ModelMap ;
3232import org .openapitools .codegen .model .ModelsMap ;
33+ import org .openapitools .codegen .model .OperationsMap ;
3334import org .openapitools .codegen .templating .mustache .EscapeChar ;
3435import org .openapitools .codegen .utils .ModelUtils ;
3536import org .slf4j .Logger ;
@@ -66,6 +67,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
6667 public static final String SCHEMA_IMPLEMENTS_FIELDS = "schemaImplementsFields" ;
6768 public static final String X_KOTLIN_IMPLEMENTS_SKIP = "xKotlinImplementsSkip" ;
6869 public static final String X_KOTLIN_IMPLEMENTS_FIELDS_SKIP = "xKotlinImplementsFieldsSkip" ;
70+ public static final String IMPLICIT_HEADERS = "implicitHeaders" ;
6971
7072 private final Logger LOGGER = LoggerFactory .getLogger (AbstractKotlinCodegen .class );
7173
@@ -81,6 +83,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
8183
8284 protected String apiDocPath = "docs/" ;
8385 protected String modelDocPath = "docs/" ;
86+ @ Setter
8487 protected boolean parcelizeModels = false ;
8588 @ Getter @ Setter
8689 protected boolean serializableModel = false ;
@@ -111,6 +114,8 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
111114 @ Getter
112115 @ Setter
113116 protected Map <String , List <String >> xKotlinImplementsFieldsSkip = new HashMap <>();
117+ @ Setter
118+ protected boolean implicitHeaders = false ;
114119
115120 public AbstractKotlinCodegen () {
116121 super ();
@@ -294,6 +299,7 @@ public AbstractKotlinCodegen() {
294299
295300 cliOptions .add (CliOption .newBoolean (MODEL_MUTABLE , MODEL_MUTABLE_DESC , false ));
296301 cliOptions .add (CliOption .newString (ADDITIONAL_MODEL_TYPE_ANNOTATIONS , "Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)" ));
302+ cliOptions .add (CliOption .newBoolean (IMPLICIT_HEADERS , "Skip header parameters in the generated API methods." , implicitHeaders ));
297303 }
298304
299305 @ Override
@@ -451,6 +457,43 @@ public ModelsMap postProcessModels(ModelsMap objs) {
451457 return postProcessModelsEnum (objs );
452458 }
453459
460+ @ Override
461+ public OperationsMap postProcessOperationsWithModels (OperationsMap objs , List <ModelMap > allModels ) {
462+ handleImplicitHeaders (objs );
463+ return objs ;
464+ }
465+
466+ protected void handleImplicitHeaders (OperationsMap objs ) {
467+ if (!implicitHeaders ) {
468+ return ;
469+ }
470+
471+ objs .getOperations ().getOperation ().forEach (this ::handleImplicitHeaders );
472+ }
473+
474+ /**
475+ * This method removes all implicit header parameters from the list of parameters
476+ *
477+ * @param operation - operation to be processed
478+ */
479+ private void handleImplicitHeaders (CodegenOperation operation ) {
480+ if (operation .allParams .isEmpty ()) {
481+ return ;
482+ }
483+ final ArrayList <CodegenParameter > copy = new ArrayList <>(operation .allParams );
484+ operation .allParams .clear ();
485+
486+ for (CodegenParameter p : copy ) {
487+ if (p .isHeaderParam ) {
488+ operation .implicitHeadersParams .add (p );
489+ operation .headerParams .removeIf (header -> header .baseName .equals (p .baseName ));
490+ LOGGER .debug ("Update operation [{}]. Remove header [{}] because it's marked to be implicit" , operation .operationId , p .baseName );
491+ } else {
492+ operation .allParams .add (p );
493+ }
494+ }
495+ }
496+
454497 @ Override
455498 public void processOpts () {
456499 super .processOpts ();
@@ -587,20 +630,14 @@ public void processOpts() {
587630 } else {
588631 applyJackson2Package ();
589632 }
633+
634+ convertPropertyToBooleanAndWriteBack (IMPLICIT_HEADERS , this ::setImplicitHeaders );
590635 }
591636
592637 protected boolean isModelMutable () {
593638 return Boolean .TRUE .equals (additionalProperties .get (MODEL_MUTABLE ));
594639 }
595640
596- public Boolean getParcelizeModels () {
597- return parcelizeModels ;
598- }
599-
600- public void setParcelizeModels (Boolean parcelizeModels ) {
601- this .parcelizeModels = parcelizeModels ;
602- }
603-
604641 public boolean nonPublicApi () {
605642 return nonPublicApi ;
606643 }
0 commit comments