Class AbstractMicronautKotlinCodegen<T extends GeneratorOptionsBuilder>

java.lang.Object
org.openapitools.codegen.DefaultCodegen
org.openapitools.codegen.languages.AbstractKotlinCodegen
io.micronaut.openapi.generator.AbstractMicronautKotlinCodegen<T>
Type Parameters:
T - The generator options builder.
All Implemented Interfaces:
MicronautCodeGenerator<T>, org.openapitools.codegen.CodegenConfig, org.openapitools.codegen.languages.features.BeanValidationFeatures
Direct Known Subclasses:
KotlinMicronautClientCodegen, KotlinMicronautServerCodegen

public abstract class AbstractMicronautKotlinCodegen<T extends GeneratorOptionsBuilder> extends org.openapitools.codegen.languages.AbstractKotlinCodegen implements org.openapitools.codegen.languages.features.BeanValidationFeatures, MicronautCodeGenerator<T>
Base generator for Micronaut.
  • Field Details

    • OPT_TITLE

      public static final String OPT_TITLE
      See Also:
    • OPT_TEST

      public static final String OPT_TEST
      See Also:
    • OPT_TEST_JUNIT

      public static final String OPT_TEST_JUNIT
      See Also:
    • OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR

      public static final String OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR
      See Also:
    • OPT_USE_AUTH

      public static final String OPT_USE_AUTH
      See Also:
    • OPT_USE_PLURAL

      public static final String OPT_USE_PLURAL
      See Also:
    • OPT_FLUX_FOR_ARRAYS

      public static final String OPT_FLUX_FOR_ARRAYS
      See Also:
    • OPT_GENERATED_ANNOTATION

      public static final String OPT_GENERATED_ANNOTATION
      See Also:
    • OPT_VISITABLE

      public static final String OPT_VISITABLE
      See Also:
    • OPT_DATE_LIBRARY_ZONED_DATETIME

      public static final String OPT_DATE_LIBRARY_ZONED_DATETIME
      See Also:
    • OPT_DATE_LIBRARY_OFFSET_DATETIME

      public static final String OPT_DATE_LIBRARY_OFFSET_DATETIME
      See Also:
    • OPT_DATE_LIBRARY_LOCAL_DATETIME

      public static final String OPT_DATE_LIBRARY_LOCAL_DATETIME
      See Also:
    • OPT_DATE_FORMAT

      public static final String OPT_DATE_FORMAT
      See Also:
    • OPT_DATE_TIME_FORMAT

      public static final String OPT_DATE_TIME_FORMAT
      See Also:
    • OPT_REACTIVE

      public static final String OPT_REACTIVE
      See Also:
    • OPT_GENERATE_HTTP_RESPONSE_ALWAYS

      public static final String OPT_GENERATE_HTTP_RESPONSE_ALWAYS
      See Also:
    • OPT_GENERATE_HTTP_RESPONSE_WHERE_REQUIRED

      public static final String OPT_GENERATE_HTTP_RESPONSE_WHERE_REQUIRED
      See Also:
    • OPT_APPLICATION_NAME

      public static final String OPT_APPLICATION_NAME
      See Also:
    • OPT_GENERATE_SWAGGER_ANNOTATIONS

      public static final String OPT_GENERATE_SWAGGER_ANNOTATIONS
      See Also:
    • OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2

      public static final String OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2
      See Also:
    • OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE

      public static final String OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE
      See Also:
    • OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE

      public static final String OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE
      See Also:
    • OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG

      public static final String OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG
      See Also:
    • OPT_IMPLICIT_HEADERS

      public static final String OPT_IMPLICIT_HEADERS
      See Also:
    • OPT_IMPLICIT_HEADERS_REGEX

      public static final String OPT_IMPLICIT_HEADERS_REGEX
      See Also:
    • OPT_USE_ENUM_CASE_INSENSITIVE

      public static final String OPT_USE_ENUM_CASE_INSENSITIVE
      See Also:
    • OPT_KSP

      public static final String OPT_KSP
      See Also:
    • ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS

      public static final String ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS
      See Also:
    • ADDITIONAL_ENUM_TYPE_ANNOTATIONS

      public static final String ADDITIONAL_ENUM_TYPE_ANNOTATIONS
      See Also:
    • CONTENT_TYPE_APPLICATION_FORM_URLENCODED

      public static final String CONTENT_TYPE_APPLICATION_FORM_URLENCODED
      See Also:
    • CONTENT_TYPE_APPLICATION_JSON

      public static final String CONTENT_TYPE_APPLICATION_JSON
      See Also:
    • CONTENT_TYPE_MULTIPART_FORM_DATA

      public static final String CONTENT_TYPE_MULTIPART_FORM_DATA
      See Also:
    • CONTENT_TYPE_ANY

      public static final String CONTENT_TYPE_ANY
      See Also:
    • random

      protected SecureRandom random
    • dateLibrary

      protected String dateLibrary
    • title

      protected String title
    • useBeanValidation

      protected boolean useBeanValidation
    • visitable

      protected boolean visitable
    • plural

      protected boolean plural
    • fluxForArrays

      protected boolean fluxForArrays
    • generatedAnnotation

      protected boolean generatedAnnotation
    • testTool

      protected String testTool
    • requiredPropertiesInConstructor

      protected boolean requiredPropertiesInConstructor
    • reactive

      protected boolean reactive
    • generateHttpResponseAlways

      protected boolean generateHttpResponseAlways
    • generateHttpResponseWhereRequired

      protected boolean generateHttpResponseWhereRequired
    • useEnumCaseInsensitive

      protected boolean useEnumCaseInsensitive
    • ksp

      protected boolean ksp
    • implicitHeaders

      protected boolean implicitHeaders
    • implicitHeadersRegex

      protected String implicitHeadersRegex
    • appName

      protected String appName
    • dateFormat

      protected String dateFormat
    • dateTimeFormat

      protected String dateTimeFormat
    • generateSwaggerAnnotations

      protected String generateSwaggerAnnotations
    • generateOperationOnlyForFirstTag

      protected boolean generateOperationOnlyForFirstTag
    • serializationLibrary

      protected String serializationLibrary
    • parameterMappings

      protected List<ParameterMapping> parameterMappings
    • responseBodyMappings

      protected List<ResponseBodyMapping> responseBodyMappings
    • allModels

      protected Map<String,org.openapitools.codegen.CodegenModel> allModels
    • additionalOneOfTypeAnnotations

      protected List<String> additionalOneOfTypeAnnotations
    • additionalEnumTypeAnnotations

      protected List<String> additionalEnumTypeAnnotations
  • Constructor Details

    • AbstractMicronautKotlinCodegen

      protected AbstractMicronautKotlinCodegen()
  • Method Details

    • setGenerateHttpResponseAlways

      public void setGenerateHttpResponseAlways(boolean generateHttpResponseAlways)
    • setGenerateHttpResponseWhereRequired

      public void setGenerateHttpResponseWhereRequired(boolean generateHttpResponseWhereRequired)
    • setReactive

      public void setReactive(boolean reactive)
    • setImplicitHeaders

      public void setImplicitHeaders(boolean implicitHeaders)
    • setImplicitHeadersRegex

      public void setImplicitHeadersRegex(String implicitHeadersRegex)
    • setTestTool

      public void setTestTool(String testTool)
    • setArtifactId

      public void setArtifactId(String artifactId)
      Overrides:
      setArtifactId in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • setModelPackage

      public void setModelPackage(String modelPackage)
      Overrides:
      setModelPackage in class DefaultCodegen
    • setApiPackage

      public void setApiPackage(String apiPackage)
      Overrides:
      setApiPackage in class DefaultCodegen
    • setPackageName

      public void setPackageName(String packageName)
      Overrides:
      setPackageName in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • setPlural

      public void setPlural(boolean plural)
    • setFluxForArrays

      public void setFluxForArrays(boolean fluxForArrays)
    • setGeneratedAnnotation

      public void setGeneratedAnnotation(boolean generatedAnnotation)
    • setKsp

      public void setKsp(boolean ksp)
    • processOpts

      public void processOpts()
      Specified by:
      processOpts in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      processOpts in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • addParameterMappings

      public void addParameterMappings(List<ParameterMapping> parameterMappings)
    • addResponseBodyMappings

      public void addResponseBodyMappings(List<ResponseBodyMapping> responseBodyMappings)
    • addSchemaMapping

      public void addSchemaMapping(Map<String,String> schemaMapping)
    • addImportMapping

      public void addImportMapping(Map<String,String> importMapping)
    • addNameMapping

      public void addNameMapping(Map<String,String> nameMapping)
    • addTypeMapping

      public void addTypeMapping(Map<String,String> typeMapping)
    • addEnumNameMapping

      public void addEnumNameMapping(Map<String,String> enumNameMapping)
    • addModelNameMapping

      public void addModelNameMapping(Map<String,String> modelNameMapping)
    • addInlineSchemaNameMapping

      public void addInlineSchemaNameMapping(Map<String,String> inlineSchemaNameMapping)
    • addInlineSchemaOption

      public void addInlineSchemaOption(Map<String,String> inlineSchemaOption)
    • addOpenapiNormalizer

      public void addOpenapiNormalizer(Map<String,String> openapiNormalizer)
    • testFileFolder

      public String testFileFolder()
    • isServer

      public abstract boolean isServer()
    • apiTestFileFolder

      public String apiTestFileFolder()
      Specified by:
      apiTestFileFolder in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      apiTestFileFolder in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • modelTestFileFolder

      public String modelTestFileFolder()
      Specified by:
      modelTestFileFolder in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      modelTestFileFolder in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • toApiTestFilename

      public String toApiTestFilename(String name)
      Description copied from class: DefaultCodegen
      Return the file name of the Api Test
      Specified by:
      toApiTestFilename in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      toApiTestFilename in class DefaultCodegen
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toModelTestFilename

      public String toModelTestFilename(String name)
      Description copied from class: DefaultCodegen
      Return the capitalized file name of the model test
      Specified by:
      toModelTestFilename in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      toModelTestFilename in class DefaultCodegen
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • setUseBeanValidation

      public void setUseBeanValidation(boolean useBeanValidation)
      Specified by:
      setUseBeanValidation in interface org.openapitools.codegen.languages.features.BeanValidationFeatures
    • setVisitable

      public void setVisitable(boolean visitable)
    • createDiscriminator

      protected org.openapitools.codegen.CodegenDiscriminator createDiscriminator(String schemaName, io.swagger.v3.oas.models.media.Schema schema)
      Overrides:
      createDiscriminator in class DefaultCodegen
    • toApiVarName

      public String toApiVarName(String name)
      Description copied from class: DefaultCodegen
      Return the variable name in the Api
      Specified by:
      toApiVarName in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      toApiVarName in class DefaultCodegen
      Parameters:
      name - the variable name of the Api
      Returns:
      the snake-cased variable name
    • isVisitable

      public boolean isVisitable()
    • sanitizeTag

      public String sanitizeTag(String tag)
      Description copied from class: DefaultCodegen
      Sanitize tag
      Specified by:
      sanitizeTag in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      sanitizeTag in class DefaultCodegen
      Parameters:
      tag - Tag
      Returns:
      Sanitized tag
    • superSanitizeTag

      public String superSanitizeTag(String tag)
    • toApiName

      public String toApiName(String name)
      Description copied from class: DefaultCodegen
      Output the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is empty
      Specified by:
      toApiName in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      toApiName in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      name - the name of the Api
      Returns:
      capitalized Api name
    • addOperationToGroup

      public void addOperationToGroup(String tag, String resourcePath, io.swagger.v3.oas.models.Operation operation, org.openapitools.codegen.CodegenOperation co, Map<String,List<org.openapitools.codegen.CodegenOperation>> operations)
      Description copied from class: DefaultCodegen
      Add operation to group
      Specified by:
      addOperationToGroup in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      addOperationToGroup in class DefaultCodegen
      Parameters:
      tag - name of the tag
      resourcePath - path of the resource
      operation - OAS Operation object
      co - Codegen Operation object
      operations - map of Codegen operations
    • preprocessOpenAPI

      public void preprocessOpenAPI(io.swagger.v3.oas.models.OpenAPI openApi)
      Specified by:
      preprocessOpenAPI in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      preprocessOpenAPI in class DefaultCodegen
    • postProcessOperationsWithModels

      public org.openapitools.codegen.model.OperationsMap postProcessOperationsWithModels(org.openapitools.codegen.model.OperationsMap objs, List<org.openapitools.codegen.model.ModelMap> allModels)
      Specified by:
      postProcessOperationsWithModels in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      postProcessOperationsWithModels in class DefaultCodegen
    • handleImplicitHeaders

      protected void handleImplicitHeaders(org.openapitools.codegen.CodegenOperation operation)
      This method removes all implicit header parameters from the list of parameters.
      Parameters:
      operation - - operation to be processed
    • toEnumValue

      public String toEnumValue(String value, String datatype)
      Description copied from class: DefaultCodegen
      Return the enum value in the language specified format e.g. status becomes "status"
      Overrides:
      toEnumValue in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized value for enum
    • fromModel

      public org.openapitools.codegen.CodegenModel fromModel(String name, io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegen
      Convert OAS Model object to Codegen Model object.
      Specified by:
      fromModel in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      fromModel in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      name - the name of the model
      schema - OAS Model object
      Returns:
      Codegen Model object
    • getTypeDeclaration

      public String getTypeDeclaration(io.swagger.v3.oas.models.media.Schema p)
      Output the type declaration of the property.
      Specified by:
      getTypeDeclaration in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      getTypeDeclaration in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      p - OpenAPI Property object
      Returns:
      a string presentation of the property type
    • toModelName

      public String toModelName(String name)
      Description copied from class: DefaultCodegen
      Converts the OpenAPI schema name to a model name suitable for the current code generator. May be overridden for each programming language. In case the name belongs to the TypeSystem it won't be renamed.
      Specified by:
      toModelName in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      toModelName in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      name - the name of the model
      Returns:
      capitalized model name
    • fromRequestBody

      public org.openapitools.codegen.CodegenParameter fromRequestBody(io.swagger.v3.oas.models.parameters.RequestBody body, Set<String> imports, String bodyParameterName)
      Overrides:
      fromRequestBody in class DefaultCodegen
    • fromParameter

      public org.openapitools.codegen.CodegenParameter fromParameter(io.swagger.v3.oas.models.parameters.Parameter p, Set<String> imports)
      Description copied from class: DefaultCodegen
      Convert OAS Parameter object to Codegen Parameter object
      Overrides:
      fromParameter in class DefaultCodegen
      Parameters:
      p - OAS parameter object
      imports - set of imports for library/package/module
      Returns:
      Codegen Parameter object
    • fromResponse

      public org.openapitools.codegen.CodegenResponse fromResponse(String responseCode, io.swagger.v3.oas.models.responses.ApiResponse response)
      Description copied from class: DefaultCodegen
      Convert OAS Response object to Codegen Response object
      Overrides:
      fromResponse in class DefaultCodegen
      Parameters:
      responseCode - HTTP response code
      response - OAS Response object
      Returns:
      Codegen Response object
    • fromProperty

      public org.openapitools.codegen.CodegenProperty fromProperty(String name, io.swagger.v3.oas.models.media.Schema schema, boolean required, boolean schemaIsFromAdditionalProperties)
      Description copied from class: DefaultCodegen
      Convert OAS Property object to Codegen Property object.

      The return value is cached. An internal cache is looked up to determine if the CodegenProperty return value has already been instantiated for the (String name, Schema p) arguments. Any subsequent processing of the CodegenModel return value must be idempotent for a given (String name, Schema schema).

      Overrides:
      fromProperty in class DefaultCodegen
      Parameters:
      name - name of the property
      schema - OAS property schema
      required - true if the property is required in the next higher object schema, false otherwise
      schemaIsFromAdditionalProperties - true if the property is a required property defined by additional properties schema If this is the actual additionalProperties schema not defining a required property, then the value should be false
      Returns:
      Codegen Property object
    • fromOperation

      public org.openapitools.codegen.CodegenOperation fromOperation(String path, String httpMethod, io.swagger.v3.oas.models.Operation operation, List<io.swagger.v3.oas.models.servers.Server> servers)
      Description copied from class: DefaultCodegen
      Convert OAS Operation object to Codegen Operation object
      Specified by:
      fromOperation in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      fromOperation in class DefaultCodegen
      Parameters:
      path - the path of the operation
      httpMethod - HTTP method
      operation - OAS operation object
      servers - list of servers
      Returns:
      Codegen Operation object
    • toEnumVarName

      public String toEnumVarName(String value, String datatype)
      Description copied from class: DefaultCodegen
      Return the sanitized variable name for enum
      Overrides:
      toEnumVarName in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized variable name for enum
    • isNumeric

      public static boolean isNumeric(String str)
    • toVarName

      public String toVarName(String name)
      Description copied from class: DefaultCodegen
      Return the variable name by removing invalid characters and proper escaping if it's a reserved word.
      Overrides:
      toVarName in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      name - the variable name
      Returns:
      the sanitized variable name
    • postProcessAllModels

      public Map<String,org.openapitools.codegen.model.ModelsMap> postProcessAllModels(Map<String,org.openapitools.codegen.model.ModelsMap> objs)
      Specified by:
      postProcessAllModels in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      postProcessAllModels in class org.openapitools.codegen.languages.AbstractKotlinCodegen
    • updateEnumVarsWithExtensions

      protected void updateEnumVarsWithExtensions(List<Map<String,Object>> enumVars, Map<String,Object> vendorExtensions, String dataType)
      Overrides:
      updateEnumVarsWithExtensions in class DefaultCodegen
    • setParameterExampleValue

      public void setParameterExampleValue(org.openapitools.codegen.CodegenParameter codegenParameter, io.swagger.v3.oas.models.parameters.Parameter parameter)
      Description copied from class: DefaultCodegen
      Return the example value of the parameter.
      Overrides:
      setParameterExampleValue in class DefaultCodegen
      Parameters:
      codegenParameter - Codegen parameter
      parameter - Parameter
    • setParameterExampleValue

      public void setParameterExampleValue(org.openapitools.codegen.CodegenParameter p)
      Description copied from class: DefaultCodegen
      Return the example value of the parameter.
      Overrides:
      setParameterExampleValue in class DefaultCodegen
      Parameters:
      p - Codegen parameter
    • getParameterExampleValue

      protected String getParameterExampleValue(org.openapitools.codegen.CodegenParameter p)
    • getPropertyExampleValue

      protected String getPropertyExampleValue(org.openapitools.codegen.CodegenProperty p)
    • getExampleValue

      public String getExampleValue(String defaultValue, String example, String dataType, Boolean isModel, List<Object> allowableValues, String itemsType, String itemsExample, List<org.openapitools.codegen.CodegenProperty> requiredVars, boolean isProperty)
    • toDefaultValue

      public String toDefaultValue(org.openapitools.codegen.CodegenProperty cp, io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegen
      Return the default value of the property

      Return null if you do NOT want a default value. Any non-null value will cause {{#defaultValue} check to pass.

      Overrides:
      toDefaultValue in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Parameters:
      cp - Codegen property
      schema - Property schema
      Returns:
      string presentation of the default value of the property
    • addMustacheLambdas

      protected com.google.common.collect.ImmutableMap.Builder<String,com.samskivert.mustache.Mustache.Lambda> addMustacheLambdas()
      Description copied from class: DefaultCodegen
      Preset map builder with commonly used Mustache lambdas. To extend the map, override addMustacheLambdas(), call parent method first and then add additional lambdas to the returned builder. If common lambdas are not desired, override addMustacheLambdas() method and return empty builder.
      Overrides:
      addMustacheLambdas in class org.openapitools.codegen.languages.AbstractKotlinCodegen
      Returns:
      preinitialized map with common lambdas
    • getPackageName

      public String getPackageName()
    • setSerializationLibrary

      public void setSerializationLibrary(String serializationLibrary)
    • setDateTimeLibrary

      public void setDateTimeLibrary(String name)
    • setUseOneOfInterfaces

      public void setUseOneOfInterfaces(Boolean useOneOfInterfaces)
      Overrides:
      setUseOneOfInterfaces in class DefaultCodegen
    • getUseInlineModelResolver

      public boolean getUseInlineModelResolver()
      Specified by:
      getUseInlineModelResolver in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      getUseInlineModelResolver in class DefaultCodegen
    • setGenerateSwaggerAnnotations

      public void setGenerateSwaggerAnnotations(boolean generateSwaggerAnnotations)
    • setDateFormat

      public void setDateFormat(String dateFormat)
    • setDateTimeFormat

      public void setDateTimeFormat(String dateTimeFormat)
    • setUseEnumCaseInsensitive

      public void setUseEnumCaseInsensitive(boolean useEnumCaseInsensitive)
    • setAdditionalOneOfTypeAnnotations

      public void setAdditionalOneOfTypeAnnotations(List<String> additionalOneOfTypeAnnotations)
    • setAdditionalEnumTypeAnnotations

      public void setAdditionalEnumTypeAnnotations(List<String> additionalEnumTypeAnnotations)
    • postProcess

      public void postProcess()
      Specified by:
      postProcess in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      postProcess in class DefaultCodegen