Class AbstractGoCodegen

    • Field Detail

      • withGoCodegenComment

        protected boolean withGoCodegenComment
      • withAWSV4Signature

        protected boolean withAWSV4Signature
      • withXml

        protected boolean withXml
      • enumClassPrefix

        protected boolean enumClassPrefix
      • structPrefix

        protected boolean structPrefix
      • generateInterfaces

        protected boolean generateInterfaces
      • packageName

        protected String packageName
      • numberTypes

        protected Set<String> numberTypes
      • usesOptionals

        protected boolean usesOptionals
    • Constructor Detail

      • AbstractGoCodegen

        public AbstractGoCodegen()
    • Method Detail

      • 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 CodegenConfig
        Overrides:
        escapeReservedWord in class DefaultCodegen
        Parameters:
        name - the name to be escaped
        Returns:
        the escaped term
      • 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 DefaultCodegen
        Parameters:
        name - the variable name
        Returns:
        the sanitized variable name
      • toParamName

        public String toParamName​(String name)
        Description copied from class: DefaultCodegen
        Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.
        Specified by:
        toParamName in interface CodegenConfig
        Overrides:
        toParamName in class DefaultCodegen
        Parameters:
        name - Codegen property object
        Returns:
        the sanitized parameter name
      • 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 CodegenConfig
        Overrides:
        toModelName in class DefaultCodegen
        Parameters:
        name - the name of the model
        Returns:
        capitalized model name
      • isReservedFilename

        protected boolean isReservedFilename​(String name)
      • toModel

        public String toModel​(String name,
                              boolean doUnderscore)
      • getTypeDeclaration

        public String getTypeDeclaration​(io.swagger.v3.oas.models.media.Schema p)
        Return the golang implementation type for the specified property.
        Specified by:
        getTypeDeclaration in interface CodegenConfig
        Overrides:
        getTypeDeclaration in class DefaultCodegen
        Parameters:
        p - the OAS property.
        Returns:
        the golang implementation type.
      • getSchemaType

        public String getSchemaType​(io.swagger.v3.oas.models.media.Schema p)
        Return the OpenAPI type for the property.
        Overrides:
        getSchemaType in class DefaultCodegen
        Parameters:
        p - the OAS property.
        Returns:
        the OpenAPI type.
      • toInstantiationType

        public String toInstantiationType​(io.swagger.v3.oas.models.media.Schema property)
        Determines the golang instantiation type of the specified schema.

        This function is called when the input schema is a map, and specifically when the 'additionalProperties' attribute is present in the OAS specification. Codegen invokes this function to resolve the "parent" association to 'additionalProperties'.

        Note the 'parent' attribute in the codegen model is used in the following scenarios: - Indicate a polymorphic association with some other type (e.g. class inheritance). - If the specification has a discriminator, codegen create a “parent” based on the discriminator. - Use of the 'additionalProperties' attribute in the OAS specification. This is the specific scenario when codegen invokes this function.

        Overrides:
        toInstantiationType in class DefaultCodegen
        Parameters:
        property - the input schema
        Returns:
        the golang instantiation type of the specified property.
      • toOperationId

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

        protected boolean needToImport​(String type)
        Description copied from class: DefaultCodegen
        Check the type to see if it needs import the library/module/package
        Overrides:
        needToImport in class DefaultCodegen
        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)
      • 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 DefaultCodegen
        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: DefaultCodegen
        Return the enum default value in the language specified format
        Overrides:
        toEnumDefaultValue in class DefaultCodegen
        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: DefaultCodegen
        Return the sanitized variable name for enum
        Overrides:
        toEnumVarName in class DefaultCodegen
        Parameters:
        name - enum variable name
        datatype - data type
        Returns:
        the sanitized variable name for enum
      • setWithGoCodegenComment

        public void setWithGoCodegenComment​(boolean withGoCodegenComment)
      • setWithAWSV4Signature

        public void setWithAWSV4Signature​(boolean withAWSV4Signature)
      • setWithXml

        public void setWithXml​(boolean withXml)
      • setEnumClassPrefix

        public void setEnumClassPrefix​(boolean enumClassPrefix)
      • setStructPrefix

        public void setStructPrefix​(boolean structPrefix)
      • setGenerateInterfaces

        public void setGenerateInterfaces​(boolean generateInterfaces)
      • toDefaultValue

        public String toDefaultValue​(io.swagger.v3.oas.models.media.Schema schema)
        Description copied from class: DefaultCodegen
        Return the default value of the property

        This method should be overridden in the generator to meet its requirement. Return null if you do NOT want a default value. Any non-null value will cause {{#defaultValue} check to pass.

        Overrides:
        toDefaultValue in class DefaultCodegen
        Parameters:
        schema - Property schema
        Returns:
        string presentation of the default value of the property
      • postProcessFile

        public void postProcessFile​(File file,
                                    String fileType)
        Description copied from class: DefaultCodegen
        Post-process the auto-generated file, e.g. using go-fmt to format the Go code. The file type can be "model-test", "model-doc", "model", "api", "api-test", "api-doc", "supporting-mustache", "supporting-common", "openapi-generator-ignore", "openapi-generator-version"

        TODO: store these values in enum instead

        Specified by:
        postProcessFile in interface CodegenConfig
        Overrides:
        postProcessFile in class DefaultCodegen
        Parameters:
        file - file to be processed
        fileType - file type
      • isNumberType

        protected boolean isNumberType​(String datatype)