Class AbstractMicronautJavaCodegen<T extends GeneratorOptionsBuilder>

java.lang.Object
org.openapitools.codegen.DefaultCodegen
org.openapitools.codegen.languages.AbstractJavaCodegen
io.micronaut.openapi.generator.AbstractMicronautJavaCodegen<T>
Type Parameters:
T - The generator options builder.
All Implemented Interfaces:
MicronautCodeGenerator<T>, org.openapitools.codegen.CodegenConfig, org.openapitools.codegen.languages.features.BeanValidationFeatures, org.openapitools.codegen.languages.features.DocumentationProviderFeatures, org.openapitools.codegen.languages.features.OptionalFeatures
Direct Known Subclasses:
JavaMicronautClientCodegen, JavaMicronautServerCodegen

public abstract class AbstractMicronautJavaCodegen<T extends GeneratorOptionsBuilder> extends org.openapitools.codegen.languages.AbstractJavaCodegen implements org.openapitools.codegen.languages.features.BeanValidationFeatures, org.openapitools.codegen.languages.features.OptionalFeatures, 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_TEST_SPOCK

      public static final String OPT_TEST_SPOCK
      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_LOMBOK

      public static final String OPT_USE_LOMBOK
      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_1

      public static final String OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1
      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:
    • 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:
    • EXT_CONTENT_TYPE

      public static final String EXT_CONTENT_TYPE
      See Also:
    • random

      protected SecureRandom random
    • title

      protected String title
    • useOptional

      protected boolean useOptional
    • visitable

      protected boolean visitable
    • lombok

      protected boolean lombok
    • fluxForArrays

      protected boolean fluxForArrays
    • plural

      protected boolean plural
    • generatedAnnotation

      protected boolean generatedAnnotation
    • testTool

      protected String testTool
    • requiredPropertiesInConstructor

      protected boolean requiredPropertiesInConstructor
    • reactive

      protected boolean reactive
    • generateHttpResponseAlways

      protected boolean generateHttpResponseAlways
    • generateHttpResponseWhereRequired

      protected boolean generateHttpResponseWhereRequired
    • 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
  • Constructor Details

    • AbstractMicronautJavaCodegen

      protected AbstractMicronautJavaCodegen()
  • Method Details

    • setGenerateHttpResponseAlways

      public void setGenerateHttpResponseAlways(boolean generateHttpResponseAlways)
    • setGenerateHttpResponseWhereRequired

      public void setGenerateHttpResponseWhereRequired(boolean generateHttpResponseWhereRequired)
    • setReactive

      public void setReactive(boolean reactive)
    • setTestTool

      public void setTestTool(String testTool)
    • setArtifactId

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

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

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

      public void setApiNamePrefix(String apiNamePrefix)
      Overrides:
      setApiNamePrefix in class DefaultCodegen
    • setApiNameSuffix

      public void setApiNameSuffix(String apiNameSuffix)
      Overrides:
      setApiNameSuffix in class DefaultCodegen
    • setModelNamePrefix

      public void setModelNamePrefix(String modelNamePrefix)
      Overrides:
      setModelNamePrefix in class DefaultCodegen
    • setModelNameSuffix

      public void setModelNameSuffix(String modelNameSuffix)
      Overrides:
      setModelNameSuffix in class DefaultCodegen
    • setInvokerPackage

      public void setInvokerPackage(String invokerPackage)
      Overrides:
      setInvokerPackage in class org.openapitools.codegen.languages.AbstractJavaCodegen
    • setLombok

      public void setLombok(boolean lombok)
    • setPlural

      public void setPlural(boolean plural)
    • setFluxForArrays

      public void setFluxForArrays(boolean fluxForArrays)
    • setGeneratedAnnotation

      public void setGeneratedAnnotation(boolean generatedAnnotation)
    • processOpts

      public void processOpts()
      Specified by:
      processOpts in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      processOpts in class org.openapitools.codegen.languages.AbstractJavaCodegen
    • 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.AbstractJavaCodegen
    • modelTestFileFolder

      public String modelTestFileFolder()
      Specified by:
      modelTestFileFolder in interface org.openapitools.codegen.CodegenConfig
      Overrides:
      modelTestFileFolder in class org.openapitools.codegen.languages.AbstractJavaCodegen
    • 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 org.openapitools.codegen.languages.AbstractJavaCodegen
      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 org.openapitools.codegen.languages.AbstractJavaCodegen
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • 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
    • fromProperty

      public org.openapitools.codegen.CodegenProperty fromProperty(String name, io.swagger.v3.oas.models.media.Schema p, 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
      p - 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
    • 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.AbstractJavaCodegen
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized variable name for enum
    • 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.AbstractJavaCodegen
      Parameters:
      cp - Codegen property
      schema - Property schema
      Returns:
      string presentation of the default value of the property
    • arrayDefaultValue

      public org.apache.commons.lang3.tuple.Pair<String,String> arrayDefaultValue(String itemsDatatypeWithEnum, String itemsDataType, boolean itemsIsEnumOrRef, boolean isArray, boolean itemsIsString, boolean itemsIsNumeric, boolean itemsIsFloat, boolean itemsIsMap, io.swagger.v3.oas.models.media.Schema schema)
    • setUseBeanValidation

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

      public void setUseOptional(boolean useOptional)
      Specified by:
      setUseOptional in interface org.openapitools.codegen.languages.features.OptionalFeatures
    • 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
    • isReservedWord

      protected boolean isReservedWord(String word)
      Overrides:
      isReservedWord in class DefaultCodegen
    • 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 org.openapitools.codegen.languages.AbstractJavaCodegen
      Parameters:
      tag - Tag
      Returns:
      Sanitized 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 DefaultCodegen
      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 org.openapitools.codegen.languages.AbstractJavaCodegen
    • 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 org.openapitools.codegen.languages.AbstractJavaCodegen
    • 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.AbstractJavaCodegen
      Parameters:
      name - the name of the model
      schema - OAS Model object
      Returns:
      Codegen Model object
    • 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.AbstractJavaCodegen
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized value for enum
    • 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 org.openapitools.codegen.languages.AbstractJavaCodegen
      Parameters:
      path - the path of the operation
      httpMethod - HTTP method
      operation - OAS operation object
      servers - list of servers
      Returns:
      Codegen Operation object
    • 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.AbstractJavaCodegen
      Parameters:
      name - the variable name
      Returns:
      the sanitized variable name
    • getterAndSetterCapitalize

      public String getterAndSetterCapitalize(String name)
      Description copied from class: DefaultCodegen
      Camelize the method name of the getter and setter
      Overrides:
      getterAndSetterCapitalize in class org.openapitools.codegen.languages.AbstractJavaCodegen
      Parameters:
      name - string to be camelized
      Returns:
      Camelized string
    • 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.AbstractJavaCodegen
    • isGenerateHardNullable

      public boolean isGenerateHardNullable()
    • 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 org.openapitools.codegen.languages.AbstractJavaCodegen
      Parameters:
      p - Codegen parameter
    • getParameterExampleValue

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

      protected String getPropertyExampleValue(org.openapitools.codegen.CodegenProperty p, boolean groovy)
    • 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 groovy, boolean isProperty)
    • escapeTextGroovy

      public String escapeTextGroovy(String text)
    • 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 DefaultCodegen
      Returns:
      preinitialized map with common lambdas
    • 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)
    • postProcess

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