public JavaClientCodegen() {
    super();
    outputFolder = "generated-code" + File.separator + "java";
    modelTemplateFiles.put("model.mustache", ".java");
    apiTemplateFiles.put("api.mustache", ".java");
    embeddedTemplateDir = templateDir = "Java";
    apiPackage = "io.swagger.client.api";
    modelPackage = "io.swagger.client.model";

    setReservedWordsLowerCase(
        Arrays.asList(
            // used as internal variables, can collide with parameter names
            "localVarPath",
            "localVarQueryParams",
            "localVarHeaderParams",
            "localVarFormParams",
            "localVarPostBody",
            "localVarAccepts",
            "localVarAccept",
            "localVarContentTypes",
            "localVarContentType",
            "localVarAuthNames",
            "localReturnType",
            "ApiClient",
            "ApiException",
            "ApiResponse",
            "Configuration",
            "StringUtil",

            // language reserved words
            "abstract",
            "continue",
            "for",
            "new",
            "switch",
            "assert",
            "default",
            "if",
            "package",
            "synchronized",
            "boolean",
            "do",
            "goto",
            "private",
            "this",
            "break",
            "double",
            "implements",
            "protected",
            "throw",
            "byte",
            "else",
            "import",
            "public",
            "throws",
            "case",
            "enum",
            "instanceof",
            "return",
            "transient",
            "catch",
            "extends",
            "int",
            "short",
            "try",
            "char",
            "final",
            "interface",
            "static",
            "void",
            "class",
            "finally",
            "long",
            "strictfp",
            "volatile",
            "const",
            "float",
            "native",
            "super",
            "while"));

    languageSpecificPrimitives =
        new HashSet<String>(
            Arrays.asList(
                "String", "boolean", "Boolean", "Double", "Integer", "Long", "Float", "Object",
                "byte[]"));
    instantiationTypes.put("array", "ArrayList");
    instantiationTypes.put("map", "HashMap");
    typeMapping.put("date", "Date");
    typeMapping.put("file", "File");
    typeMapping.put("UUID", "String");

    cliOptions.add(
        new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
    cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
    cliOptions.add(
        new CliOption(
            CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING,
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util"));
    cliOptions.add(
        CliOption.newBoolean(
            USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
    cliOptions.add(
        new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));

    supportedLibraries.put(
        DEFAULT_LIBRARY, "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
    supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.1.1");
    supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
    supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
    supportedLibraries.put(
        RETROFIT_1, "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
    supportedLibraries.put(
        RETROFIT_2,
        "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.1). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.2)");

    CliOption library =
        new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
    library.setDefault(DEFAULT_LIBRARY);
    library.setEnum(supportedLibraries);
    library.setDefault(DEFAULT_LIBRARY);
    cliOptions.add(library);

    CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
    Map<String, String> dateOptions = new HashMap<String, String>();
    dateOptions.put("java8", "Java 8 native");
    dateOptions.put("joda", "Joda");
    dateLibrary.setEnum(dateOptions);

    cliOptions.add(dateLibrary);
  }
  public AbstractJavaCodegen() {
    super();
    modelTemplateFiles.put("model.mustache", ".java");
    apiTemplateFiles.put("api.mustache", ".java");
    apiTestTemplateFiles.put("api_test.mustache", ".java");
    modelDocTemplateFiles.put("model_doc.mustache", ".md");
    apiDocTemplateFiles.put("api_doc.mustache", ".md");

    setReservedWordsLowerCase(
        Arrays.asList(
            // used as internal variables, can collide with parameter names
            "localVarPath",
            "localVarQueryParams",
            "localVarHeaderParams",
            "localVarFormParams",
            "localVarPostBody",
            "localVarAccepts",
            "localVarAccept",
            "localVarContentTypes",
            "localVarContentType",
            "localVarAuthNames",
            "localReturnType",
            "ApiClient",
            "ApiException",
            "ApiResponse",
            "Configuration",
            "StringUtil",

            // language reserved words
            "abstract",
            "continue",
            "for",
            "new",
            "switch",
            "assert",
            "default",
            "if",
            "package",
            "synchronized",
            "boolean",
            "do",
            "goto",
            "private",
            "this",
            "break",
            "double",
            "implements",
            "protected",
            "throw",
            "byte",
            "else",
            "import",
            "public",
            "throws",
            "case",
            "enum",
            "instanceof",
            "return",
            "transient",
            "catch",
            "extends",
            "int",
            "short",
            "try",
            "char",
            "final",
            "interface",
            "static",
            "void",
            "class",
            "finally",
            "long",
            "strictfp",
            "volatile",
            "const",
            "float",
            "native",
            "super",
            "while"));

    languageSpecificPrimitives =
        new HashSet<String>(
            Arrays.asList(
                "String", "boolean", "Boolean", "Double", "Integer", "Long", "Float", "Object",
                "byte[]"));
    instantiationTypes.put("array", "ArrayList");
    instantiationTypes.put("map", "HashMap");
    typeMapping.put("date", "Date");
    typeMapping.put("file", "File");
    typeMapping.put("UUID", "String");

    cliOptions.add(
        new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
    cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
    cliOptions.add(
        new CliOption(
            CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING,
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            FULL_JAVA_UTIL,
            "whether to use fully qualified name for classes under java.util. This option only works for Java API client"));
    cliOptions.add(
        new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));

    CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
    Map<String, String> dateOptions = new HashMap<String, String>();
    dateOptions.put("java8", "Java 8 native");
    dateOptions.put("java8-localdatetime", "Java 8 using LocalDateTime (for legacy app only)");
    dateOptions.put("joda", "Joda");
    dateOptions.put("legacy", "Legacy java.util.Date");
    dateLibrary.setEnum(dateOptions);

    cliOptions.add(dateLibrary);
  }
Пример #3
0
  public JavaClientCodegen() {
    super();
    outputFolder = "generated-code" + File.separator + "java";
    modelTemplateFiles.put("model.mustache", ".java");
    apiTemplateFiles.put("api.mustache", ".java");
    embeddedTemplateDir = templateDir = "Java";
    apiPackage = "io.swagger.client.api";
    modelPackage = "io.swagger.client.model";

    reservedWords =
        new HashSet<String>(
            Arrays.asList(
                // used as internal variables, can collide with parameter names
                "path",
                "queryParams",
                "headerParams",
                "formParams",
                "postBody",
                "accepts",
                "accept",
                "contentTypes",
                "contentType",
                "authNames",

                // language reserved words
                "abstract",
                "continue",
                "for",
                "new",
                "switch",
                "assert",
                "default",
                "if",
                "package",
                "synchronized",
                "boolean",
                "do",
                "goto",
                "private",
                "this",
                "break",
                "double",
                "implements",
                "protected",
                "throw",
                "byte",
                "else",
                "import",
                "public",
                "throws",
                "case",
                "enum",
                "instanceof",
                "return",
                "transient",
                "catch",
                "extends",
                "int",
                "short",
                "try",
                "char",
                "final",
                "interface",
                "static",
                "void",
                "class",
                "finally",
                "long",
                "strictfp",
                "volatile",
                "const",
                "float",
                "native",
                "super",
                "while"));

    languageSpecificPrimitives =
        new HashSet<String>(
            Arrays.asList(
                "String", "boolean", "Boolean", "Double", "Integer", "Long", "Float", "Object",
                "byte[]"));
    instantiationTypes.put("array", "ArrayList");
    instantiationTypes.put("map", "HashMap");

    cliOptions.add(
        new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
    cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
    cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
    cliOptions.add(
        new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
    cliOptions.add(
        new CliOption(
            CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING,
            CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
    cliOptions.add(
        CliOption.newBoolean(
            FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util"));

    supportedLibraries.put(
        DEFAULT_LIBRARY, "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
    supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.1.1");
    supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
    supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
    supportedLibraries.put(
        "retrofit", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
    supportedLibraries.put(
        "retrofit2", "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)");
    CliOption library =
        new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
    library.setDefault(DEFAULT_LIBRARY);
    library.setEnum(supportedLibraries);
    library.setDefault(DEFAULT_LIBRARY);
    cliOptions.add(library);
  }