Class AbstractRustCodegen
- java.lang.Object
-
- org.openapitools.codegen.DefaultCodegen
-
- org.openapitools.codegen.languages.AbstractRustCodegen
-
- All Implemented Interfaces:
CodegenConfig
- Direct Known Subclasses:
RustClientCodegen,RustServerCodegen
public abstract class AbstractRustCodegen extends DefaultCodegen implements CodegenConfig
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractRustCodegen.CasingType
-
Field Summary
Fields Modifier and Type Field Description protected List<String>charactersToAllowprotected StringenumSuffixprotected Set<String>keywordsThatDoNotSupportRawIdentifiers-
Fields inherited from class org.openapitools.codegen.DefaultCodegen
additionalProperties, addOneOfInterfaceImports, addOneOfInterfaces, addSuffixToDuplicateOperationNicknames, allowUnicodeIdentifiers, apiDocTemplateFiles, apiNamePrefix, apiNameSuffix, apiPackage, apiTemplateFiles, apiTestTemplateFiles, cliOptions, DefaultFeatureSet, defaultIncludes, disallowAdditionalPropertiesIfNotPresent, docExtension, embeddedTemplateDir, enableMinimalUpdate, enablePostProcessFile, ensureUniqueParams, enumUnknownDefaultCase, enumUnknownDefaultCaseName, falseSchema, filesMetadataFilename, fileSuffix, generatorMetadata, gitHost, gitRepoId, gitUserId, hideGenerationTimestamp, httpUserAgent, ignoreFilePathOverride, importBaseType, importContainerType, importMapping, inlineSchemaNameMapping, inlineSchemaOption, inputSpec, instantiationTypes, JSON_MIME_PATTERN, JSON_VENDOR_MIME_PATTERN, languageSpecificPrimitives, legacyDiscriminatorBehavior, library, loadDeepObjectIntoItems, modelDocTemplateFiles, modelNameMapping, modelNamePrefix, modelNameSuffix, modelPackage, modelTemplateFiles, modelTestTemplateFiles, nameMapping, openAPI, openapiNormalizer, outputFolder, parameterNameMapping, prependFormOrBodyParameters, releaseNote, removeEnumValuePrefix, removeOperationIdPrefix, removeOperationIdPrefixCount, removeOperationIdPrefixDelimiter, reservedWords, reservedWordsMappings, schemaMapping, serverVariables, skipOperationExample, skipOverwrite, sortModelPropertiesByRequiredFlag, sortParamsByRequiredFlag, specialCharReplacements, strictSpecBehavior, supportedLibraries, supportingFiles, supportsAdditionalPropertiesWithComposedSchema, supportsInheritance, supportsMixins, supportsMultipleInheritance, templateDir, testPackage, trueSchema, typeAliases, typeMapping, useOneOfInterfaces, vendorExtensions, versionMetadataFilename, XML_MIME_PATTERN
-
-
Constructor Summary
Constructors Constructor Description AbstractRustCodegen()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringaddApiNamePrefixAndSuffix(String name)protected StringaddModelNamePrefixAndSuffix(String name)StringaddRegularExpressionDelimiter(String pattern)If the pattern misses the delimiter, add "/" to the beginning and end Otherwise, return the original patternStringbestFittingIntegerType(BigInteger minimum, boolean exclusiveMinimum, BigInteger maximum, boolean exclusiveMaximum, boolean preferUnsigned)Determine the best fitting Rust type for an integer property.booleancanFitIntoUnsigned(BigInteger minimum, boolean exclusiveMinimum)Determine if an integer property can be guaranteed to fit into an unsigned data type.StringescapeQuotationMark(String input)Escape single and/or double quote to avoid code injectionStringescapeUnsafeCharacters(String input)override with any special text escaping logic to handle unsafe characters so as to avoid code injectionGeneratorLanguagegeneratorLanguage()booleanisReservedWord(String word)StringsanitizeIdentifier(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 numberStringtoApiDocFilename(String name)Return the file name of the Api DocumentationStringtoApiFilename(String name)Return the file name of the Api TestStringtoApiName(String name)Output the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is emptyStringtoEnumDefaultValue(String value, String datatype)Return the enum default value in the language specified formatStringtoEnumName(CodegenProperty property)Return the Enum name (e.g.StringtoEnumValue(String value, String datatype)Return the enum value in the language specified format e.g.StringtoEnumVarName(String name, String datatype)Return the sanitized variable name for enumStringtoModelDocFilename(String name)Return the capitalized file name of the model documentationStringtoModelFilename(String name)Return the capitalized file name of the modelStringtoModelName(String name)Converts the OpenAPI schema name to a model name suitable for the current code generator.StringtoOperationId(String operationId)Return the operation ID (method name)StringtoParamName(String name)Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.StringtoVarName(String name)Return the variable name by removing invalid characters and proper escaping if it's a reserved word.-
Methods inherited from class org.openapitools.codegen.DefaultCodegen
addAdditionPropertiesToCodeGenModel, addBodyModelSchema, addHeaders, addImport, addImport, addImport, addImports, addImports, addImports, addImportsForPropertyType, addImportsToOneOfInterface, additionalProperties, addMustacheLambdas, addOneOfInterfaceModel, addOneOfNameExtension, addOperationToGroup, addOption, addOption, addParentContainer, addProperties, addRequiredVarsMap, addSwitch, addVars, addVars, addVarsRequiredVarsAdditionalProps, apiDocFileFolder, apiDocFilename, apiDocTemplateFiles, apiFileFolder, apiFilename, apiPackage, apiTemplateFiles, apiTestFileFolder, apiTestFilename, apiTestTemplateFiles, buildEnumVars, buildLibraryCliOption, cliOptions, convertPropertyToBoolean, convertPropertyToBooleanAndWriteBack, createDiscriminator, defaultIncludes, defaultTemplatingEngine, embeddedTemplateDir, encodePath, escapeReservedWord, escapeText, escapeTextWhileAllowingNewLines, fileSuffix, findCommonPrefixOfVars, findMethodResponse, fromCallback, fromFormProperty, fromModel, fromOperation, fromParameter, fromProperty, fromProperty, fromProperty, fromRequestBody, fromRequestBodyToFormParameters, fromResponse, fromSecurity, fromServers, fromServerVariables, generateExamplePath, generateJSONSpecFile, generateYAMLSpecFile, generatorLanguageVersion, getAdditionalPropertiesName, getAddSuffixToDuplicateOperationNicknames, getAlias, getAllModels, getAllOfDescendants, getAllowUnicodeIdentifiers, getApiNamePrefix, getApiNameSuffix, getCollectionFormat, getCollectionFormat, getConsumesInfo, getContent, getContentType, getDisallowAdditionalPropertiesIfNotPresent, getDocExtension, getEnsureUniqueParams, getEnumDefaultValue, getEnumUnknownDefaultCase, getFeatureSet, getFilesMetadataFilename, getGeneratorMetadata, getGitHost, getGitRepoId, getGitUserId, getHelp, getHttpUserAgent, getIgnoreFilePathOverride, getInnerEnumAllowableValues, getInputSpec, getItemsName, getLegacyDiscriminatorBehavior, getLibrary, getModelNamePrefix, getModelNameSuffix, getModelNameToSchemaCache, getMostInnerItems, getName, getOneOfAnyOfDescendants, getOrGenerateOperationId, getOutputDir, getParameterDataType, getPrependFormOrBodyParameters, getProducesInfo, getReleaseNote, getRemoveOperationIdPrefixCount, getRemoveOperationIdPrefixDelimiter, getSchemaAdditionalProperties, getSchemaFromBooleanOrSchema, getSchemaItems, getSchemaType, getSingleSchemaType, getSortModelPropertiesByRequiredFlag, getSortParamsByRequiredFlag, getSupportedVendorExtensions, getSymbolName, getTag, getTemplatingEngine, getterAndSetterCapitalize, getTypeDeclaration, getTypeDeclaration, getUseInlineModelResolver, getUseOneOfInterfaces, getUseOpenAPINormalizer, getVersionMetadataFilename, handleMethodResponse, handleMethodResponse, handleSpecialCharacters, hasBodyParameter, hasFormParameter, importMapping, initializeSpecialCharacterMapping, inlineSchemaNameMapping, inlineSchemaOption, instantiationTypes, isAnyTypeSchema, isDataTypeBinary, isDataTypeFile, isDataTypeString, isEnableMinimalUpdate, isEnablePostProcessFile, isHideGenerationTimestamp, isJsonMimeType, isJsonVendorMimeType, isLibrary, isParameterNameUnique, isPropertyInnerMostEnum, isRemoveEnumValuePrefix, isRemoveOperationIdPrefix, isSkipOperationExample, isSkipOverwrite, isStrictSpecBehavior, isXmlMimeType, languageSpecificPrimitives, lowerCamelCase, modelDocFileFolder, modelDocTemplateFiles, modelFileFolder, modelFilename, modelNameMapping, modelPackage, modelTemplateFiles, modelTestFileFolder, modelTestTemplateFiles, modifyFeatureSet, nameMapping, needToImport, openapiNormalizer, outputFolder, parameterNameMapping, postProcess, postProcessAllModels, postProcessFile, postProcessModelProperty, postProcessModels, postProcessModelsEnum, postProcessOperationsWithModels, postProcessParameter, postProcessSupportingFileData, preprocessOpenAPI, processCompiler, processOpenAPI, processOpts, processTemplatingEngine, processTestExampleData, removeImport, removeNonNameElementToCamelCase, removeNonNameElementToCamelCase, removeOption, removeSelfReferenceImports, reservedWords, reservedWordsMappings, sanitizeName, sanitizeName, sanitizeName, sanitizeTag, schemaMapping, serverVariableOverrides, setAddProps, setAllowUnicodeIdentifiers, setApiNamePrefix, setApiNameSuffix, setApiPackage, setCircularReferences, setDisallowAdditionalPropertiesIfNotPresent, setDocExtension, setEnableMinimalUpdate, setEnablePostProcessFile, setEnsureUniqueParams, setEnumUnknownDefaultCase, setFilesMetadataFilename, setGitHost, setGitRepoId, setGitUserId, setHideGenerationTimestamp, setHttpUserAgent, setIgnoreFilePathOverride, setInputSpec, setLegacyDiscriminatorBehavior, setLibrary, setModelNamePrefix, setModelNameSuffix, setModelPackage, setNonArrayMapProperty, setOpenAPI, setOutputDir, setParameterBooleanFlagWithCodegenProperty, setParameterEncodingValues, setParameterExamples, setParameterExampleValue, setParameterExampleValue, setParameterExampleValue, setParameterNullable, setPrependFormOrBodyParameters, setReleaseNote, setRemoveEnumValuePrefix, setRemoveOperationIdPrefix, setRemoveOperationIdPrefixCount, setRemoveOperationIdPrefixDelimiter, setReservedWordsLowerCase, setSkipOperationExample, setSkipOverwrite, setSortModelPropertiesByRequiredFlag, setSortParamsByRequiredFlag, setStrictSpecBehavior, setTemplateDir, setTemplatingEngine, setUseOneOfInterfaces, setVersionMetadataFilename, shouldAddImport, shouldOverwrite, supportedLibraries, supportingFiles, templateDir, testPackage, toAllOfName, toAnyOfName, toApiImport, toApiTestFilename, toApiVarName, toArrayModelParamName, toBooleanGetter, toDefaultParameterValue, toDefaultParameterValue, toDefaultValue, toDefaultValue, toDefaultValueWithParam, toExamples, toExampleValue, toGetter, toInstantiationType, toMediaTypeSchemaName, toModelImport, toModelImportMap, toModelTestFilename, toOneOfName, toRegularExpression, toSetter, toTestCaseName, typeMapping, unaliasPropertySchema, unaliasSchema, updateAllModels, updateCodegenPropertyEnum, updateDataTypeWithEnumForArray, updateDataTypeWithEnumForMap, updateEnumVarsWithExtensions, updateModelForAnyType, updateModelForComposedSchema, updateModelForInteger, updateModelForNumber, updateModelForObject, updateModelForString, updateOption, updateParameterForString, updatePropertyForAnyType, updatePropertyForArray, updatePropertyForInteger, updatePropertyForMap, updatePropertyForMap, updatePropertyForNumber, updatePropertyForObject, updatePropertyForString, updateRequestBodyForArray, updateRequestBodyForMap, updateRequestBodyForObject, updateRequestBodyForPrimitiveType, updateRequestBodyForString, vendorExtensions, writePropertyBack
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openapitools.codegen.CodegenConfig
additionalProperties, addOperationToGroup, apiDocFileFolder, apiDocFilename, apiDocTemplateFiles, apiFileFolder, apiFilename, apiPackage, apiTemplateFiles, apiTestFileFolder, apiTestFilename, apiTestTemplateFiles, cliOptions, defaultIncludes, defaultTemplatingEngine, embeddedTemplateDir, encodePath, escapeReservedWord, escapeText, escapeTextWhileAllowingNewLines, fileSuffix, fromModel, fromOperation, fromSecurity, fromServers, fromServerVariables, generateExamplePath, generatorLanguageVersion, getAddSuffixToDuplicateOperationNicknames, getDocExtension, getFeatureSet, getFilesMetadataFilename, getGeneratorMetadata, getGitHost, getGitRepoId, getGitUserId, getHelp, getHttpUserAgent, getIgnoreFilePathOverride, getInputSpec, getLibrary, getName, getOutputDir, getReleaseNote, getSupportedVendorExtensions, getTag, getTemplatingEngine, getTypeDeclaration, getTypeDeclaration, getUseInlineModelResolver, getUseOpenAPINormalizer, getVersionMetadataFilename, importMapping, inlineSchemaNameMapping, inlineSchemaOption, instantiationTypes, isEnableMinimalUpdate, isEnablePostProcessFile, isHideGenerationTimestamp, isRemoveEnumValuePrefix, isRemoveOperationIdPrefix, isSkipOperationExample, isSkipOverwrite, isStrictSpecBehavior, languageSpecificPrimitives, modelDocFileFolder, modelDocTemplateFiles, modelFileFolder, modelFilename, modelNameMapping, modelPackage, modelTemplateFiles, modelTestFileFolder, modelTestTemplateFiles, nameMapping, openapiNormalizer, outputFolder, parameterNameMapping, postProcess, postProcessAllModels, postProcessFile, postProcessModelProperty, postProcessModels, postProcessOperationsWithModels, postProcessParameter, postProcessSupportingFileData, preprocessOpenAPI, processCompiler, processOpenAPI, processOpts, processTemplatingEngine, reservedWords, reservedWordsMappings, sanitizeName, sanitizeTag, schemaMapping, serverVariableOverrides, setDocExtension, setEnableMinimalUpdate, setEnablePostProcessFile, setGitHost, setGitRepoId, setGitUserId, setHideGenerationTimestamp, setHttpUserAgent, setIgnoreFilePathOverride, setInputSpec, setLibrary, setOpenAPI, setOutputDir, setReleaseNote, setRemoveEnumValuePrefix, setRemoveOperationIdPrefix, setSkipOperationExample, setSkipOverwrite, setStrictSpecBehavior, setTemplatingEngine, shouldOverwrite, supportedLibraries, supportingFiles, templateDir, testPackage, toApiImport, toApiTestFilename, toApiVarName, toBooleanGetter, toGetter, toModelImport, toModelImportMap, toModelTestFilename, toSetter, typeMapping, unaliasSchema, updateAllModels, vendorExtensions
-
-
-
-
Method Detail
-
generatorLanguage
public GeneratorLanguage generatorLanguage()
- Specified by:
generatorLanguagein interfaceCodegenConfig- Overrides:
generatorLanguagein classDefaultCodegen
-
escapeQuotationMark
public String escapeQuotationMark(String input)
Description copied from class:DefaultCodegenEscape single and/or double quote to avoid code injection- Specified by:
escapeQuotationMarkin interfaceCodegenConfig- Overrides:
escapeQuotationMarkin classDefaultCodegen- 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:DefaultCodegenoverride with any special text escaping logic to handle unsafe characters so as to avoid code injection- Specified by:
escapeUnsafeCharactersin interfaceCodegenConfig- Overrides:
escapeUnsafeCharactersin classDefaultCodegen- Parameters:
input- String to be cleaned up- Returns:
- string with unsafe characters removed or escaped
-
isReservedWord
public boolean isReservedWord(String word)
- Overrides:
isReservedWordin classDefaultCodegen
-
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 stringcasingType- Which casing type to applyescapePrefix- Prefix to escape words beginning with numbers or reserved wordstype- 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:DefaultCodegenReturn the variable name by removing invalid characters and proper escaping if it's a reserved word.- Overrides:
toVarNamein classDefaultCodegen- Parameters:
name- the variable name- Returns:
- the sanitized variable name
-
toParamName
public String toParamName(String name)
Description copied from class:DefaultCodegenReturn the parameter name by removing invalid characters and proper escaping if it's a reserved word.- Specified by:
toParamNamein interfaceCodegenConfig- Overrides:
toParamNamein classDefaultCodegen- Parameters:
name- Codegen property object- Returns:
- the sanitized parameter name
-
toOperationId
public String toOperationId(String operationId)
Description copied from class:DefaultCodegenReturn the operation ID (method name)- Overrides:
toOperationIdin classDefaultCodegen- Parameters:
operationId- operation ID- Returns:
- the sanitized method name
-
toModelName
public String toModelName(String name)
Description copied from class:DefaultCodegenConverts 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:
toModelNamein interfaceCodegenConfig- Overrides:
toModelNamein classDefaultCodegen- Parameters:
name- the name of the model- Returns:
- capitalized model name
-
toModelFilename
public String toModelFilename(String name)
Description copied from class:DefaultCodegenReturn the capitalized file name of the model- Specified by:
toModelFilenamein interfaceCodegenConfig- Overrides:
toModelFilenamein classDefaultCodegen- Parameters:
name- the model name- Returns:
- the file name of the model
-
toModelDocFilename
public String toModelDocFilename(String name)
Description copied from class:DefaultCodegenReturn the capitalized file name of the model documentation- Specified by:
toModelDocFilenamein interfaceCodegenConfig- Overrides:
toModelDocFilenamein classDefaultCodegen- Parameters:
name- the model name- Returns:
- the file name of the model
-
toEnumVarName
public String toEnumVarName(String name, String datatype)
Description copied from class:DefaultCodegenReturn the sanitized variable name for enum- Overrides:
toEnumVarNamein classDefaultCodegen- Parameters:
name- enum variable namedatatype- data type- Returns:
- the sanitized variable name for enum
-
toEnumName
public String toEnumName(CodegenProperty property)
Description copied from class:DefaultCodegenReturn the Enum name (e.g. StatusEnum given 'status')- Overrides:
toEnumNamein classDefaultCodegen- Parameters:
property- Codegen property- Returns:
- the Enum name
-
toEnumValue
public String toEnumValue(String value, String datatype)
Description copied from class:DefaultCodegenReturn the enum value in the language specified format e.g. status becomes "status"- Overrides:
toEnumValuein classDefaultCodegen- Parameters:
value- enum variable namedatatype- data type- Returns:
- the sanitized value for enum
-
toEnumDefaultValue
public String toEnumDefaultValue(String value, String datatype)
Description copied from class:DefaultCodegenReturn the enum default value in the language specified format- Overrides:
toEnumDefaultValuein classDefaultCodegen- Parameters:
value- enum variable namedatatype- data type- Returns:
- the default value for the enum
-
toApiName
public String toApiName(String name)
Description copied from class:DefaultCodegenOutput the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is empty- Specified by:
toApiNamein interfaceCodegenConfig- Overrides:
toApiNamein classDefaultCodegen- Parameters:
name- the name of the Api- Returns:
- capitalized Api name
-
toApiFilename
public String toApiFilename(String name)
Description copied from class:DefaultCodegenReturn the file name of the Api Test- Specified by:
toApiFilenamein interfaceCodegenConfig- Overrides:
toApiFilenamein classDefaultCodegen- Parameters:
name- the file name of the Api- Returns:
- the file name of the Api
-
toApiDocFilename
public String toApiDocFilename(String name)
Description copied from class:DefaultCodegenReturn the file name of the Api Documentation- Specified by:
toApiDocFilenamein interfaceCodegenConfig- Overrides:
toApiDocFilenamein classDefaultCodegen- Parameters:
name- the file name of the Api- Returns:
- the file name of the Api
-
addRegularExpressionDelimiter
public String addRegularExpressionDelimiter(String pattern)
Description copied from class:DefaultCodegenIf the pattern misses the delimiter, add "/" to the beginning and end Otherwise, return the original pattern- Overrides:
addRegularExpressionDelimiterin classDefaultCodegen- Parameters:
pattern- the pattern (regular expression)- Returns:
- the pattern with delimiter
-
-