Class AbstractPythonCodegen
- java.lang.Object
-
- org.openapitools.codegen.DefaultCodegen
-
- org.openapitools.codegen.languages.AbstractPythonCodegen
-
- All Implemented Interfaces:
CodegenConfig
- Direct Known Subclasses:
AbstractPythonConnexionServerCodegen
,PythonClientCodegen
,PythonFastAPIServerCodegen
public abstract class AbstractPythonCodegen extends DefaultCodegen implements CodegenConfig
-
-
Field Summary
Fields Modifier and Type Field Description protected String
packageName
protected String
packageVersion
protected String
projectName
-
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, inlineSchemaNameDefault, inlineSchemaNameMapping, inputSpec, instantiationTypes, JSON_MIME_PATTERN, JSON_VENDOR_MIME_PATTERN, languageSpecificPrimitives, legacyDiscriminatorBehavior, library, loadDeepObjectIntoItems, modelDocTemplateFiles, modelNamePrefix, modelNameSuffix, modelPackage, modelTemplateFiles, modelTestTemplateFiles, openAPI, openapiNormalizer, outputFolder, 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
-
-
Constructor Summary
Constructors Constructor Description AbstractPythonCodegen()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static String
dropDots(String str)
String
escapeQuotationMark(String input)
Escape single and/or double quote to avoid code injectionString
escapeReservedWord(String name)
Return the escaped name of the reserved wordString
escapeUnsafeCharacters(String input)
override with any special text escaping logic to handle unsafe characters so as to avoid code injectionGeneratorLanguage
generatorLanguage()
String
getSchemaType(io.swagger.v3.oas.models.media.Schema p)
returns the OpenAPI type for the property.String
patternCorrection(String pattern)
void
postProcessFile(File file, String fileType)
Post-process the auto-generated file, e.g.void
processOpts()
String
sanitizeTag(String tag)
Sanitize tagvoid
setPackageName(String packageName)
void
setPackageVersion(String packageVersion)
void
setParameterExampleValue(CodegenParameter p)
Return the example value of the parameter.void
setParameterExampleValue(CodegenParameter codegenParameter, io.swagger.v3.oas.models.parameters.Parameter parameter)
Return the example value of the parameter.void
setProjectName(String projectName)
String
toApiFilename(String name)
Return the file name of the Api TestString
toApiName(String name)
Output the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is emptyString
toApiTestFilename(String name)
Return the file name of the Api TestString
toApiVarName(String name)
Return the variable name in the ApiString
toDefaultValue(io.swagger.v3.oas.models.media.Schema p)
Return the default value of the propertyString
toExampleValue(io.swagger.v3.oas.models.media.Schema schema)
Return the example value of the propertyString
toModelFilename(String name)
Return the capitalized file name of the modelString
toModelName(String name)
Converts the OpenAPI schema name to a model name suitable for the current code generator.String
toModelTestFilename(String name)
Return the capitalized file name of the model testString
toOperationId(String operationId)
Return the operation ID (method name)String
toParamName(String name)
Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.String
toRegularExpression(String pattern)
Return the regular expression/JSON schema pattern (http://json-schema.org/latest/json-schema-validation.html#anchor33)String
toVarName(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, addRegularExpressionDelimiter, 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, escapeText, escapeTextWhileAllowingNewLines, fileSuffix, findCommonPrefixOfVars, findMethodResponse, fromCallback, fromFormProperty, fromModel, fromOperation, fromParameter, fromProperty, fromProperty, fromProperty, fromRequestBody, fromRequestBodyToFormParameters, fromResponse, fromSecurity, fromServers, fromServerVariables, generateExamplePath, generateJSONSpecFile, generateYAMLSpecFile, generatorLanguageVersion, getAdditionalProperties, 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, getSingleSchemaType, getSortModelPropertiesByRequiredFlag, getSortParamsByRequiredFlag, getSupportedVendorExtensions, getSymbolName, getTag, getTemplatingEngine, getterAndSetterCapitalize, getTypeDeclaration, getTypeDeclaration, getUseInlineModelResolver, getUseOneOfInterfaces, getUseOpenAPINormalizer, getVersionMetadataFilename, handleMethodResponse, handleMethodResponse, handleSpecialCharacters, hasBodyParameter, hasFormParameter, importMapping, initializeSpecialCharacterMapping, inlineSchemaNameDefault, inlineSchemaNameMapping, instantiationTypes, isAnyTypeSchema, isDataTypeBinary, isDataTypeFile, isDataTypeString, isEnableMinimalUpdate, isEnablePostProcessFile, isFreeFormObject, isHideGenerationTimestamp, isJsonMimeType, isJsonVendorMimeType, isLibrary, isParameterNameUnique, isPropertyInnerMostEnum, isRemoveEnumValuePrefix, isRemoveOperationIdPrefix, isReservedWord, isSkipOperationExample, isSkipOverwrite, isStrictSpecBehavior, languageSpecificPrimitives, lowerCamelCase, modelDocFileFolder, modelDocTemplateFiles, modelFileFolder, modelFilename, modelPackage, modelTemplateFiles, modelTestFileFolder, modelTestTemplateFiles, modifyFeatureSet, needToImport, openapiNormalizer, outputFolder, postProcess, postProcessAllModels, postProcessModelProperty, postProcessModels, postProcessModelsEnum, postProcessOperationsWithModels, postProcessParameter, postProcessSupportingFileData, preprocessOpenAPI, processCompiler, processOpenAPI, processTemplatingEngine, processTestExampleData, removeImport, removeNonNameElementToCamelCase, removeNonNameElementToCamelCase, removeOption, removeSelfReferenceImports, reservedWords, reservedWordsMappings, sanitizeName, sanitizeName, sanitizeName, 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, 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, toApiDocFilename, toApiImport, toArrayModelParamName, toBooleanGetter, toDefaultParameterValue, toDefaultParameterValue, toDefaultValue, toDefaultValueWithParam, toEnumDefaultValue, toEnumName, toEnumValue, toEnumVarName, toExamples, toGetter, toInstantiationType, toMediaTypeSchemaName, toModelDocFilename, toModelImport, toModelImportMap, toOneOfName, 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, 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, inlineSchemaNameDefault, inlineSchemaNameMapping, instantiationTypes, isEnableMinimalUpdate, isEnablePostProcessFile, isHideGenerationTimestamp, isRemoveEnumValuePrefix, isRemoveOperationIdPrefix, isSkipOperationExample, isSkipOverwrite, isStrictSpecBehavior, languageSpecificPrimitives, modelDocFileFolder, modelDocTemplateFiles, modelFileFolder, modelFilename, modelPackage, modelTemplateFiles, modelTestFileFolder, modelTestTemplateFiles, openapiNormalizer, outputFolder, postProcess, postProcessAllModels, postProcessModelProperty, postProcessModels, postProcessOperationsWithModels, postProcessParameter, postProcessSupportingFileData, preprocessOpenAPI, processCompiler, processOpenAPI, processTemplatingEngine, reservedWords, reservedWordsMappings, sanitizeName, 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, toApiDocFilename, toApiImport, toBooleanGetter, toGetter, toModelDocFilename, toModelImport, toModelImportMap, toSetter, typeMapping, unaliasSchema, updateAllModels, vendorExtensions
-
-
-
-
Method Detail
-
processOpts
public void processOpts()
- Specified by:
processOpts
in interfaceCodegenConfig
- Overrides:
processOpts
in classDefaultCodegen
-
escapeReservedWord
public String escapeReservedWord(String name)
Description copied from class:DefaultCodegen
Return the escaped name of the reserved word- Specified by:
escapeReservedWord
in interfaceCodegenConfig
- Overrides:
escapeReservedWord
in classDefaultCodegen
- Parameters:
name
- the name to be escaped- Returns:
- the escaped reserved word
throws Runtime exception as reserved word is not allowed (default behavior)
-
toDefaultValue
public String toDefaultValue(io.swagger.v3.oas.models.media.Schema p)
Return the default value of the property- Overrides:
toDefaultValue
in classDefaultCodegen
- Parameters:
p
- OpenAPI property object- Returns:
- string presentation of the default value of the property
-
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 classDefaultCodegen
- Parameters:
name
- the variable name- Returns:
- the sanitized variable name
-
toRegularExpression
public String toRegularExpression(String pattern)
Description copied from class:DefaultCodegen
Return the regular expression/JSON schema pattern (http://json-schema.org/latest/json-schema-validation.html#anchor33)- Overrides:
toRegularExpression
in classDefaultCodegen
- Parameters:
pattern
- the pattern (regular expression)- Returns:
- properly-escaped pattern
-
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 interfaceCodegenConfig
- Overrides:
toParamName
in classDefaultCodegen
- 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 classDefaultCodegen
- Parameters:
operationId
- operation ID- Returns:
- the sanitized method name
-
escapeQuotationMark
public String escapeQuotationMark(String input)
Description copied from class:DefaultCodegen
Escape single and/or double quote to avoid code injection- Specified by:
escapeQuotationMark
in interfaceCodegenConfig
- Overrides:
escapeQuotationMark
in 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:DefaultCodegen
override with any special text escaping logic to handle unsafe characters so as to avoid code injection- Specified by:
escapeUnsafeCharacters
in interfaceCodegenConfig
- Overrides:
escapeUnsafeCharacters
in classDefaultCodegen
- Parameters:
input
- String to be cleaned up- Returns:
- string with unsafe characters removed or escaped
-
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 interfaceCodegenConfig
- Overrides:
postProcessFile
in classDefaultCodegen
- Parameters:
file
- file to be processedfileType
- file type
-
toExampleValue
public String toExampleValue(io.swagger.v3.oas.models.media.Schema schema)
Description copied from class:DefaultCodegen
Return the example value of the propertyThis method should be overridden in the generator to meet its requirement.
- Overrides:
toExampleValue
in classDefaultCodegen
- Parameters:
schema
- Property schema- Returns:
- string presentation of the example value of the property
-
setParameterExampleValue
public void setParameterExampleValue(CodegenParameter p)
Description copied from class:DefaultCodegen
Return the example value of the parameter.- Overrides:
setParameterExampleValue
in classDefaultCodegen
- Parameters:
p
- Codegen parameter
-
setParameterExampleValue
public void setParameterExampleValue(CodegenParameter codegenParameter, io.swagger.v3.oas.models.parameters.Parameter parameter)
Description copied from class:DefaultCodegen
Return the example value of the parameter.- Overrides:
setParameterExampleValue
in classDefaultCodegen
- Parameters:
codegenParameter
- Codegen parameterparameter
- Parameter
-
sanitizeTag
public String sanitizeTag(String tag)
Description copied from class:DefaultCodegen
Sanitize tag- Specified by:
sanitizeTag
in interfaceCodegenConfig
- Overrides:
sanitizeTag
in classDefaultCodegen
- Parameters:
tag
- Tag- Returns:
- Sanitized tag
-
setPackageName
public void setPackageName(String packageName)
-
setProjectName
public void setProjectName(String projectName)
-
setPackageVersion
public void setPackageVersion(String packageVersion)
-
getSchemaType
public String getSchemaType(io.swagger.v3.oas.models.media.Schema p)
Description copied from class:DefaultCodegen
returns the OpenAPI type for the property. Use getAlias to handle $ref of primitive type- Overrides:
getSchemaType
in classDefaultCodegen
- Parameters:
p
- property schema- Returns:
- string presentation of the type
-
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 interfaceCodegenConfig
- Overrides:
toModelName
in classDefaultCodegen
- Parameters:
name
- the name of the model- Returns:
- capitalized model name
-
toModelFilename
public String toModelFilename(String name)
Description copied from class:DefaultCodegen
Return the capitalized file name of the model- Specified by:
toModelFilename
in interfaceCodegenConfig
- Overrides:
toModelFilename
in classDefaultCodegen
- Parameters:
name
- the model name- Returns:
- the file name of the model
-
toModelTestFilename
public String toModelTestFilename(String name)
Description copied from class:DefaultCodegen
Return the capitalized file name of the model test- Specified by:
toModelTestFilename
in interfaceCodegenConfig
- Overrides:
toModelTestFilename
in classDefaultCodegen
- Parameters:
name
- the model name- Returns:
- the file name of the model
-
toApiFilename
public String toApiFilename(String name)
Description copied from class:DefaultCodegen
Return the file name of the Api Test- Specified by:
toApiFilename
in interfaceCodegenConfig
- Overrides:
toApiFilename
in classDefaultCodegen
- Parameters:
name
- the file name of the Api- Returns:
- the file name of the Api
-
toApiTestFilename
public String toApiTestFilename(String name)
Description copied from class:DefaultCodegen
Return the file name of the Api Test- Specified by:
toApiTestFilename
in interfaceCodegenConfig
- Overrides:
toApiTestFilename
in classDefaultCodegen
- 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:DefaultCodegen
Output the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is empty- Specified by:
toApiName
in interfaceCodegenConfig
- Overrides:
toApiName
in classDefaultCodegen
- Parameters:
name
- the name of the Api- Returns:
- capitalized Api name
-
toApiVarName
public String toApiVarName(String name)
Description copied from class:DefaultCodegen
Return the variable name in the Api- Specified by:
toApiVarName
in interfaceCodegenConfig
- Overrides:
toApiVarName
in classDefaultCodegen
- Parameters:
name
- the variable name of the Api- Returns:
- the snake-cased variable name
-
generatorLanguage
public GeneratorLanguage generatorLanguage()
- Specified by:
generatorLanguage
in interfaceCodegenConfig
- Overrides:
generatorLanguage
in classDefaultCodegen
-
-