Class AbstractRustCodegen

    • Field Detail

      • charactersToAllow

        protected List<String> charactersToAllow
      • keywordsThatDoNotSupportRawIdentifiers

        protected Set<String> keywordsThatDoNotSupportRawIdentifiers
      • enumSuffix

        protected String enumSuffix
    • Constructor Detail

      • AbstractRustCodegen

        public AbstractRustCodegen()
    • Method Detail

      • bestFittingIntegerType

        public String bestFittingIntegerType​(@Nullable
                                             BigInteger minimum,
                                             boolean exclusiveMinimum,
                                             @Nullable
                                             BigInteger maximum,
                                             boolean exclusiveMaximum,
                                             boolean preferUnsigned)
        Determine the best fitting Rust type for an integer property. This is intended for use when a specific format has not been defined in the specification. Where the minimum or maximum is not known then the returned type will default to having at least 32 bits.
        Parameters:
        minimum - The minimum value as set in the specification.
        exclusiveMinimum - If the minimum value itself is excluded by the specification.
        maximum - The maximum value as set in the specification.
        exclusiveMaximum - If the maximum value itself is excluded by the specification.
        preferUnsigned - Use unsigned types where the effective minimum is greater than or equal to zero.
        Returns:
        The Rust data type name.
      • canFitIntoUnsigned

        public boolean canFitIntoUnsigned​(@Nullable
                                          BigInteger minimum,
                                          boolean exclusiveMinimum)
        Determine if an integer property can be guaranteed to fit into an unsigned data type.
        Parameters:
        minimum - The minimum value as set in the specification.
        exclusiveMinimum - If boundary values are excluded by the specification.
        Returns:
        True if the effective minimum is greater than or equal to zero.
      • sanitizeIdentifier

        public String sanitizeIdentifier​(String name,
                                         AbstractRustCodegen.CasingType casingType,
                                         String escapePrefix,
                                         String type,
                                         boolean allowRawIdentifiers)
        General purpose sanitizing function for Rust identifiers (fields, variables, structs, parameters, etc.).
        Rules for Rust are fairly simple:
        • Characters must belong to [A-Za-z0-9_]
        • Cannot use reserved words (but can sometimes prefix with "r#")
        • Cannot begin with a number
        Parameters:
        name - The input string
        casingType - Which casing type to apply
        escapePrefix - Prefix to escape words beginning with numbers or reserved words
        type - The type of identifier (used for logging)
        allowRawIdentifiers - Raw identifiers can't always be used, because of filename vs import mismatch.
        Returns:
        Sanitized string
      • 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
      • 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
      • addModelNamePrefixAndSuffix

        protected String addModelNamePrefixAndSuffix​(String 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
      • 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
      • 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
      • addApiNamePrefixAndSuffix

        protected String addApiNamePrefixAndSuffix​(String name)
      • 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 CodegenConfig
        Overrides:
        toApiName in class DefaultCodegen
        Parameters:
        name - the name of the Api
        Returns:
        capitalized Api name
      • addRegularExpressionDelimiter

        public String addRegularExpressionDelimiter​(String pattern)
        Description copied from class: DefaultCodegen
        If the pattern misses the delimiter, add "/" to the beginning and end Otherwise, return the original pattern
        Overrides:
        addRegularExpressionDelimiter in class DefaultCodegen
        Parameters:
        pattern - the pattern (regular expression)
        Returns:
        the pattern with delimiter