Class AbstractGoCodegen

java.lang.Object
io.swagger.codegen.v3.generators.DefaultCodegenConfig
io.swagger.codegen.v3.generators.go.AbstractGoCodegen
All Implemented Interfaces:
io.swagger.codegen.v3.CodegenConfig
Direct Known Subclasses:
GoClientCodegen, GoServerCodegen

public abstract class AbstractGoCodegen extends DefaultCodegenConfig
  • Field Details

    • LOGGER

      protected static org.slf4j.Logger LOGGER
    • withXml

      protected boolean withXml
    • packageName

      protected String packageName
  • Constructor Details

    • AbstractGoCodegen

      public AbstractGoCodegen()
  • Method Details

    • escapeReservedWord

      public String escapeReservedWord(String name)
      Escapes a reserved word as defined in the `reservedWords` array. Handle escaping those terms here. This logic is only called if a variable matches the reserved words
      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 term
    • 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
    • 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
    • toModel

      public String toModel(String name)
    • 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
    • postProcessParameter

      public void postProcessParameter(io.swagger.codegen.v3.CodegenParameter parameter)
      Overrides postProcessParameter to add a vendor extension "x-exportParamName". This is useful when paramName starts with a lowercase letter, but we need that param to be exportable (starts with an Uppercase letter).
      Specified by:
      postProcessParameter in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessParameter in class DefaultCodegenConfig
      Parameters:
      parameter - CodegenParameter object to be processed.
    • getTypeDeclaration

      public String getTypeDeclaration(io.swagger.v3.oas.models.media.Schema schema)
      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:
      schema - Schema Property object
      Returns:
      a string presentation of the property type
    • 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
    • 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
    • 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
    • postProcessSupportingFileData

      public Map<String,Object> postProcessSupportingFileData(Map<String,Object> objs)
      Specified by:
      postProcessSupportingFileData in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessSupportingFileData 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
    • setPackageName

      public void setPackageName(String packageName)
    • 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
    • createMapping

      public Map<String,String> createMapping(String key, String value)
    • 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
    • toEnumDefaultValue

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

      public String toEnumVarName(String name, String datatype)
      Description copied from class: DefaultCodegenConfig
      Return the sanitized variable name for enum
      Overrides:
      toEnumVarName in class DefaultCodegenConfig
      Parameters:
      name - enum variable name
      datatype - data type
      Returns:
      the sanitized variable name for enum
    • 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
    • setWithXml

      public void setWithXml(boolean withXml)
    • 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> allDefinitions)
      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
      allDefinitions - a map of all Swagger models from the spec
      Returns:
      Codegen Model object
    • getSchemaHandler

      public io.swagger.codegen.v3.ISchemaHandler getSchemaHandler()
      Specified by:
      getSchemaHandler in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      getSchemaHandler in class DefaultCodegenConfig
    • checkAliasModel

      public boolean checkAliasModel()