コード例 #1
0
  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);
  }
コード例 #2
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";

    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);
  }
コード例 #3
0
  public HaskellServantCodegen() {
    super();

    // set the output folder here
    outputFolder = "generated-code/HaskellServantCodegen";

    /**
     * Models. You can write model files using the modelTemplateFiles map. if you want to create one
     * template for file, you can do so here. for multiple files for model, just put another entry
     * in the `modelTemplateFiles` with a different extension
     */
    modelTemplateFiles.put(
        "model.mustache", // the template to use
        ".hs"); // the extension for each file to write

    /**
     * Api classes. You can write classes for each Api file with the apiTemplateFiles map. as with
     * models, add multiple entries with different extensions for multiple files per class
     */
    apiTemplateFiles.put(
        "api.mustache", // the template to use
        ".hs"); // the extension for each file to write

    /**
     * Template Location. This is the location which templates will be read from. The generator will
     * use the resource stream to attempt to read the templates.
     */
    templateDir = "HaskellServantCodegen";

    /** Api Package. Optional, if needed, this can be used in templates */
    apiPackage = "Api";

    /** Model Package. Optional, if needed, this can be used in templates */
    modelPackage = "Model";

    /** Reserved words. Override this with reserved words specific to your language */
    // from https://wiki.haskell.org/Keywords
    reservedWords =
        new HashSet<String>(
            Arrays.asList(
                "as",
                "case",
                "of",
                "class",
                "data", // "data family", "data instance",
                "default",
                "deriving", // "deriving instance",
                "do",
                "forall",
                "foreign",
                "hiding",
                "id",
                "if",
                "then",
                "else",
                "import",
                "infix",
                "infixl",
                "infixr",
                "instance",
                "let",
                "in",
                "mdo",
                "module",
                "newtype",
                "proc",
                "qualified",
                "rec",
                "type", // "type family", "type instance",
                "where"));

    /**
     * Additional Properties. These values can be passed to the templates and are available in
     * models, apis, and supporting files
     */
    additionalProperties.put("apiVersion", apiVersion);

    /**
     * Supporting Files. You can write single files for the generator with the entire object tree
     * available. If the input file has a suffix of `.mustache it will be processed by the template
     * engine. Otherwise, it will be copied
     */
    supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
    supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
    supportingFiles.add(
        new SupportingFile(
            "haskell-servant-codegen.mustache", "", "haskell-servant-codegen.cabal"));
    supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
    supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
    supportingFiles.add(new SupportingFile("Apis.mustache", "lib", "Apis.hs"));
    supportingFiles.add(new SupportingFile("Utils.mustache", "lib", "Utils.hs"));
    supportingFiles.add(new SupportingFile("Client.mustache", "client", "Main.hs"));
    supportingFiles.add(new SupportingFile("Server.mustache", "server", "Main.hs"));

    /**
     * Language Specific Primitives. These types will not trigger imports by the client generator
     */
    languageSpecificPrimitives =
        new HashSet<String>(
            Arrays.asList(
                "Bool", "String", "Int", "Integer", "Float", "Char", "Double", "List", "FilePath"));

    typeMapping.clear();
    // typeMapping.put("enum", "NSString");
    typeMapping.put("array", "List");
    typeMapping.put("set", "Set");
    typeMapping.put("boolean", "Bool");
    typeMapping.put("string", "String");
    typeMapping.put("int", "Int");
    typeMapping.put("long", "Integer");
    typeMapping.put("float", "Float");
    // typeMapping.put("byte", "Byte");
    typeMapping.put("short", "Int");
    typeMapping.put("char", "Char");
    typeMapping.put("double", "Double");
    typeMapping.put("DateTime", "Integer");
    // typeMapping.put("object", "Map");
    typeMapping.put("file", "FilePath");

    importMapping.clear();
    importMapping.put("Map", "qualified Data.Map as Map");
  }
コード例 #4
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);
  }