Class AbstractJavaCodegen

java.lang.Object
io.swagger.codegen.v3.generators.DefaultCodegenConfig
io.swagger.codegen.v3.generators.java.AbstractJavaCodegen
All Implemented Interfaces:
io.swagger.codegen.v3.CodegenConfig
Direct Known Subclasses:
AbstractJavaJAXRSServerCodegen, JavaClientCodegen, JavaCXFClientCodegen, JavaInflectorServerCodegen, JavaVertXServerCodegen, MicronautCodegen, SpringCodegen

public abstract class AbstractJavaCodegen extends DefaultCodegenConfig
  • Field Details

    • FULL_JAVA_UTIL

      public static final String FULL_JAVA_UTIL
      See Also:
    • DEFAULT_LIBRARY

      public static final String DEFAULT_LIBRARY
      See Also:
    • DATE_LIBRARY

      public static final String DATE_LIBRARY
      See Also:
    • JAVA8_MODE

      public static final String JAVA8_MODE
      See Also:
    • JAVA11_MODE

      public static final String JAVA11_MODE
      See Also:
    • WITH_XML

      public static final String WITH_XML
      See Also:
    • SUPPORT_JAVA6

      public static final String SUPPORT_JAVA6
      See Also:
    • ERROR_ON_UNKNOWN_ENUM

      public static final String ERROR_ON_UNKNOWN_ENUM
      See Also:
    • CHECK_DUPLICATED_MODEL_NAME

      public static final String CHECK_DUPLICATED_MODEL_NAME
      See Also:
    • USE_NULLABLE_FOR_NOTNULL

      public static final String USE_NULLABLE_FOR_NOTNULL
      See Also:
    • WIREMOCK_OPTION

      public static final String WIREMOCK_OPTION
      See Also:
    • JAKARTA

      public static final String JAKARTA
      See Also:
    • dateLibrary

      protected String dateLibrary
    • java8Mode

      protected boolean java8Mode
    • java11Mode

      protected boolean java11Mode
    • withXml

      protected boolean withXml
    • invokerPackage

      protected String invokerPackage
    • groupId

      protected String groupId
    • artifactId

      protected String artifactId
    • artifactVersion

      protected String artifactVersion
    • artifactUrl

      protected String artifactUrl
    • artifactDescription

      protected String artifactDescription
    • developerName

      protected String developerName
    • developerEmail

      protected String developerEmail
    • developerOrganization

      protected String developerOrganization
    • developerOrganizationUrl

      protected String developerOrganizationUrl
    • scmConnection

      protected String scmConnection
    • scmDeveloperConnection

      protected String scmDeveloperConnection
    • scmUrl

      protected String scmUrl
    • licenseName

      protected String licenseName
    • licenseUrl

      protected String licenseUrl
    • projectFolder

      protected String projectFolder
    • projectTestFolder

      protected String projectTestFolder
    • sourceFolder

      protected String sourceFolder
    • testFolder

      protected String testFolder
    • localVariablePrefix

      protected String localVariablePrefix
    • fullJavaUtil

      protected boolean fullJavaUtil
    • javaUtilPrefix

      protected String javaUtilPrefix
    • serializableModel

      protected Boolean serializableModel
    • serializeBigDecimalAsString

      protected boolean serializeBigDecimalAsString
    • apiDocPath

      protected String apiDocPath
    • modelDocPath

      protected String modelDocPath
    • supportJava6

      protected boolean supportJava6
    • jakarta

      protected boolean jakarta
    • useNullableForNotNull

      protected boolean useNullableForNotNull
  • Constructor Details

    • AbstractJavaCodegen

      public AbstractJavaCodegen()
  • Method Details

    • processOpts

      public void processOpts()
      Specified by:
      processOpts in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      processOpts in class DefaultCodegenConfig
    • escapeUnderscore

      protected String escapeUnderscore(String name)
    • escapeReservedWord

      public String escapeReservedWord(String name)
      Description copied from class: DefaultCodegenConfig
      Return the escaped name of the reserved word
      Specified by:
      escapeReservedWord in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeReservedWord in class DefaultCodegenConfig
      Parameters:
      name - the name to be escaped
      Returns:
      the escaped reserved word throws Runtime exception as reserved word is not allowed (default behavior)
    • apiFileFolder

      public String apiFileFolder()
      Specified by:
      apiFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiFileFolder in class DefaultCodegenConfig
    • apiTestFileFolder

      public String apiTestFileFolder()
      Specified by:
      apiTestFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiTestFileFolder in class DefaultCodegenConfig
    • modelFileFolder

      public String modelFileFolder()
      Specified by:
      modelFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      modelFileFolder in class DefaultCodegenConfig
    • apiDocFileFolder

      public String apiDocFileFolder()
      Specified by:
      apiDocFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiDocFileFolder in class DefaultCodegenConfig
    • modelDocFileFolder

      public String modelDocFileFolder()
      Specified by:
      modelDocFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      modelDocFileFolder in class DefaultCodegenConfig
    • toApiDocFilename

      public String toApiDocFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the file name of the Api Documentation
      Specified by:
      toApiDocFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiDocFilename in class DefaultCodegenConfig
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toModelDocFilename

      public String toModelDocFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the capitalized file name of the model documentation
      Specified by:
      toModelDocFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelDocFilename in class DefaultCodegenConfig
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • toApiTestFilename

      public String toApiTestFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the file name of the Api Test
      Specified by:
      toApiTestFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiTestFilename in class DefaultCodegenConfig
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toApiName

      public String toApiName(String name)
      Description copied from class: DefaultCodegenConfig
      Output the API (class) name (capitalized) ending with "Api" Return DefaultApi if name is empty
      Specified by:
      toApiName in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiName in class DefaultCodegenConfig
      Parameters:
      name - the name of the Api
      Returns:
      capitalized Api name ending with "Api"
    • toApiFilename

      public String toApiFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the file name of the Api Test
      Specified by:
      toApiFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiFilename in class DefaultCodegenConfig
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toVarName

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

      public String camelizeVarName(String word, boolean lowercaseFirstLetter)
    • toParamName

      public String toParamName(String name)
      Description copied from class: DefaultCodegenConfig
      Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.
      Specified by:
      toParamName in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toParamName in class DefaultCodegenConfig
      Parameters:
      name - Codegen property object
      Returns:
      the sanitized parameter name
    • toModelName

      public String toModelName(String name)
      Description copied from class: DefaultCodegenConfig
      Output the proper model name (capitalized). In case the name belongs to the TypeSystem it won't be renamed.
      Specified by:
      toModelName in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelName in class DefaultCodegenConfig
      Parameters:
      name - the name of the model
      Returns:
      capitalized model name
    • toModelFilename

      public String toModelFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the capitalized file name of the model
      Specified by:
      toModelFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelFilename in class DefaultCodegenConfig
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • getTypeDeclaration

      public String getTypeDeclaration(io.swagger.v3.oas.models.media.Schema propertySchema)
      Description copied from class: DefaultCodegenConfig
      Output the type declaration of the property
      Specified by:
      getTypeDeclaration in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      getTypeDeclaration in class DefaultCodegenConfig
      Parameters:
      propertySchema - Schema Property object
      Returns:
      a string presentation of the property type
    • getAlias

      public String getAlias(String name)
      Description copied from class: DefaultCodegenConfig
      Determine the type alias for the given type if it exists. This feature is only used for Java, because the language does not have a aliasing mechanism of its own.
      Overrides:
      getAlias in class DefaultCodegenConfig
      Parameters:
      name - The type name.
      Returns:
      The alias of the given type, if it exists. If there is no alias for this type, then returns the input type name.
    • toDefaultValue

      public String toDefaultValue(io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegenConfig
      Return the default value of the property
      Overrides:
      toDefaultValue in class DefaultCodegenConfig
      Parameters:
      schema - Schema property object
      Returns:
      string presentation of the default value of the property
    • setParameterExampleValue

      public void setParameterExampleValue(io.swagger.codegen.v3.CodegenParameter p)
      Description copied from class: DefaultCodegenConfig
      Return the example value of the parameter.
      Overrides:
      setParameterExampleValue in class DefaultCodegenConfig
      Parameters:
      p - Swagger property object
    • toExampleValue

      public String toExampleValue(io.swagger.v3.oas.models.media.Schema schemaProperty)
      Description copied from class: DefaultCodegenConfig
      Return the example value of the property
      Overrides:
      toExampleValue in class DefaultCodegenConfig
      Parameters:
      schemaProperty - Schema property object
      Returns:
      string presentation of the example value of the property
    • getSchemaType

      public String getSchemaType(io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegenConfig
      returns the swagger type for the property
      Overrides:
      getSchemaType in class DefaultCodegenConfig
      Parameters:
      schema - Schema property object
      Returns:
      string presentation of the type
    • toOperationId

      public String toOperationId(String operationId)
      Description copied from class: DefaultCodegenConfig
      Return the operation ID (method name)
      Overrides:
      toOperationId in class DefaultCodegenConfig
      Parameters:
      operationId - operation ID
      Returns:
      the sanitized method name
    • fromModel

      public io.swagger.codegen.v3.CodegenModel fromModel(String name, io.swagger.v3.oas.models.media.Schema schema, Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas)
      Description copied from class: DefaultCodegenConfig
      Convert Swagger Model object to Codegen Model object
      Specified by:
      fromModel in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      fromModel in class DefaultCodegenConfig
      Parameters:
      name - the name of the model
      schema - Swagger Model object
      allSchemas - a map of all Swagger models from the spec
      Returns:
      Codegen Model object
    • addAdditionPropertiesToCodeGenModel

      protected void addAdditionPropertiesToCodeGenModel(io.swagger.codegen.v3.CodegenModel codegenModel, io.swagger.v3.oas.models.media.Schema schema)
      Overrides:
      addAdditionPropertiesToCodeGenModel in class DefaultCodegenConfig
    • postProcessModelProperty

      public void postProcessModelProperty(io.swagger.codegen.v3.CodegenModel model, io.swagger.codegen.v3.CodegenProperty property)
      Specified by:
      postProcessModelProperty in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessModelProperty in class DefaultCodegenConfig
    • fixUpParentAndInterfaces

      protected void fixUpParentAndInterfaces(io.swagger.codegen.v3.CodegenModel codegenModel, Map<String,io.swagger.codegen.v3.CodegenModel> allModels)
      Description copied from class: DefaultCodegenConfig
      Fix up all parent and interface CodegenModel references.
      Overrides:
      fixUpParentAndInterfaces in class DefaultCodegenConfig
    • postProcessParameter

      public void postProcessParameter(io.swagger.codegen.v3.CodegenParameter parameter)
      Specified by:
      postProcessParameter in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessParameter in class DefaultCodegenConfig
    • postProcessModels

      public Map<String,Object> postProcessModels(Map<String,Object> objs)
      Specified by:
      postProcessModels in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessModels in class DefaultCodegenConfig
    • postProcessOperations

      public Map<String,Object> postProcessOperations(Map<String,Object> objs)
      Specified by:
      postProcessOperations in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessOperations in class DefaultCodegenConfig
    • preprocessOpenAPI

      public void preprocessOpenAPI(io.swagger.v3.oas.models.OpenAPI openAPI)
      Specified by:
      preprocessOpenAPI in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      preprocessOpenAPI in class DefaultCodegenConfig
    • needToImport

      protected boolean needToImport(String type)
      Description copied from class: DefaultCodegenConfig
      Check the type to see if it needs import the library/module/package
      Overrides:
      needToImport in class DefaultCodegenConfig
      Parameters:
      type - name of the type
      Returns:
      true if the library/module/package of the corresponding type needs to be imported
    • checkDuplicatedModelNameIgnoringCase

      protected void checkDuplicatedModelNameIgnoringCase(io.swagger.v3.oas.models.OpenAPI openAPI)
    • replaceDuplicatedInPaths

      protected void replaceDuplicatedInPaths(io.swagger.v3.oas.models.Paths paths, String modelName, String newModelName)
    • replaceDuplicatedInModelProperties

      protected void replaceDuplicatedInModelProperties(Map<String,io.swagger.v3.oas.models.media.Schema> definitions, String modelName, String newModelName)
    • toEnumName

      public String toEnumName(io.swagger.codegen.v3.CodegenProperty property)
      Description copied from class: DefaultCodegenConfig
      Return the Enum name (e.g. StatusEnum given 'status')
      Overrides:
      toEnumName in class DefaultCodegenConfig
      Parameters:
      property - Codegen property
      Returns:
      the Enum name
    • toEnumVarName

      public String toEnumVarName(String value, String datatype)
      Description copied from class: DefaultCodegenConfig
      Return the sanitized variable name for enum
      Overrides:
      toEnumVarName in class DefaultCodegenConfig
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized variable name for enum
    • toEnumValue

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

      public io.swagger.codegen.v3.CodegenOperation fromOperation(String path, String httpMethod, io.swagger.v3.oas.models.Operation operation, Map<String,io.swagger.v3.oas.models.media.Schema> schemas, io.swagger.v3.oas.models.OpenAPI openAPI)
      Description copied from class: DefaultCodegenConfig
      Convert Swagger Operation object to Codegen Operation object
      Specified by:
      fromOperation in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      fromOperation in class DefaultCodegenConfig
      Parameters:
      path - the path of the operation
      httpMethod - HTTP method
      operation - Swagger operation object
      schemas - a map of schemas
      openAPI - a OpenAPI object representing the spec
      Returns:
      Codegen Operation object
    • sanitizeVarName

      public String sanitizeVarName(String name)
    • isSameEnum

      protected static boolean isSameEnum(io.swagger.codegen.v3.CodegenProperty actual, io.swagger.codegen.v3.CodegenProperty other)
    • setInvokerPackage

      public void setInvokerPackage(String invokerPackage)
    • setGroupId

      public void setGroupId(String groupId)
    • setArtifactId

      public void setArtifactId(String artifactId)
    • setArtifactVersion

      public void setArtifactVersion(String artifactVersion)
    • setArtifactUrl

      public void setArtifactUrl(String artifactUrl)
    • setArtifactDescription

      public void setArtifactDescription(String artifactDescription)
    • setScmConnection

      public void setScmConnection(String scmConnection)
    • setScmDeveloperConnection

      public void setScmDeveloperConnection(String scmDeveloperConnection)
    • setScmUrl

      public void setScmUrl(String scmUrl)
    • setUseNullableForNotnull

      public void setUseNullableForNotnull(Boolean useNullableForNotNull)
    • setDeveloperName

      public void setDeveloperName(String developerName)
    • setDeveloperEmail

      public void setDeveloperEmail(String developerEmail)
    • setDeveloperOrganization

      public void setDeveloperOrganization(String developerOrganization)
    • setDeveloperOrganizationUrl

      public void setDeveloperOrganizationUrl(String developerOrganizationUrl)
    • setLicenseName

      public void setLicenseName(String licenseName)
    • setLicenseUrl

      public void setLicenseUrl(String licenseUrl)
    • setSourceFolder

      public void setSourceFolder(String sourceFolder)
    • setTestFolder

      public void setTestFolder(String testFolder)
    • setLocalVariablePrefix

      public void setLocalVariablePrefix(String localVariablePrefix)
    • setSerializeBigDecimalAsString

      public void setSerializeBigDecimalAsString(boolean s)
    • setSerializableModel

      public void setSerializableModel(Boolean serializableModel)
    • setFullJavaUtil

      public void setFullJavaUtil(boolean fullJavaUtil)
    • setWithXml

      public void setWithXml(boolean withXml)
    • setDateLibrary

      public void setDateLibrary(String library)
    • setJava8Mode

      public void setJava8Mode(boolean enabled)
    • setJava11Mode

      public void setJava11Mode(boolean java11Mode)
    • setJakarta

      public void setJakarta(boolean jakarta)
    • escapeQuotationMark

      public String escapeQuotationMark(String input)
      Description copied from class: DefaultCodegenConfig
      Escape single and/or double quote to avoid code injection
      Specified by:
      escapeQuotationMark in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeQuotationMark in class DefaultCodegenConfig
      Parameters:
      input - String to be cleaned up
      Returns:
      string with quotation mark removed or escaped
    • escapeUnsafeCharacters

      public String escapeUnsafeCharacters(String input)
      Description copied from class: DefaultCodegenConfig
      override with any special text escaping logic to handle unsafe characters so as to avoid code injection
      Specified by:
      escapeUnsafeCharacters in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeUnsafeCharacters in class DefaultCodegenConfig
      Parameters:
      input - String to be cleaned up
      Returns:
      string with unsafe characters removed or escaped
    • setSupportJava6

      public void setSupportJava6(boolean value)
    • toRegularExpression

      public String toRegularExpression(String pattern)
      Description copied from class: DefaultCodegenConfig
      Return the regular expression/JSON schema pattern (http://json-schema.org/latest/json-schema-validation.html#anchor33)
      Overrides:
      toRegularExpression in class DefaultCodegenConfig
      Parameters:
      pattern - the pattern (regular expression)
      Returns:
      properly-escaped pattern
    • convertPropertyToBoolean

      public boolean convertPropertyToBoolean(String propertyKey)
      Overrides:
      convertPropertyToBoolean in class DefaultCodegenConfig
    • writePropertyBack

      public void writePropertyBack(String propertyKey, boolean value)
      Overrides:
      writePropertyBack in class DefaultCodegenConfig
    • toBooleanGetter

      public String toBooleanGetter(String name)
      Output the Getter name for boolean property, e.g. isActive
      Specified by:
      toBooleanGetter in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toBooleanGetter in class DefaultCodegenConfig
      Parameters:
      name - the name of the property
      Returns:
      getter name based on naming convention
    • sanitizeTag

      public String sanitizeTag(String tag)
      Description copied from class: DefaultCodegenConfig
      Sanitize tag
      Specified by:
      sanitizeTag in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      sanitizeTag in class DefaultCodegenConfig
      Parameters:
      tag - Tag
      Returns:
      Sanitized tag
    • addHandlebarHelpers

      public void addHandlebarHelpers(com.github.jknack.handlebars.Handlebars handlebars)
      Specified by:
      addHandlebarHelpers in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      addHandlebarHelpers in class DefaultCodegenConfig
    • setLanguageArguments

      public void setLanguageArguments(List<io.swagger.codegen.v3.CodegenArgument> languageArguments)
      Specified by:
      setLanguageArguments in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      setLanguageArguments in class DefaultCodegenConfig
    • checkAliasModel

      public boolean checkAliasModel()