public class DefaultCodegen extends Object
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
additionalProperties |
protected String |
apiPackage |
protected Map<String,String> |
apiTemplateFiles |
protected List<CliOption> |
cliOptions |
protected Set<String> |
defaultIncludes |
protected String |
embeddedTemplateDir |
protected Boolean |
ensureUniqueParams |
protected String |
fileSuffix |
protected Map<String,String> |
importMapping |
protected Map<String,String> |
instantiationTypes |
protected Set<String> |
languageSpecificPrimitives |
protected String |
library |
protected static org.slf4j.Logger |
LOGGER |
protected String |
modelPackage |
protected Map<String,String> |
modelTemplateFiles |
protected String |
outputFolder |
protected Set<String> |
reservedWords |
protected boolean |
skipOverwrite |
protected Boolean |
sortParamsByRequiredFlag |
protected Map<String,String> |
supportedLibraries |
protected List<SupportingFile> |
supportingFiles |
protected boolean |
supportsInheritance |
protected String |
templateDir |
protected Map<String,String> |
typeMapping |
Constructor and Description |
---|
DefaultCodegen()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
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 group
|
String |
apiFileFolder() |
String |
apiFilename(String templateName,
String tag) |
String |
apiPackage() |
Map<String,String> |
apiTemplateFiles() |
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.java
|
static String |
camelize(String word,
boolean lowercaseFirstLetter)
Camelize name (parameter, property, method, etc)
|
List<CliOption> |
cliOptions() |
protected String |
dashize(String word)
Dashize the given word.
|
Set<String> |
defaultIncludes() |
String |
embeddedTemplateDir() |
String |
escapeReservedWord(String name)
Return the escaped name of the reserved word
|
String |
escapeText(String input) |
String |
fileSuffix() |
CodegenModel |
fromModel(String name,
io.swagger.models.Model model)
Convert Swagger Model object to Codegen Model object without providing all model definitions
|
CodegenModel |
fromModel(String name,
io.swagger.models.Model model,
Map<String,io.swagger.models.Model> allDefinitions)
Convert Swagger Model object to Codegen Model object
|
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)
|
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
|
CodegenParameter |
fromParameter(io.swagger.models.parameters.Parameter param,
Set<String> imports)
Convert Swagger Parameter object to Codegen Parameter object
|
CodegenProperty |
fromProperty(String name,
io.swagger.models.properties.Property p)
Convert Swagger Property object to Codegen Property object
|
CodegenResponse |
fromResponse(String responseCode,
io.swagger.models.Response response)
Convert Swagger Response object to Codegen Response object
|
List<CodegenSecurity> |
fromSecurity(Map<String,io.swagger.models.auth.SecuritySchemeDefinition> schemes)
Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects
|
String |
generateExamplePath(String path,
io.swagger.models.Operation operation)
Return the example path
|
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() |
String |
getSwaggerType(io.swagger.models.properties.Property p)
returns the swagger type for the property
|
String |
getterAndSetterCapitalize(String name)
Camelize the method name of the getter and setter
|
String |
getTypeDeclaration(io.swagger.models.properties.Property p)
Output the type declaration of the property
|
String |
getTypeDeclaration(String name)
Output the type declaration of a given name
|
Map<String,String> |
importMapping() |
String |
initialCaps(String name)
Capitalize the string
|
Map<String,String> |
instantiationTypes() |
boolean |
isSkipOverwrite() |
Set<String> |
languageSpecificPrimitives() |
String |
modelFileFolder() |
String |
modelPackage() |
Map<String,String> |
modelTemplateFiles() |
protected boolean |
needToImport(String type)
Check the type to see if it needs import the library/module/package
|
String |
outputFolder() |
void |
postProcessModelProperty(CodegenModel model,
CodegenProperty property) |
Map<String,Object> |
postProcessModels(Map<String,Object> objs) |
Map<String,Object> |
postProcessOperations(Map<String,Object> objs) |
void |
postProcessParameter(CodegenParameter parameter) |
Map<String,Object> |
postProcessSupportingFileData(Map<String,Object> objs) |
void |
preprocessSwagger(io.swagger.models.Swagger swagger) |
void |
processOpts() |
void |
processSwagger(io.swagger.models.Swagger swagger) |
String |
removeNonNameElementToCamelCase(String name)
Remove characters not suitable for variable or method name from the input and camelize it
|
Set<String> |
reservedWords() |
String |
sanitizeName(String name)
Sanitize name (parameter, property, method, etc)
|
void |
setApiPackage(String apiPackage) |
void |
setEnsureUniqueParams(Boolean ensureUniqueParams) |
void |
setLibrary(String library) |
void |
setModelPackage(String modelPackage) |
protected void |
setNonArrayMapProperty(CodegenProperty property,
String type) |
void |
setOutputDir(String dir) |
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 string
|
Map<String,String> |
supportedLibraries()
All library templates supported.
|
List<SupportingFile> |
supportingFiles() |
String |
templateDir() |
String |
toApiFilename(String name)
Return the file name of the Api
|
String |
toApiImport(String name)
Return the fully-qualified "Api" name for import
|
String |
toApiName(String name)
Output the API (class) name (capitalized) ending with "Api"
Return DefaultApi if name is empty
|
String |
toApiVarName(String name)
Return the variable name in the Api
|
String |
toDefaultValue(io.swagger.models.properties.Property p)
Return the default value of the property
|
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
|
String |
toEnumName(CodegenProperty property)
Return the Enum name (e.g.
|
protected List<Map<String,Object>> |
toExamples(Map<String,Object> examples) |
String |
toInstantiationType(io.swagger.models.properties.Property p)
Return the instantiation type of the property, especially for map and array
|
String |
toModelFilename(String name)
Return the capitalized file name of the model
|
String |
toModelImport(String name)
Return the fully-qualified "Model" name for import
|
String |
toModelName(String name)
Output the proper model name (capitalized)
|
String |
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 |
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.
|
protected static final org.slf4j.Logger LOGGER
protected String outputFolder
protected String modelPackage
protected String apiPackage
protected String fileSuffix
protected String templateDir
protected String embeddedTemplateDir
protected List<SupportingFile> supportingFiles
protected boolean skipOverwrite
protected boolean supportsInheritance
protected String library
protected Boolean sortParamsByRequiredFlag
protected Boolean ensureUniqueParams
public DefaultCodegen()
public void processOpts()
public Map<String,Object> postProcessSupportingFileData(Map<String,Object> objs)
public void postProcessModelProperty(CodegenModel model, CodegenProperty property)
public void postProcessParameter(CodegenParameter parameter)
public void preprocessSwagger(io.swagger.models.Swagger swagger)
public void processSwagger(io.swagger.models.Swagger swagger)
public String modelPackage()
public String apiPackage()
public String fileSuffix()
public String templateDir()
public String embeddedTemplateDir()
public String apiFileFolder()
public String modelFileFolder()
public List<SupportingFile> supportingFiles()
public String outputFolder()
public void setOutputDir(String dir)
public String getOutputDir()
public void setTemplateDir(String templateDir)
public void setModelPackage(String modelPackage)
public void setApiPackage(String apiPackage)
public void setSortParamsByRequiredFlag(Boolean sortParamsByRequiredFlag)
public void setEnsureUniqueParams(Boolean ensureUniqueParams)
public String toApiFilename(String name)
name
- the file name of the Apipublic String toApiVarName(String name)
name
- the varible name of the Apipublic String toModelFilename(String name)
name
- the model namepublic String toOperationId(String operationId)
operationId
- operation IDpublic String toVarName(String name)
name
- the variable namepublic String toParamName(String name)
name
- Codegen property objectpublic String toEnumName(CodegenProperty property)
property
- Codegen property objectpublic String escapeReservedWord(String name)
name
- the name to be escapedpublic String toModelImport(String name)
name
- the name of the "Model"public String toApiImport(String name)
name
- the name of the "Api"public String generateExamplePath(String path, io.swagger.models.Operation operation)
path
- the path of the operationoperation
- Swagger operation objectpublic String toInstantiationType(io.swagger.models.properties.Property p)
p
- Swagger property objectpublic String toDefaultValue(io.swagger.models.properties.Property p)
p
- Swagger property objectpublic String toDefaultValueWithParam(String name, io.swagger.models.properties.Property p)
name
- Name of the property objectp
- Swagger property objectpublic String getSwaggerType(io.swagger.models.properties.Property p)
p
- Swagger property objectpublic String snakeCase(String name)
name
- string to be snake-casedpublic String initialCaps(String name)
name
- string to be capitalizedpublic String getTypeDeclaration(String name)
name
- namepublic String getTypeDeclaration(io.swagger.models.properties.Property p)
p
- Swagger Property objectpublic String toApiName(String name)
name
- the name of the Apipublic String toModelName(String name)
name
- the name of the modelpublic CodegenModel fromModel(String name, io.swagger.models.Model model)
name
- the name of the modelmodel
- Swagger Model objectpublic CodegenModel fromModel(String name, io.swagger.models.Model model, Map<String,io.swagger.models.Model> allDefinitions)
name
- the name of the modelmodel
- Swagger Model objectallDefinitions
- a map of all Swagger models from the specpublic String getterAndSetterCapitalize(String name)
name
- string to be camelizedpublic CodegenProperty fromProperty(String name, io.swagger.models.properties.Property p)
name
- name of the propertyp
- Swagger property objectprotected void setNonArrayMapProperty(CodegenProperty property, String type)
public CodegenOperation fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions)
path
- the path of the operationhttpMethod
- HTTP methodoperation
- Swagger operation objectdefinitions
- a map of Swagger modelspublic CodegenOperation fromOperation(String path, String httpMethod, io.swagger.models.Operation operation, Map<String,io.swagger.models.Model> definitions, io.swagger.models.Swagger swagger)
path
- the path of the operationhttpMethod
- HTTP methodoperation
- Swagger operation objectdefinitions
- a map of Swagger modelsswagger
- a Swagger object representing the specpublic CodegenResponse fromResponse(String responseCode, io.swagger.models.Response response)
responseCode
- HTTP response coderesponse
- Swagger Response objectpublic CodegenParameter fromParameter(io.swagger.models.parameters.Parameter param, Set<String> imports)
param
- Swagger parameter objectimports
- set of imports for library/package/modulepublic List<CodegenSecurity> fromSecurity(Map<String,io.swagger.models.auth.SecuritySchemeDefinition> schemes)
schemes
- a map of Swagger SecuritySchemeDefinition objectprotected String getOrGenerateOperationId(io.swagger.models.Operation operation, String path, String httpMethod)
operation
- the operation objectpath
- the path of the operationhttpMethod
- the HTTP method of the operationprotected boolean needToImport(String type)
type
- name of the typepublic void addOperationToGroup(String tag, String resourcePath, io.swagger.models.Operation operation, CodegenOperation co, Map<String,List<CodegenOperation>> operations)
tag
- name of the tagresourcePath
- path of the resourceoperation
- Swagger Operation objectco
- Codegen Operation objectoperations
- map of Codegen operationspublic static String underscore(String word)
word
- The wordprotected String dashize(String word)
word
- The wordpublic String removeNonNameElementToCamelCase(String name)
name
- string to be camelizepublic static String camelize(String word)
word
- string to be camelizepublic static String camelize(String word, boolean lowercaseFirstLetter)
word
- string to be camelizelowercaseFirstLetter
- lower case for first letter if set to truepublic boolean shouldOverwrite(String filename)
public boolean isSkipOverwrite()
public void setSkipOverwrite(boolean skipOverwrite)
public Map<String,String> supportedLibraries()
public void setLibrary(String library)
public String getLibrary()
protected CliOption buildLibraryCliOption(Map<String,String> supportedLibraries)
Copyright © 2016. All rights reserved.