Class JavaScriptClientCodegen

java.lang.Object
io.swagger.codegen.v3.generators.DefaultCodegenConfig
io.swagger.codegen.v3.generators.javascript.JavaScriptClientCodegen
All Implemented Interfaces:
io.swagger.codegen.v3.CodegenConfig

public class JavaScriptClientCodegen extends DefaultCodegenConfig
  • Field Details

    • PROJECT_NAME

      public static final String PROJECT_NAME
      See Also:
    • MODULE_NAME

      public static final String MODULE_NAME
      See Also:
    • PROJECT_DESCRIPTION

      public static final String PROJECT_DESCRIPTION
      See Also:
    • PROJECT_VERSION

      public static final String PROJECT_VERSION
      See Also:
    • USE_PROMISES

      public static final String USE_PROMISES
      See Also:
    • USE_INHERITANCE

      public static final String USE_INHERITANCE
      See Also:
    • EMIT_MODEL_METHODS

      public static final String EMIT_MODEL_METHODS
      See Also:
    • EMIT_JS_DOC

      public static final String EMIT_JS_DOC
      See Also:
    • USE_ES6

      public static final String USE_ES6
      See Also:
    • LOAD_TEST_DATA_FROM_FILE

      public static final String LOAD_TEST_DATA_FROM_FILE
      See Also:
    • TEST_DATA_FILE

      public static final String TEST_DATA_FILE
      See Also:
    • PRESERVE_LEADING_PARAM_CHAR

      public static final String PRESERVE_LEADING_PARAM_CHAR
      See Also:
    • projectName

      protected String projectName
    • moduleName

      protected String moduleName
    • projectDescription

      protected String projectDescription
    • projectVersion

      protected String projectVersion
    • licenseName

      protected String licenseName
    • invokerPackage

      protected String invokerPackage
    • sourceFolder

      protected String sourceFolder
    • localVariablePrefix

      protected String localVariablePrefix
    • usePromises

      protected boolean usePromises
    • emitModelMethods

      protected boolean emitModelMethods
    • emitJSDoc

      protected boolean emitJSDoc
    • apiDocPath

      protected String apiDocPath
    • modelDocPath

      protected String modelDocPath
    • apiTestPath

      protected String apiTestPath
    • modelTestPath

      protected String modelTestPath
    • useES6

      protected boolean useES6
    • loadTestDataFromFile

      protected boolean loadTestDataFromFile
    • testDataFile

      protected File testDataFile
    • preserveLeadingParamChar

      protected boolean preserveLeadingParamChar
  • Constructor Details

    • JavaScriptClientCodegen

      public JavaScriptClientCodegen()
  • Method Details

    • getTag

      public io.swagger.codegen.v3.CodegenType getTag()
    • getName

      public String getName()
    • getHelp

      public String getHelp()
    • processOpts

      public void processOpts()
      Specified by:
      processOpts in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      processOpts in class DefaultCodegenConfig
    • preprocessOpenAPI

      public void preprocessOpenAPI(io.swagger.v3.oas.models.OpenAPI openAPI)
      Specified by:
      preprocessOpenAPI in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      preprocessOpenAPI in class DefaultCodegenConfig
    • escapeReservedWord

      public String escapeReservedWord(String name)
      Description copied from class: DefaultCodegenConfig
      Return the escaped name of the reserved word
      Specified by:
      escapeReservedWord in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeReservedWord in class DefaultCodegenConfig
      Parameters:
      name - the name to be escaped
      Returns:
      the escaped reserved word throws Runtime exception as reserved word is not allowed (default behavior)
    • apiTestFileFolder

      public String apiTestFileFolder()
      Specified by:
      apiTestFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiTestFileFolder in class DefaultCodegenConfig
    • modelTestFileFolder

      public String modelTestFileFolder()
      Specified by:
      modelTestFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      modelTestFileFolder in class DefaultCodegenConfig
    • apiFileFolder

      public String apiFileFolder()
      Specified by:
      apiFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiFileFolder in class DefaultCodegenConfig
    • modelFileFolder

      public String modelFileFolder()
      Specified by:
      modelFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      modelFileFolder in class DefaultCodegenConfig
    • getInvokerPackage

      public String getInvokerPackage()
    • setInvokerPackage

      public void setInvokerPackage(String invokerPackage)
    • setSourceFolder

      public void setSourceFolder(String sourceFolder)
    • setProjectName

      public void setProjectName(String projectName)
    • setLocalVariablePrefix

      public void setLocalVariablePrefix(String localVariablePrefix)
    • setModuleName

      public void setModuleName(String moduleName)
    • setProjectDescription

      public void setProjectDescription(String projectDescription)
    • setProjectVersion

      public void setProjectVersion(String projectVersion)
    • setLicenseName

      public void setLicenseName(String licenseName)
    • setUsePromises

      public void setUsePromises(boolean usePromises)
    • setUseES6

      public void setUseES6(boolean useES6)
    • setUseInheritance

      public void setUseInheritance(boolean useInheritance)
    • setEmitModelMethods

      public void setEmitModelMethods(boolean emitModelMethods)
    • setEmitJSDoc

      public void setEmitJSDoc(boolean emitJSDoc)
    • apiDocFileFolder

      public String apiDocFileFolder()
      Specified by:
      apiDocFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      apiDocFileFolder in class DefaultCodegenConfig
    • modelDocFileFolder

      public String modelDocFileFolder()
      Specified by:
      modelDocFileFolder in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      modelDocFileFolder in class DefaultCodegenConfig
    • toApiDocFilename

      public String toApiDocFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the file name of the Api Documentation
      Specified by:
      toApiDocFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiDocFilename in class DefaultCodegenConfig
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toModelDocFilename

      public String toModelDocFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the capitalized file name of the model documentation
      Specified by:
      toModelDocFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelDocFilename in class DefaultCodegenConfig
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • toApiTestFilename

      public String toApiTestFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the file name of the Api Test
      Specified by:
      toApiTestFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiTestFilename in class DefaultCodegenConfig
      Parameters:
      name - the file name of the Api
      Returns:
      the file name of the Api
    • toModelTestFilename

      public String toModelTestFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the capitalized file name of the model test
      Specified by:
      toModelTestFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelTestFilename in class DefaultCodegenConfig
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • getModelPropertyNaming

      public String getModelPropertyNaming()
    • toVarName

      public String toVarName(String name)
      Description copied from class: DefaultCodegenConfig
      Return the variable name by removing invalid characters and proper escaping if it's a reserved word.
      Overrides:
      toVarName in class DefaultCodegenConfig
      Parameters:
      name - the variable name
      Returns:
      the sanitized variable name
    • toParamName

      public String toParamName(String name)
      Description copied from class: DefaultCodegenConfig
      Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.
      Specified by:
      toParamName in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toParamName in class DefaultCodegenConfig
      Parameters:
      name - Codegen property object
      Returns:
      the sanitized parameter name
    • toModelName

      public String toModelName(String name)
      Description copied from class: DefaultCodegenConfig
      Output the proper model name (capitalized). In case the name belongs to the TypeSystem it won't be renamed.
      Specified by:
      toModelName in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelName in class DefaultCodegenConfig
      Parameters:
      name - the name of the model
      Returns:
      capitalized model name
    • toModelFilename

      public String toModelFilename(String name)
      Description copied from class: DefaultCodegenConfig
      Return the capitalized file name of the model
      Specified by:
      toModelFilename in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelFilename in class DefaultCodegenConfig
      Parameters:
      name - the model name
      Returns:
      the file name of the model
    • toModelImport

      public String toModelImport(String name)
      Description copied from class: DefaultCodegenConfig
      Return the fully-qualified "Model" name for import
      Specified by:
      toModelImport in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toModelImport in class DefaultCodegenConfig
      Parameters:
      name - the name of the "Model"
      Returns:
      the fully-qualified "Model" name for import
    • toApiImport

      public String toApiImport(String name)
      Description copied from class: DefaultCodegenConfig
      Return the fully-qualified "Api" name for import
      Specified by:
      toApiImport in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      toApiImport in class DefaultCodegenConfig
      Parameters:
      name - the name of the "Api"
      Returns:
      the fully-qualified "Api" name for import
    • getTypeDeclaration

      public String getTypeDeclaration(io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegenConfig
      Output the type declaration of the property
      Specified by:
      getTypeDeclaration in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      getTypeDeclaration in class DefaultCodegenConfig
      Parameters:
      schema - Schema Property object
      Returns:
      a string presentation of the property type
    • toDefaultValue

      public String toDefaultValue(io.swagger.v3.oas.models.media.Schema propertySchema)
      Description copied from class: DefaultCodegenConfig
      Return the default value of the property
      Overrides:
      toDefaultValue in class DefaultCodegenConfig
      Parameters:
      propertySchema - Schema property object
      Returns:
      string presentation of the default value of the property
    • setModelPropertyNaming

      public void setModelPropertyNaming(String naming)
    • toDefaultValueWithParam

      public String toDefaultValueWithParam(String name, io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegenConfig
      Return the property initialized from a data object Useful for initialization with a plain object in Javascript
      Overrides:
      toDefaultValueWithParam in class DefaultCodegenConfig
      Parameters:
      name - Name of the property object
      schema - openAPI schema object
      Returns:
      string presentation of the default value of the property
    • setParameterExampleValue

      public void setParameterExampleValue(io.swagger.codegen.v3.CodegenParameter p)
      Description copied from class: DefaultCodegenConfig
      Return the example value of the parameter.
      Overrides:
      setParameterExampleValue in class DefaultCodegenConfig
      Parameters:
      p - Swagger property object
    • normalizeType

      public String normalizeType(String type)
      Normalize type by wrapping primitive types with single quotes.
      Parameters:
      type - Primitive type
      Returns:
      Normalized type
    • getSchemaType

      public String getSchemaType(io.swagger.v3.oas.models.media.Schema schema)
      Description copied from class: DefaultCodegenConfig
      returns the swagger type for the property
      Overrides:
      getSchemaType in class DefaultCodegenConfig
      Parameters:
      schema - Schema property object
      Returns:
      string presentation of the type
    • toOperationId

      public String toOperationId(String operationId)
      Description copied from class: DefaultCodegenConfig
      Return the operation ID (method name)
      Overrides:
      toOperationId in class DefaultCodegenConfig
      Parameters:
      operationId - operation ID
      Returns:
      the sanitized method name
    • fromOperation

      public io.swagger.codegen.v3.CodegenOperation fromOperation(String path, String httpMethod, io.swagger.v3.oas.models.Operation operation, Map<String,io.swagger.v3.oas.models.media.Schema> schemas, io.swagger.v3.oas.models.OpenAPI openAPI)
      Description copied from class: DefaultCodegenConfig
      Convert Swagger Operation object to Codegen Operation object
      Specified by:
      fromOperation in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      fromOperation in class DefaultCodegenConfig
      Parameters:
      path - the path of the operation
      httpMethod - HTTP method
      operation - Swagger operation object
      schemas - a map of schemas
      openAPI - a OpenAPI object representing the spec
      Returns:
      Codegen Operation object
    • fromModel

      public io.swagger.codegen.v3.CodegenModel fromModel(String name, io.swagger.v3.oas.models.media.Schema schema, Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas)
      Description copied from class: DefaultCodegenConfig
      Convert Swagger Model object to Codegen Model object
      Specified by:
      fromModel in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      fromModel in class DefaultCodegenConfig
      Parameters:
      name - the name of the model
      schema - Swagger Model object
      allSchemas - a map of all Swagger models from the spec
      Returns:
      Codegen Model object
    • addAdditionPropertiesToCodeGenModel

      protected void addAdditionPropertiesToCodeGenModel(io.swagger.codegen.v3.CodegenModel codegenModel, io.swagger.v3.oas.models.media.Schema schema)
      Overrides:
      addAdditionPropertiesToCodeGenModel in class DefaultCodegenConfig
    • getDefaultTemplateDir

      public String getDefaultTemplateDir()
      Specified by:
      getDefaultTemplateDir in class DefaultCodegenConfig
    • postProcessOperations

      public Map<String,Object> postProcessOperations(Map<String,Object> objs)
      Specified by:
      postProcessOperations in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessOperations in class DefaultCodegenConfig
    • postProcessOperationsWithModels

      public Map<String,Object> postProcessOperationsWithModels(Map<String,Object> objs, List<Object> allModels)
      Specified by:
      postProcessOperationsWithModels in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessOperationsWithModels in class DefaultCodegenConfig
    • setLoadTestDataFromFile

      public void setLoadTestDataFromFile(boolean loadTestDataFromFile)
      todo: let's handle this with handlebar helpers // The api-test-param-complex and api-test-property-complex templates need to know whether a parameter is required, // but they cannot use normal inheritance to determine this, because CodegenProperty.required in the current context // shadows CodegenParameter.required in the ancestor context. Also, they can't use a vendor extension property on // the CodegenParameter, as compound tags are not resolved recursively. So the only way is to use Lambdas. private CodegenParameter cgParam; private Lambda cacheCurrentParam = new Lambda() {
    • setTestDataFile

      public void setTestDataFile(File testDataFile)
    • setPreserveLeadingParamChar

      public void setPreserveLeadingParamChar(boolean preserveLeadingParamChar)
    • postProcessModels

      public Map<String,Object> postProcessModels(Map<String,Object> objs)
      Specified by:
      postProcessModels in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      postProcessModels in class DefaultCodegenConfig
    • detectRecursiveModel

      public void detectRecursiveModel(List<io.swagger.codegen.v3.CodegenProperty> allVars, String className, Map<String,io.swagger.codegen.v3.CodegenModel> allModels)
    • addImport

      protected void addImport(io.swagger.codegen.v3.CodegenModel model, String type)
      Overrides:
      addImport in class DefaultCodegenConfig
    • needToImport

      protected boolean needToImport(String type)
      Description copied from class: DefaultCodegenConfig
      Check the type to see if it needs import the library/module/package
      Overrides:
      needToImport in class DefaultCodegenConfig
      Parameters:
      type - name of the type
      Returns:
      true if the library/module/package of the corresponding type needs to be imported
    • toEnumName

      public String toEnumName(io.swagger.codegen.v3.CodegenProperty property)
      Description copied from class: DefaultCodegenConfig
      Return the Enum name (e.g. StatusEnum given 'status')
      Overrides:
      toEnumName in class DefaultCodegenConfig
      Parameters:
      property - Codegen property
      Returns:
      the Enum name
    • toEnumVarName

      public String toEnumVarName(String value, String datatype)
      Description copied from class: DefaultCodegenConfig
      Return the sanitized variable name for enum
      Overrides:
      toEnumVarName in class DefaultCodegenConfig
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized variable name for enum
    • toEnumValue

      public String toEnumValue(String value, String datatype)
      Description copied from class: DefaultCodegenConfig
      Return the enum value in the language specified format e.g. status becomes "status"
      Overrides:
      toEnumValue in class DefaultCodegenConfig
      Parameters:
      value - enum variable name
      datatype - data type
      Returns:
      the sanitized value for enum
    • escapeQuotationMark

      public String escapeQuotationMark(String input)
      Description copied from class: DefaultCodegenConfig
      Escape single and/or double quote to avoid code injection
      Specified by:
      escapeQuotationMark in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeQuotationMark in class DefaultCodegenConfig
      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: DefaultCodegenConfig
      override with any special text escaping logic to handle unsafe characters so as to avoid code injection
      Specified by:
      escapeUnsafeCharacters in interface io.swagger.codegen.v3.CodegenConfig
      Overrides:
      escapeUnsafeCharacters in class DefaultCodegenConfig
      Parameters:
      input - String to be cleaned up
      Returns:
      string with unsafe characters removed or escaped