Package io.swagger.codegen
Class DefaultCodegen
- java.lang.Object
-
- io.swagger.codegen.DefaultCodegen
-
- Direct Known Subclasses:
AbstractAdaCodegen
,AbstractCppCodegen
,AbstractCSharpCodegen
,AbstractEiffelCodegen
,AbstractGoCodegen
,AbstractJavaCodegen
,AbstractKotlinCodegen
,AbstractPhpCodegen
,AbstractScalaCodegen
,AbstractTypeScriptClientCodegen
,AndroidClientCodegen
,Apache2ConfigCodegen
,BashClientCodegen
,ClojureClientCodegen
,ConfluenceWikiGenerator
,DartClientCodegen
,ElixirClientCodegen
,ElmClientCodegen
,ErlangClientCodegen
,ErlangServerCodegen
,FinchServerCodegen
,FlashClientCodegen
,FlaskConnexionCodegen
,HaskellHttpClientCodegen
,HaskellServantCodegen
,JavascriptClientCodegen
,JavascriptClosureAngularClientCodegen
,JMeterCodegen
,LuaClientCodegen
,NodeJSServerCodegen
,ObjcClientCodegen
,PerlClientCodegen
,PhpClientCodegen
,PowerShellClientCodegen
,PythonClientCodegen
,Rails5ServerCodegen
,RClientCodegen
,RubyClientCodegen
,RustClientCodegen
,RustServerCodegen
,SilexServerCodegen
,SinatraServerCodegen
,SlimFrameworkServerCodegen
,StaticDocCodegen
,StaticHtml2Generator
,StaticHtmlGenerator
,SwaggerGenerator
,SwaggerYamlGenerator
,Swift3Codegen
,Swift4Codegen
,Swift5Codegen
,SwiftCodegen
,TizenClientCodegen
public class DefaultCodegen extends Object
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description DefaultCodegen()
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, io.swagger.models.ModelImpl swaggerModel)
protected void
addImport(CodegenModel m, String type)
Map<String,Object>
additionalProperties()
void
addOperationToGroup(String tag, String resourcePath, io.swagger.models.Operation operation, CodegenOperation co, Map<String,List<CodegenOperation>> operations)
Add operation to groupprotected void
addOption(String key, String description)
protected void
addOption(String key, String description, String defaultValue)
protected void
addParentContainer(CodegenModel m, String name, io.swagger.models.properties.Property property)
protected void
addProperties(Map<String,io.swagger.models.properties.Property> properties, List<String> required, io.swagger.models.Model model, Map<String,io.swagger.models.Model> allDefinitions)
String
addRegularExpressionDelimiter(String pattern)
If the pattern misses the delimiter, add "/" to the beginning and end Otherwise, return the original patternprotected void
addSwitch(String key, String description, Boolean defaultValue)
String
apiDocFileFolder()
String
apiDocFilename(String templateName, String tag)
Return the full path and API documentation fileMap<String,String>
apiDocTemplateFiles()
String
apiFileFolder()
String
apiFilename(String templateName, String tag)
String
apiPackage()
Map<String,String>
apiTemplateFiles()
String
apiTestFileFolder()
String
apiTestFilename(String templateName, String tag)
Return the full path and API test fileMap<String,String>
apiTestTemplateFiles()
protected CliOption
buildLibraryCliOption(Map<String,String> supportedLibraries)
static String
camelize(String word)
Camelize name (parameter, property, method, etc) with upper case for first letter copied from Twitter elephant bird https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.javastatic String
camelize(String word, boolean lowercaseFirstLetter)
Camelize name (parameter, property, method, etc)List<CliOption>
cliOptions()
protected void
configureDataForTestTemplate(CodegenOperation codegenOperation)
boolean
convertPropertyToBoolean(String propertyKey)
boolean
convertPropertyToBooleanAndWriteBack(String propertyKey)
reads propertyKey from additionalProperties, converts it to a boolean and writes it back to additionalProperties to be usable as a boolean in mustache files.protected String
dashize(String word)
Dashize the given word.boolean
defaultIgnoreImportMappingOption()
Set<String>
defaultIncludes()
String
embeddedTemplateDir()
protected String
ensureUniqueName(Map<String,Integer> uniqueNames, String name)
If necessary, appends a suffix to enforce uniqueness of names within a namespace.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
escapeText(String input)
String
escapeUnsafeCharacters(String input)
override with any special text escaping logic to handle unsafe characters so as to avoid code injectionString
fileSuffix()
String
findCommonPrefixOfVars(List<Object> vars)
Returns the common prefix of variables for enum naming if two or more variables are present.protected io.swagger.models.Response
findMethodResponse(Map<String,io.swagger.models.Response> responses)
Override with any special handling of response codesprotected void
fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String,CodegenModel> allModels)
Fix up all parent and interface CodegenModel references.CodegenModel
fromModel(String name, io.swagger.models.Model model)
Convert Swagger Model object to Codegen Model object without providing all model definitionsCodegenModel
fromModel(String name, io.swagger.models.Model model, Map<String,io.swagger.models.Model> allDefinitions)
Convert Swagger Model object to Codegen Model objectCodegenOperation
fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions)
Convert Swagger Operation object to Codegen Operation object (without providing a Swagger object)CodegenOperation
fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions, io.swagger.models.Swagger swagger)
Convert Swagger Operation object to Codegen Operation objectCodegenParameter
fromParameter(io.swagger.models.parameters.Parameter param, Set<String> imports)
Convert Swagger Parameter object to Codegen Parameter objectCodegenProperty
fromProperty(String name, io.swagger.models.properties.Property p)
Convert Swagger Property object to Codegen Property objectCodegenResponse
fromResponse(String responseCode, io.swagger.models.Response response)
Convert Swagger Response object to Codegen Response objectList<CodegenSecurity>
fromSecurity(Map<String,io.swagger.models.auth.SecuritySchemeDefinition> schemes)
Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objectsString
generateExamplePath(String path, io.swagger.models.Operation operation)
Return the example pathString
getAlias(String name)
Determine the type alias for the given type if it exists.protected Map<String,String>
getAllAliases(Map<String,io.swagger.models.Model> allDefinitions)
Determine all of the types in the model definitions that are aliases of simple types.String
getCommonTemplateDir()
protected List<Map<String,String>>
getExamples(Map<String,io.swagger.models.Model> definitions, Map<String,Object> examples, List<String> mediaTypes, Object object)
String
getGitRepoBaseURL()
Git repo Base URLString
getGitRepoId()
Git repo IDString
getGitUserId()
Git user IDString
getHttpUserAgent()
HTTP user agentString
getIgnoreFilePathOverride()
Provides an override location, if any is specified, for the .swagger-codegen-ignore.boolean
getIgnoreImportMapping()
protected Map<String,Object>
getInnerEnumAllowableValues(CodegenProperty property)
String
getInputSpec()
String
getLibrary()
Library template (sub-template).protected String
getOrGenerateOperationId(io.swagger.models.Operation operation, String path, String httpMethod)
Get operationId from the operation object, and if it's blank, generate a new one from the given parameters.String
getOutputDir()
protected String
getParameterDataType(io.swagger.models.parameters.Parameter parameter, io.swagger.models.properties.Property property)
Returns the data type of a parameter.String
getReleaseNote()
Release noteBoolean
getSkipAliasGeneration()
String
getSwaggerType(io.swagger.models.properties.Property p)
returns the swagger type for the propertyprotected String
getSymbolName(String input)
Return the symbol name of a symbolString
getterAndSetterCapitalize(String name)
Camelize the method name of the getter and setterString
getTypeDeclaration(io.swagger.models.properties.Property p)
Output the type declaration of the propertyString
getTypeDeclaration(String name)
Output the type declaration of a given nameMap<String,String>
importMapping()
protected void
initalizeSpecialCharacterMapping()
Initialize special character mappingString
initialCaps(String name)
Capitalize the stringMap<String,String>
instantiationTypes()
boolean
isDataTypeBinary(String dataType)
boolean
isDataTypeFile(String dataType)
boolean
isHideGenerationTimestamp()
protected boolean
isModelObject(io.swagger.models.ModelImpl model)
boolean
isPrimivite(String datatype)
protected Boolean
isPropertyInnerMostEnum(CodegenProperty property)
Update property for map containerboolean
isRemoveOperationIdPrefix()
protected boolean
isReservedWord(String word)
boolean
isSkipOverwrite()
boolean
isUsingFlattenSpec()
Set<String>
languageSpecificPrimitives()
String
modelDocFileFolder()
Map<String,String>
modelDocTemplateFiles()
String
modelFileFolder()
String
modelFilename(String templateName, String modelName)
String
modelPackage()
Map<String,String>
modelTemplateFiles()
String
modelTestFileFolder()
Map<String,String>
modelTestTemplateFiles()
protected boolean
needToImport(String type)
Check the type to see if it needs import the library/module/packageString
outputFolder()
Map<String,Object>
postProcessAllModels(Map<String,Object> objs)
void
postProcessModelProperties(CodegenModel model)
void
postProcessModelProperty(CodegenModel model, CodegenProperty property)
Map<String,Object>
postProcessModels(Map<String,Object> objs)
Map<String,Object>
postProcessModelsEnum(Map<String,Object> objs)
post process enum defined in model's propertiesMap<String,Object>
postProcessOperations(Map<String,Object> objs)
Map<String,Object>
postProcessOperationsWithModels(Map<String,Object> objs, List<Object> allModels)
void
postProcessParameter(CodegenParameter parameter)
Map<String,Object>
postProcessSupportingFileData(Map<String,Object> objs)
void
preprocessSwagger(io.swagger.models.Swagger swagger)
com.samskivert.mustache.Mustache.Compiler
processCompiler(com.samskivert.mustache.Mustache.Compiler compiler)
void
processOpts()
void
processSwagger(io.swagger.models.Swagger swagger)
protected void
readRefModelParameter(io.swagger.models.RefModel refModel, CodegenParameter codegenParameter, Set<String> imports)
String
removeNonNameElementToCamelCase(String name)
Remove characters not suitable for variable or method name from the input and camelize itprotected String
removeNonNameElementToCamelCase(String name, String nonNameElementPattern)
Remove characters that is not good to be included in method name from the input and camelize itSet<String>
reservedWords()
Map<String,String>
reservedWordsMappings()
String
sanitizeName(String name)
Sanitize name (parameter, property, method, etc)String
sanitizeTag(String tag)
Sanitize tagvoid
setAllowUnicodeIdentifiers(Boolean allowUnicodeIdentifiers)
void
setApiPackage(String apiPackage)
void
setCommonTemplateDir(String commonTemplateDir)
void
setEnsureUniqueParams(Boolean ensureUniqueParams)
void
setGitRepoBaseURL(String gitRepoBaseURL)
Set Git repo Base URL.void
setGitRepoId(String gitRepoId)
Set Git repo ID.void
setGitUserId(String gitUserId)
Set Git user ID.void
setHideGenerationTimestamp(boolean hideGenerationTimestamp)
void
setHttpUserAgent(String httpUserAgent)
Set HTTP user agent.void
setIgnoreFilePathOverride(String ignoreFileOverride)
Sets an override location for the .swagger-codegen.ignore location for the first code generation.void
setIgnoreImportMapping(boolean ignoreImportMapping)
void
setInputSpec(String inputSpec)
void
setLibrary(String library)
Set library template (sub-template).void
setModelNamePrefix(String modelNamePrefix)
void
setModelNameSuffix(String modelNameSuffix)
void
setModelPackage(String modelPackage)
protected void
setNonArrayMapProperty(CodegenProperty property, String type)
void
setOutputDir(String dir)
void
setParameterBooleanFlagWithCodegenProperty(CodegenParameter parameter, CodegenProperty property)
Set CodegenParameter boolean flag using CodegenProperty.void
setParameterExampleValue(CodegenParameter p)
Return the example value of the parameter.void
setReleaseNote(String releaseNote)
Set release note.void
setRemoveOperationIdPrefix(boolean removeOperationIdPrefix)
protected void
setReservedWordsLowerCase(List<String> words)
void
setSkipAliasGeneration(Boolean skipAliasGeneration)
void
setSkipOverwrite(boolean skipOverwrite)
void
setSortParamsByRequiredFlag(Boolean sortParamsByRequiredFlag)
void
setTemplateDir(String templateDir)
boolean
shouldOverwrite(String filename)
String
snakeCase(String name)
Return the snake-case of the stringMap<String,String>
supportedLibraries()
All library templates supported.List<SupportingFile>
supportingFiles()
String
templateDir()
String
testPackage()
static String
titleCase(String input)
Capitalise first character of stringString
toApiDocFilename(String name)
Return the file name of the Api DocumentationString
toApiFilename(String name)
Return the file name of the Api TestString
toApiImport(String name)
Return the fully-qualified "Api" name for importString
toApiName(String name)
Output the API (class) name (capitalized) ending with "Api" 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
toBooleanGetter(String name)
Output the Getter name for boolean property, e.g.String
toDefaultValue(io.swagger.models.properties.Property p)
Return the default value of the propertyString
toDefaultValueWithParam(String name, io.swagger.models.properties.Property p)
Return the property initialized from a data object Useful for initialization with a plain object in JavascriptString
toEnumDefaultValue(String value, String datatype)
Return the enum default value in the language specified formatString
toEnumName(CodegenProperty property)
Return the Enum name (e.g.String
toEnumValue(String value, String datatype)
Return the enum value in the language specified format e.g.String
toEnumVarName(String value, String datatype)
Return the sanitized variable name for enumprotected List<Map<String,Object>>
toExamples(Map<String,Object> examples)
String
toExampleValue(io.swagger.models.properties.Property p)
Return the example value of the propertyString
toGetter(String name)
Output the Getter name, e.g.String
toInstantiationType(io.swagger.models.properties.Property p)
Return the instantiation type of the property, especially for map and arrayString
toModelDocFilename(String name)
Return the capitalized file name of the model documentationString
toModelFilename(String name)
Return the capitalized file name of the modelString
toModelImport(String name)
Return the fully-qualified "Model" name for importString
toModelName(String name)
Output the proper model name (capitalized).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
toSetter(String name)
Output the Getter name, e.g.String
toVarName(String name)
Return the variable name by removing invalid characters and proper escaping if it's a reserved word.Map<String,String>
typeMapping()
static String
underscore(String word)
Underscore the given word.void
updateCodegenPropertyEnum(CodegenProperty var)
Update codegen property's enum by adding "enumVars" (with name and value)protected void
updateDataTypeWithEnumForArray(CodegenProperty property)
Update datatypeWithEnum for array containerprotected void
updateDataTypeWithEnumForMap(CodegenProperty property)
Update datatypeWithEnum for map containerprotected void
updatePropertyForArray(CodegenProperty property, CodegenProperty innerProperty)
Update property for array(list) containerprotected void
updatePropertyForMap(CodegenProperty property, CodegenProperty innerProperty)
Update property for map containerMap<String,Object>
vendorExtensions()
void
writeOptional(String outputFolder, SupportingFile supportingFile)
Only write if the file doesn't existvoid
writePropertyBack(String propertyKey, boolean value)
-
-
-
Field Detail
-
LOGGER
protected static final org.slf4j.Logger LOGGER
-
inputSpec
protected String inputSpec
-
outputFolder
protected String outputFolder
-
modelPackage
protected String modelPackage
-
apiPackage
protected String apiPackage
-
fileSuffix
protected String fileSuffix
-
modelNamePrefix
protected String modelNamePrefix
-
modelNameSuffix
protected String modelNameSuffix
-
testPackage
protected String testPackage
-
templateDir
protected String templateDir
-
embeddedTemplateDir
protected String embeddedTemplateDir
-
commonTemplateDir
protected String commonTemplateDir
-
supportingFiles
protected List<SupportingFile> supportingFiles
-
skipOverwrite
protected boolean skipOverwrite
-
removeOperationIdPrefix
protected boolean removeOperationIdPrefix
-
supportsInheritance
protected boolean supportsInheritance
-
supportsMixins
protected boolean supportsMixins
-
library
protected String library
-
sortParamsByRequiredFlag
protected Boolean sortParamsByRequiredFlag
-
ensureUniqueParams
protected Boolean ensureUniqueParams
-
allowUnicodeIdentifiers
protected Boolean allowUnicodeIdentifiers
-
gitUserId
protected String gitUserId
-
gitRepoId
protected String gitRepoId
-
releaseNote
protected String releaseNote
-
gitRepoBaseURL
protected String gitRepoBaseURL
-
httpUserAgent
protected String httpUserAgent
-
hideGenerationTimestamp
protected Boolean hideGenerationTimestamp
-
skipAliasGeneration
protected Boolean skipAliasGeneration
-
ignoreImportMapping
protected boolean ignoreImportMapping
-
ignoreFilePathOverride
protected String ignoreFilePathOverride
-
-
Constructor Detail
-
DefaultCodegen
public DefaultCodegen()
Default constructor. This method will map between Swagger type and language-specified type, as well as mapping between Swagger type and the corresponding import statement for the language. This will also add some language specified CLI options, if any. returns string presentation of the example path (it's a constructor)
-
-
Method Detail
-
processOpts
public void processOpts()
-
fixUpParentAndInterfaces
protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String,CodegenModel> allModels)
Fix up all parent and interface CodegenModel references.- Parameters:
allModels
-
-
postProcessModelsEnum
public Map<String,Object> postProcessModelsEnum(Map<String,Object> objs)
post process enum defined in model's properties- Parameters:
objs
- Map of models- Returns:
- maps of models with better enum support
-
findCommonPrefixOfVars
public String findCommonPrefixOfVars(List<Object> vars)
Returns the common prefix of variables for enum naming if two or more variables are present.- Parameters:
vars
- List of variable names- Returns:
- the common prefix for naming
-
ensureUniqueName
protected String ensureUniqueName(Map<String,Integer> uniqueNames, String name)
If necessary, appends a suffix to enforce uniqueness of names within a namespace.- Parameters:
uniqueNames
- Counts name occurrences within a namespace.name
- The proposed name.- Returns:
name
, uniquely suffixed as necessary.
-
toEnumDefaultValue
public String toEnumDefaultValue(String value, String datatype)
Return the enum default value in the language specified format- Parameters:
value
- enum variable namedatatype
- data type- Returns:
- the default value for the enum
-
toEnumValue
public String toEnumValue(String value, String datatype)
Return the enum value in the language specified format e.g. status becomes "status"- Parameters:
value
- enum variable namedatatype
- data type- Returns:
- the sanitized value for enum
-
toEnumVarName
public String toEnumVarName(String value, String datatype)
Return the sanitized variable name for enum- Parameters:
value
- enum variable namedatatype
- data type- Returns:
- the sanitized variable name for enum
-
isPrimivite
public boolean isPrimivite(String datatype)
-
postProcessOperationsWithModels
public Map<String,Object> postProcessOperationsWithModels(Map<String,Object> objs, List<Object> allModels)
-
postProcessSupportingFileData
public Map<String,Object> postProcessSupportingFileData(Map<String,Object> objs)
-
postProcessModelProperties
public void postProcessModelProperties(CodegenModel model)
-
postProcessModelProperty
public void postProcessModelProperty(CodegenModel model, CodegenProperty property)
-
postProcessParameter
public void postProcessParameter(CodegenParameter parameter)
-
preprocessSwagger
public void preprocessSwagger(io.swagger.models.Swagger swagger)
-
processSwagger
public void processSwagger(io.swagger.models.Swagger swagger)
-
processCompiler
public com.samskivert.mustache.Mustache.Compiler processCompiler(com.samskivert.mustache.Mustache.Compiler compiler)
-
escapeUnsafeCharacters
public String escapeUnsafeCharacters(String input)
override with any special text escaping logic to handle unsafe characters so as to avoid code injection- Parameters:
input
- String to be cleaned up- Returns:
- string with unsafe characters removed or escaped
-
escapeQuotationMark
public String escapeQuotationMark(String input)
Escape single and/or double quote to avoid code injection- Parameters:
input
- String to be cleaned up- Returns:
- string with quotation mark removed or escaped
-
testPackage
public String testPackage()
-
modelPackage
public String modelPackage()
-
apiPackage
public String apiPackage()
-
fileSuffix
public String fileSuffix()
-
templateDir
public String templateDir()
-
embeddedTemplateDir
public String embeddedTemplateDir()
-
getCommonTemplateDir
public String getCommonTemplateDir()
-
setCommonTemplateDir
public void setCommonTemplateDir(String commonTemplateDir)
-
apiFileFolder
public String apiFileFolder()
-
modelFileFolder
public String modelFileFolder()
-
apiTestFileFolder
public String apiTestFileFolder()
-
modelTestFileFolder
public String modelTestFileFolder()
-
apiDocFileFolder
public String apiDocFileFolder()
-
modelDocFileFolder
public String modelDocFileFolder()
-
supportingFiles
public List<SupportingFile> supportingFiles()
-
outputFolder
public String outputFolder()
-
setOutputDir
public void setOutputDir(String dir)
-
getOutputDir
public String getOutputDir()
-
getInputSpec
public String getInputSpec()
-
setInputSpec
public void setInputSpec(String inputSpec)
-
setTemplateDir
public void setTemplateDir(String templateDir)
-
setModelPackage
public void setModelPackage(String modelPackage)
-
setModelNamePrefix
public void setModelNamePrefix(String modelNamePrefix)
-
setModelNameSuffix
public void setModelNameSuffix(String modelNameSuffix)
-
setApiPackage
public void setApiPackage(String apiPackage)
-
setSortParamsByRequiredFlag
public void setSortParamsByRequiredFlag(Boolean sortParamsByRequiredFlag)
-
setEnsureUniqueParams
public void setEnsureUniqueParams(Boolean ensureUniqueParams)
-
setAllowUnicodeIdentifiers
public void setAllowUnicodeIdentifiers(Boolean allowUnicodeIdentifiers)
-
toRegularExpression
public String toRegularExpression(String pattern)
Return the regular expression/JSON schema pattern (http://json-schema.org/latest/json-schema-validation.html#anchor33)- Parameters:
pattern
- the pattern (regular expression)- Returns:
- properly-escaped pattern
-
toApiFilename
public String toApiFilename(String name)
Return the file name of the Api Test- Parameters:
name
- the file name of the Api- Returns:
- the file name of the Api
-
toApiDocFilename
public String toApiDocFilename(String name)
Return the file name of the Api Documentation- Parameters:
name
- the file name of the Api- Returns:
- the file name of the Api
-
toApiTestFilename
public String toApiTestFilename(String name)
Return the file name of the Api Test- Parameters:
name
- the file name of the Api- Returns:
- the file name of the Api
-
toApiVarName
public String toApiVarName(String name)
Return the variable name in the Api- Parameters:
name
- the varible name of the Api- Returns:
- the snake-cased variable name
-
toModelFilename
public String toModelFilename(String name)
Return the capitalized file name of the model- Parameters:
name
- the model name- Returns:
- the file name of the model
-
toModelTestFilename
public String toModelTestFilename(String name)
Return the capitalized file name of the model test- Parameters:
name
- the model name- Returns:
- the file name of the model
-
toModelDocFilename
public String toModelDocFilename(String name)
Return the capitalized file name of the model documentation- Parameters:
name
- the model name- Returns:
- the file name of the model
-
toOperationId
public String toOperationId(String operationId)
Return the operation ID (method name)- Parameters:
operationId
- operation ID- Returns:
- the sanitized method name
-
toVarName
public String toVarName(String name)
Return the variable name by removing invalid characters and proper escaping if it's a reserved word.- Parameters:
name
- the variable name- Returns:
- the sanitized variable name
-
toParamName
public String toParamName(String name)
Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.- Parameters:
name
- Codegen property object- Returns:
- the sanitized parameter name
-
toEnumName
public String toEnumName(CodegenProperty property)
Return the Enum name (e.g. StatusEnum given 'status')- Parameters:
property
- Codegen property- Returns:
- the Enum name
-
escapeReservedWord
public String escapeReservedWord(String name)
Return the escaped name of the reserved word- Parameters:
name
- the name to be escaped- Returns:
- the escaped reserved word throws Runtime exception as reserved word is not allowed (default behavior)
-
toModelImport
public String toModelImport(String name)
Return the fully-qualified "Model" name for import- Parameters:
name
- the name of the "Model"- Returns:
- the fully-qualified "Model" name for import
-
toApiImport
public String toApiImport(String name)
Return the fully-qualified "Api" name for import- Parameters:
name
- the name of the "Api"- Returns:
- the fully-qualified "Api" name for import
-
initalizeSpecialCharacterMapping
protected void initalizeSpecialCharacterMapping()
Initialize special character mapping
-
getSymbolName
protected String getSymbolName(String input)
Return the symbol name of a symbol- Parameters:
input
- Symbol (e.g. $)- Returns:
- Symbol name (e.g. Dollar)
-
generateExamplePath
public String generateExamplePath(String path, io.swagger.models.Operation operation)
Return the example path- Parameters:
path
- the path of the operationoperation
- Swagger operation object- Returns:
- string presentation of the example path
-
toInstantiationType
public String toInstantiationType(io.swagger.models.properties.Property p)
Return the instantiation type of the property, especially for map and array- Parameters:
p
- Swagger property object- Returns:
- string presentation of the instantiation type of the property
-
setParameterExampleValue
public void setParameterExampleValue(CodegenParameter p)
Return the example value of the parameter.- Parameters:
p
- Swagger property object
-
toExampleValue
public String toExampleValue(io.swagger.models.properties.Property p)
Return the example value of the property- Parameters:
p
- Swagger property object- Returns:
- string presentation of the example value of the property
-
toDefaultValue
public String toDefaultValue(io.swagger.models.properties.Property p)
Return the default value of the property- Parameters:
p
- Swagger property object- Returns:
- string presentation of the default value of the property
-
toDefaultValueWithParam
public String toDefaultValueWithParam(String name, io.swagger.models.properties.Property p)
Return the property initialized from a data object Useful for initialization with a plain object in Javascript- Parameters:
name
- Name of the property objectp
- Swagger property object- Returns:
- string presentation of the default value of the property
-
getSwaggerType
public String getSwaggerType(io.swagger.models.properties.Property p)
returns the swagger type for the property- Parameters:
p
- Swagger property object- Returns:
- string presentation of the type
-
snakeCase
public String snakeCase(String name)
Return the snake-case of the string- Parameters:
name
- string to be snake-cased- Returns:
- snake-cased string
-
initialCaps
public String initialCaps(String name)
Capitalize the string- Parameters:
name
- string to be capitalized- Returns:
- capitalized string
-
getTypeDeclaration
public String getTypeDeclaration(String name)
Output the type declaration of a given name- Parameters:
name
- name- Returns:
- a string presentation of the type
-
getTypeDeclaration
public String getTypeDeclaration(io.swagger.models.properties.Property p)
Output the type declaration of the property- Parameters:
p
- Swagger Property object- Returns:
- a string presentation of the property type
-
getAlias
public String getAlias(String name)
Determine the type alias for the given type if it exists. This feature is only used for Java, because the language does not have a aliasing mechanism of its own.- Parameters:
name
- The type name.- Returns:
- The alias of the given type, if it exists. If there is no alias for this type, then returns the input type name.
-
toBooleanGetter
public String toBooleanGetter(String name)
Output the Getter name for boolean property, e.g. getActive- Parameters:
name
- the name of the property- Returns:
- getter name based on naming convention
-
toGetter
public String toGetter(String name)
Output the Getter name, e.g. getSize- Parameters:
name
- the name of the property- Returns:
- getter name based on naming convention
-
toSetter
public String toSetter(String name)
Output the Getter name, e.g. getSize- Parameters:
name
- the name of the property- Returns:
- setter name based on naming convention
-
toApiName
public String toApiName(String name)
Output the API (class) name (capitalized) ending with "Api" Return DefaultApi if name is empty- Parameters:
name
- the name of the Api- Returns:
- capitalized Api name ending with "Api"
-
toModelName
public String toModelName(String name)
Output the proper model name (capitalized). In case the name belongs to the TypeSystem it won't be renamed.- Parameters:
name
- the name of the model- Returns:
- capitalized model name
-
fromModel
public CodegenModel fromModel(String name, io.swagger.models.Model model)
Convert Swagger Model object to Codegen Model object without providing all model definitions- Parameters:
name
- the name of the modelmodel
- Swagger Model object- Returns:
- Codegen Model object
-
fromModel
public CodegenModel fromModel(String name, io.swagger.models.Model model, Map<String,io.swagger.models.Model> allDefinitions)
Convert Swagger Model object to Codegen Model object- Parameters:
name
- the name of the modelmodel
- Swagger Model objectallDefinitions
- a map of all Swagger models from the spec- Returns:
- Codegen Model object
-
addAdditionPropertiesToCodeGenModel
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, io.swagger.models.ModelImpl swaggerModel)
-
addProperties
protected void addProperties(Map<String,io.swagger.models.properties.Property> properties, List<String> required, io.swagger.models.Model model, Map<String,io.swagger.models.Model> allDefinitions)
-
getterAndSetterCapitalize
public String getterAndSetterCapitalize(String name)
Camelize the method name of the getter and setter- Parameters:
name
- string to be camelized- Returns:
- Camelized string
-
fromProperty
public CodegenProperty fromProperty(String name, io.swagger.models.properties.Property p)
Convert Swagger Property object to Codegen Property object- Parameters:
name
- name of the propertyp
- Swagger property object- Returns:
- Codegen Property object
-
updatePropertyForArray
protected void updatePropertyForArray(CodegenProperty property, CodegenProperty innerProperty)
Update property for array(list) container- Parameters:
property
- Codegen propertyinnerProperty
- Codegen inner property of map or list
-
updatePropertyForMap
protected void updatePropertyForMap(CodegenProperty property, CodegenProperty innerProperty)
Update property for map container- Parameters:
property
- Codegen propertyinnerProperty
- Codegen inner property of map or list
-
isPropertyInnerMostEnum
protected Boolean isPropertyInnerMostEnum(CodegenProperty property)
Update property for map container- Parameters:
property
- Codegen property- Returns:
- True if the inner most type is enum
-
getInnerEnumAllowableValues
protected Map<String,Object> getInnerEnumAllowableValues(CodegenProperty property)
-
updateDataTypeWithEnumForArray
protected void updateDataTypeWithEnumForArray(CodegenProperty property)
Update datatypeWithEnum for array container- Parameters:
property
- Codegen property
-
updateDataTypeWithEnumForMap
protected void updateDataTypeWithEnumForMap(CodegenProperty property)
Update datatypeWithEnum for map container- Parameters:
property
- Codegen property
-
setNonArrayMapProperty
protected void setNonArrayMapProperty(CodegenProperty property, String type)
-
findMethodResponse
protected io.swagger.models.Response findMethodResponse(Map<String,io.swagger.models.Response> responses)
Override with any special handling of response codes- Parameters:
responses
- Swagger Operation's responses- Returns:
- default method response or <tt>null</tt> if not found
-
fromOperation
public CodegenOperation fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions)
Convert Swagger Operation object to Codegen Operation object (without providing a Swagger object)- Parameters:
path
- the path of the operationhttpMethod
- HTTP methodoperation
- Swagger operation objectdefinitions
- a map of Swagger models- Returns:
- Codegen Operation object
-
fromOperation
public CodegenOperation fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions, io.swagger.models.Swagger swagger)
Convert Swagger Operation object to Codegen Operation object- Parameters:
path
- the path of the operationhttpMethod
- HTTP methodoperation
- Swagger operation objectdefinitions
- a map of Swagger modelsswagger
- a Swagger object representing the spec- Returns:
- Codegen Operation object
-
fromResponse
public CodegenResponse fromResponse(String responseCode, io.swagger.models.Response response)
Convert Swagger Response object to Codegen Response object- Parameters:
responseCode
- HTTP response coderesponse
- Swagger Response object- Returns:
- Codegen Response object
-
fromParameter
public CodegenParameter fromParameter(io.swagger.models.parameters.Parameter param, Set<String> imports)
Convert Swagger Parameter object to Codegen Parameter object- Parameters:
param
- Swagger parameter objectimports
- set of imports for library/package/module- Returns:
- Codegen Parameter object
-
getParameterDataType
protected String getParameterDataType(io.swagger.models.parameters.Parameter parameter, io.swagger.models.properties.Property property)
Returns the data type of a parameter. Returns null by default to use the CodegenProperty.datatype value- Parameters:
parameter
-property
-- Returns:
-
isDataTypeBinary
public boolean isDataTypeBinary(String dataType)
-
isDataTypeFile
public boolean isDataTypeFile(String dataType)
-
readRefModelParameter
protected void readRefModelParameter(io.swagger.models.RefModel refModel, CodegenParameter codegenParameter, Set<String> imports)
-
fromSecurity
public List<CodegenSecurity> fromSecurity(Map<String,io.swagger.models.auth.SecuritySchemeDefinition> schemes)
Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects- Parameters:
schemes
- a map of Swagger SecuritySchemeDefinition object- Returns:
- a list of Codegen Security objects
-
isReservedWord
protected boolean isReservedWord(String word)
-
getOrGenerateOperationId
protected String getOrGenerateOperationId(io.swagger.models.Operation operation, String path, String httpMethod)
Get operationId from the operation object, and if it's blank, generate a new one from the given parameters.- Parameters:
operation
- the operation objectpath
- the path of the operationhttpMethod
- the HTTP method of the operation- Returns:
- the (generated) operationId
-
needToImport
protected boolean needToImport(String type)
Check the type to see if it needs import the library/module/package- Parameters:
type
- name of the type- Returns:
- true if the library/module/package of the corresponding type needs to be imported
-
addOperationToGroup
public void addOperationToGroup(String tag, String resourcePath, io.swagger.models.Operation operation, CodegenOperation co, Map<String,List<CodegenOperation>> operations)
Add operation to group- Parameters:
tag
- name of the tagresourcePath
- path of the resourceoperation
- Swagger Operation objectco
- Codegen Operation objectoperations
- map of Codegen operations
-
addParentContainer
protected void addParentContainer(CodegenModel m, String name, io.swagger.models.properties.Property property)
-
underscore
public static String underscore(String word)
Underscore the given word. Copied from Twitter elephant bird https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java- Parameters:
word
- The word- Returns:
- The underscored version of the word
-
dashize
protected String dashize(String word)
Dashize the given word.- Parameters:
word
- The word- Returns:
- The dashized version of the word, e.g. "my-name"
-
addImport
protected void addImport(CodegenModel m, String type)
-
getAllAliases
protected Map<String,String> getAllAliases(Map<String,io.swagger.models.Model> allDefinitions)
Determine all of the types in the model definitions that are aliases of simple types.- Parameters:
allDefinitions
- The complete set of model definitions.- Returns:
- A mapping from model name to type alias
-
removeNonNameElementToCamelCase
public String removeNonNameElementToCamelCase(String name)
Remove characters not suitable for variable or method name from the input and camelize it- Parameters:
name
- string to be camelize- Returns:
- camelized string
-
removeNonNameElementToCamelCase
protected String removeNonNameElementToCamelCase(String name, String nonNameElementPattern)
Remove characters that is not good to be included in method name from the input and camelize it- Parameters:
name
- string to be camelizenonNameElementPattern
- a regex pattern of the characters that is not good to be included in name- Returns:
- camelized string
-
camelize
public static String camelize(String word)
Camelize name (parameter, property, method, etc) with upper case for first letter copied from Twitter elephant bird https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java- Parameters:
word
- string to be camelize- Returns:
- camelized string
-
camelize
public static String camelize(String word, boolean lowercaseFirstLetter)
Camelize name (parameter, property, method, etc)- Parameters:
word
- string to be camelizelowercaseFirstLetter
- lower case for first letter if set to true- Returns:
- camelized string
-
apiDocFilename
public String apiDocFilename(String templateName, String tag)
Return the full path and API documentation file- Parameters:
templateName
- template nametag
- tag- Returns:
- the API documentation file name with full path
-
apiTestFilename
public String apiTestFilename(String templateName, String tag)
Return the full path and API test file- Parameters:
templateName
- template nametag
- tag- Returns:
- the API test file name with full path
-
shouldOverwrite
public boolean shouldOverwrite(String filename)
-
isSkipOverwrite
public boolean isSkipOverwrite()
-
setSkipOverwrite
public void setSkipOverwrite(boolean skipOverwrite)
-
setSkipAliasGeneration
public void setSkipAliasGeneration(Boolean skipAliasGeneration)
-
getSkipAliasGeneration
public Boolean getSkipAliasGeneration()
-
isRemoveOperationIdPrefix
public boolean isRemoveOperationIdPrefix()
-
setRemoveOperationIdPrefix
public void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix)
-
isHideGenerationTimestamp
public boolean isHideGenerationTimestamp()
-
setHideGenerationTimestamp
public void setHideGenerationTimestamp(boolean hideGenerationTimestamp)
-
supportedLibraries
public Map<String,String> supportedLibraries()
All library templates supported. (key: library name, value: library description)- Returns:
- the supported libraries
-
setLibrary
public void setLibrary(String library)
Set library template (sub-template).- Parameters:
library
- Library template
-
getLibrary
public String getLibrary()
Library template (sub-template).- Returns:
- Library template
-
setGitUserId
public void setGitUserId(String gitUserId)
Set Git user ID.- Parameters:
gitUserId
- Git user ID
-
getGitUserId
public String getGitUserId()
Git user ID- Returns:
- Git user ID
-
setGitRepoId
public void setGitRepoId(String gitRepoId)
Set Git repo ID.- Parameters:
gitRepoId
- Git repo ID
-
getGitRepoId
public String getGitRepoId()
Git repo ID- Returns:
- Git repo ID
-
setGitRepoBaseURL
public void setGitRepoBaseURL(String gitRepoBaseURL)
Set Git repo Base URL.- Parameters:
gitRepoBaseURL
- Git repo ID
-
getGitRepoBaseURL
public String getGitRepoBaseURL()
Git repo Base URL- Returns:
- Git Base URL
-
setReleaseNote
public void setReleaseNote(String releaseNote)
Set release note.- Parameters:
releaseNote
- Release note
-
getReleaseNote
public String getReleaseNote()
Release note- Returns:
- Release note
-
setHttpUserAgent
public void setHttpUserAgent(String httpUserAgent)
Set HTTP user agent.- Parameters:
httpUserAgent
- HTTP user agent
-
getHttpUserAgent
public String getHttpUserAgent()
HTTP user agent- Returns:
- HTTP user agent
-
buildLibraryCliOption
protected CliOption buildLibraryCliOption(Map<String,String> supportedLibraries)
-
sanitizeName
public String sanitizeName(String name)
Sanitize name (parameter, property, method, etc)- Parameters:
name
- string to be sanitize- Returns:
- sanitized string
-
sanitizeTag
public String sanitizeTag(String tag)
Sanitize tag- Parameters:
tag
- Tag- Returns:
- Sanitized tag
-
writeOptional
public void writeOptional(String outputFolder, SupportingFile supportingFile)
Only write if the file doesn't exist- Parameters:
outputFolder
- Output foldersupportingFile
- Supporting file
-
setParameterBooleanFlagWithCodegenProperty
public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter parameter, CodegenProperty property)
Set CodegenParameter boolean flag using CodegenProperty.- Parameters:
parameter
- Codegen Parameterproperty
- Codegen property
-
updateCodegenPropertyEnum
public void updateCodegenPropertyEnum(CodegenProperty var)
Update codegen property's enum by adding "enumVars" (with name and value)- Parameters:
var
- list of CodegenProperty
-
addRegularExpressionDelimiter
public String addRegularExpressionDelimiter(String pattern)
If the pattern misses the delimiter, add "/" to the beginning and end Otherwise, return the original pattern- Parameters:
pattern
- the pattern (regular expression)- Returns:
- the pattern with delimiter
-
convertPropertyToBooleanAndWriteBack
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey)
reads propertyKey from additionalProperties, converts it to a boolean and writes it back to additionalProperties to be usable as a boolean in mustache files.- Parameters:
propertyKey
- property key- Returns:
- property value as boolean
-
getIgnoreFilePathOverride
public String getIgnoreFilePathOverride()
Provides an override location, if any is specified, for the .swagger-codegen-ignore. This is originally intended for the first generation only.- Returns:
- a string of the full path to an override ignore file.
-
setIgnoreFilePathOverride
public void setIgnoreFilePathOverride(String ignoreFileOverride)
Sets an override location for the .swagger-codegen.ignore location for the first code generation.- Parameters:
ignoreFileOverride
- The full path to an ignore file
-
convertPropertyToBoolean
public boolean convertPropertyToBoolean(String propertyKey)
-
getExamples
protected List<Map<String,String>> getExamples(Map<String,io.swagger.models.Model> definitions, Map<String,Object> examples, List<String> mediaTypes, Object object)
-
writePropertyBack
public void writePropertyBack(String propertyKey, boolean value)
-
configureDataForTestTemplate
protected void configureDataForTestTemplate(CodegenOperation codegenOperation)
-
getIgnoreImportMapping
public boolean getIgnoreImportMapping()
-
setIgnoreImportMapping
public void setIgnoreImportMapping(boolean ignoreImportMapping)
-
defaultIgnoreImportMappingOption
public boolean defaultIgnoreImportMappingOption()
-
isModelObject
protected boolean isModelObject(io.swagger.models.ModelImpl model)
-
isUsingFlattenSpec
public boolean isUsingFlattenSpec()
-
-