@Test
 public void getOptionsTest() throws ApiException {
   final Map<String, CliOption> options =
       Generator.getOptions(new JavaOptionsProvider().getLanguage());
   assertNotNull(options);
   final CliOption opt = options.get(CodegenConstants.LIBRARY);
   assertNotNull(opt);
   assertEquals(opt.getDefault(), JavaClientCodegen.DEFAULT_LIBRARY);
 }
  public RubyClientCodegen() {
    super();
    modelPackage = "models";
    apiPackage = "api";
    outputFolder = "generated-code" + File.separator + "ruby";
    modelTemplateFiles.put("model.mustache", ".rb");
    apiTemplateFiles.put("api.mustache", ".rb");
    embeddedTemplateDir = templateDir = "ruby";

    typeMapping.clear();
    languageSpecificPrimitives.clear();

    reservedWords =
        new HashSet<String>(
            Arrays.asList(
                // local variable names used in API methods (endpoints)
                "path",
                "query_params",
                "header_params",
                "_header_accept",
                "_header_accept_result",
                "_header_content_type",
                "form_params",
                "post_body",
                "auth_names",
                // ruby reserved keywords
                "__FILE__",
                "and",
                "def",
                "end",
                "in",
                "or",
                "self",
                "unless",
                "__LINE__",
                "begin",
                "defined?",
                "ensure",
                "module",
                "redo",
                "super",
                "until",
                "BEGIN",
                "break",
                "do",
                "false",
                "next",
                "rescue",
                "then",
                "when",
                "END",
                "case",
                "else",
                "for",
                "nil",
                "retry",
                "true",
                "while",
                "alias",
                "class",
                "elsif",
                "if",
                "not",
                "return",
                "undef",
                "yield"));

    languageSpecificPrimitives.add("int");
    languageSpecificPrimitives.add("array");
    languageSpecificPrimitives.add("map");
    languageSpecificPrimitives.add("string");
    languageSpecificPrimitives.add("DateTime");

    typeMapping.put("string", "String");
    typeMapping.put("char", "String");
    typeMapping.put("int", "Integer");
    typeMapping.put("integer", "Integer");
    typeMapping.put("long", "Integer");
    typeMapping.put("short", "Integer");
    typeMapping.put("float", "Float");
    typeMapping.put("double", "Float");
    typeMapping.put("number", "Float");
    typeMapping.put("date", "Date");
    typeMapping.put("DateTime", "DateTime");
    typeMapping.put("boolean", "BOOLEAN");
    typeMapping.put("array", "Array");
    typeMapping.put("List", "Array");
    typeMapping.put("map", "Hash");
    typeMapping.put("object", "Object");
    typeMapping.put("file", "File");

    // remove modelPackage and apiPackage added by default
    Iterator<CliOption> itr = cliOptions.iterator();
    while (itr.hasNext()) {
      CliOption opt = itr.next();
      if (CodegenConstants.MODEL_PACKAGE.equals(opt.getOpt())
          || CodegenConstants.API_PACKAGE.equals(opt.getOpt())) {
        itr.remove();
      }
    }
    cliOptions.add(
        new CliOption(GEM_NAME, "gem name (convention: underscore_case).")
            .defaultValue("swagger_client"));
    cliOptions.add(
        new CliOption(
                MODULE_NAME,
                "top module name (convention: CamelCase, usually corresponding" + " to gem name).")
            .defaultValue("SwaggerClient"));
    cliOptions.add(new CliOption(GEM_VERSION, "gem version.").defaultValue("1.0.0"));

    cliOptions.add(new CliOption(GEM_LICENSE, "gem license. ").defaultValue("Apache-2.0"));

    cliOptions.add(new CliOption(GEM_HOMEPAGE, "gem homepage. ").defaultValue("http://swagger.io"));

    cliOptions.add(
        new CliOption(GEM_SUMMARY, "gem summary. ")
            .defaultValue("A ruby wrapper for the swagger APIs"));

    cliOptions.add(
        new CliOption(GEM_DESCRIPTION, "gem description. ")
            .defaultValue("This gem maps to a swagger API"));

    cliOptions.add(new CliOption(GEM_AUTHOR, "gem author (only one is supported)."));

    cliOptions.add(new CliOption(GEM_AUTHOR_EMAIL, "gem author email (only one is supported)."));
  }
  public PythonClientCodegen() {
    super();

    modelPackage = "models";
    apiPackage = "api";
    outputFolder = "generated-code" + File.separatorChar + "python";

    modelTemplateFiles.put("model.mustache", ".py");
    apiTemplateFiles.put("api.mustache", ".py");

    modelTestTemplateFiles.put("model_test.mustache", ".py");
    apiTestTemplateFiles.put("api_test.mustache", ".py");

    embeddedTemplateDir = templateDir = "python";

    modelDocTemplateFiles.put("model_doc.mustache", ".md");
    apiDocTemplateFiles.put("api_doc.mustache", ".md");

    testFolder = "test";

    languageSpecificPrimitives.clear();
    languageSpecificPrimitives.add("int");
    languageSpecificPrimitives.add("float");
    languageSpecificPrimitives.add("list");
    languageSpecificPrimitives.add("bool");
    languageSpecificPrimitives.add("str");
    languageSpecificPrimitives.add("datetime");
    languageSpecificPrimitives.add("date");
    languageSpecificPrimitives.add("object");

    typeMapping.clear();
    typeMapping.put("integer", "int");
    typeMapping.put("float", "float");
    typeMapping.put("number", "float");
    typeMapping.put("long", "int");
    typeMapping.put("double", "float");
    typeMapping.put("array", "list");
    typeMapping.put("map", "dict");
    typeMapping.put("boolean", "bool");
    typeMapping.put("string", "str");
    typeMapping.put("date", "date");
    typeMapping.put("DateTime", "datetime");
    typeMapping.put("object", "object");
    typeMapping.put("file", "file");
    // TODO binary should be mapped to byte array
    // mapped to String as a workaround
    typeMapping.put("binary", "str");
    typeMapping.put("ByteArray", "str");
    // map uuid to string for the time being
    typeMapping.put("UUID", "str");

    // from https://docs.python.org/release/2.5.4/ref/keywords.html
    setReservedWordsLowerCase(
        Arrays.asList(
            // local variable name used in API methods (endpoints)
            "all_params",
            "resource_path",
            "path_params",
            "query_params",
            "header_params",
            "form_params",
            "local_var_files",
            "body_params",
            "auth_settings",
            // @property
            "property",
            // python reserved words
            "and",
            "del",
            "from",
            "not",
            "while",
            "as",
            "elif",
            "global",
            "or",
            "with",
            "assert",
            "else",
            "if",
            "pass",
            "yield",
            "break",
            "except",
            "import",
            "print",
            "class",
            "exec",
            "in",
            "raise",
            "continue",
            "finally",
            "is",
            "return",
            "def",
            "for",
            "lambda",
            "try",
            "self"));

    regexModifiers = new HashMap<Character, String>();
    regexModifiers.put('i', "IGNORECASE");
    regexModifiers.put('l', "LOCALE");
    regexModifiers.put('m', "MULTILINE");
    regexModifiers.put('s', "DOTALL");
    regexModifiers.put('u', "UNICODE");
    regexModifiers.put('x', "VERBOSE");

    cliOptions.clear();
    cliOptions.add(
        new CliOption(
                CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
            .defaultValue("swagger_client"));
    cliOptions.add(
        new CliOption(CodegenConstants.PACKAGE_VERSION, "python package version.")
            .defaultValue("1.0.0"));
    cliOptions.add(
        CliOption.newBoolean(
                CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
                CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC)
            .defaultValue(Boolean.TRUE.toString()));
  }
  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);
  }
  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);
  }
Exemplo n.º 6
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);
  }