Java Code Examples for org.openapitools.codegen.CliOption#setEnum()

The following examples show how to use org.openapitools.codegen.CliOption#setEnum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceCombCodegen.java    From servicecomb-toolkit with Apache License 2.0 6 votes vote down vote up
public ServiceCombCodegen() {
  super();

  outputFolder = "generated-code/ServiceComb";

  embeddedTemplateDir = templateDir = "ServiceComb";
  modelTemplateFiles.put(modelTemplateFolder + "/model.mustache", ".java");
  modelTemplateFiles.remove("model.mustache");

  supportedLibraries.put(DEFAULT_LIBRARY, "ServiceComb Server application using the SpringMVC programming model.");
  supportedLibraries.put(POJO_LIBRARY, "ServiceComb Server application using the POJO programming model.");
  supportedLibraries.put(JAX_RS_LIBRARY, "ServiceComb Server application using the JAX-RS programming model.");
  supportedLibraries
      .put(SPRING_BOOT_LIBRARY, "ServiceComb Server application using the SpringBoot programming model.");

  setLibrary(DEFAULT_LIBRARY);

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

  addDirectoryStrategy(new ProviderDirectoryStrategy(), ServiceType.PROVIDER.getValue());
  addDirectoryStrategy(new ConsumerDirectoryStrategy(), ServiceType.CONSUMER.getValue());
  addDirectoryStrategy(new DefaultDirectoryStrategy(), ServiceType.ALL.getValue());
}
 
Example 2
Source File: DartDioClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public DartDioClientCodegen() {
    super();
    browserClient = false;
    outputFolder = "generated-code/dart-dio";
    embeddedTemplateDir = "dart-dio";
    this.setTemplateDir(embeddedTemplateDir);

    //no tests at this time
    modelTestTemplateFiles.clear();
    apiTestTemplateFiles.clear();

    cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload"));
    CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use").defaultValue(this.getDateLibrary());
    Map<String, String> dateOptions = new HashMap<>();
    dateOptions.put("core", "Dart core library (DateTime)");
    dateOptions.put("timemachine", "Time Machine is date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.");
    dateLibrary.setEnum(dateOptions);
    cliOptions.add(dateLibrary);

    typeMapping.put("file", "Uint8List");
    typeMapping.put("binary", "Uint8List");
    typeMapping.put("AnyType", "Object");

    importMapping.put("BuiltList", "package:built_collection/built_collection.dart");
    importMapping.put("BuiltMap", "package:built_collection/built_collection.dart");
    importMapping.put("JsonObject", "package:built_value/json_object.dart");
    importMapping.put("Uint8List", "dart:typed_data");
}
 
Example 3
Source File: KotlinServerCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance of `KotlinServerCodegen`.
 */
public KotlinServerCodegen() {
    super();

    modifyFeatureSet(features -> features
            .includeDocumentationFeatures(DocumentationFeature.Readme)
            .wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML))
            .securityFeatures(EnumSet.of(
                    SecurityFeature.BasicAuth,
                    SecurityFeature.ApiKey,
                    SecurityFeature.OAuth2_Implicit
            ))
            .excludeGlobalFeatures(
                    GlobalFeature.XMLStructureDefinitions,
                    GlobalFeature.Callbacks,
                    GlobalFeature.LinkObjects,
                    GlobalFeature.ParameterStyling
            )
            .excludeSchemaSupportFeatures(
                    SchemaSupportFeature.Polymorphism
            )
            .excludeParameterFeatures(
                    ParameterFeature.Cookie
            )
    );

    artifactId = "kotlin-server";
    packageName = "org.openapitools.server";

    // cliOptions default redefinition need to be updated
    updateOption(CodegenConstants.ARTIFACT_ID, this.artifactId);
    updateOption(CodegenConstants.PACKAGE_NAME, this.packageName);

    outputFolder = "generated-code" + File.separator + "kotlin-server";
    modelTemplateFiles.put("model.mustache", ".kt");
    apiTemplateFiles.put("api.mustache", ".kt");
    embeddedTemplateDir = templateDir = "kotlin-server";
    apiPackage = packageName + ".apis";
    modelPackage = packageName + ".models";

    supportedLibraries.put(Constants.KTOR, "ktor framework");

    // TODO: Configurable server engine. Defaults to netty in build.gradle.
    CliOption library = new CliOption(CodegenConstants.LIBRARY, CodegenConstants.LIBRARY_DESC);
    library.setDefault(DEFAULT_LIBRARY);
    library.setEnum(supportedLibraries);

    cliOptions.add(library);

    addSwitch(Constants.AUTOMATIC_HEAD_REQUESTS, Constants.AUTOMATIC_HEAD_REQUESTS_DESC, getAutoHeadFeatureEnabled());
    addSwitch(Constants.CONDITIONAL_HEADERS, Constants.CONDITIONAL_HEADERS_DESC, getConditionalHeadersFeatureEnabled());
    addSwitch(Constants.HSTS, Constants.HSTS_DESC, getHstsFeatureEnabled());
    addSwitch(Constants.CORS, Constants.CORS_DESC, getCorsFeatureEnabled());
    addSwitch(Constants.COMPRESSION, Constants.COMPRESSION_DESC, getCompressionFeatureEnabled());
}
 
Example 4
Source File: KotlinClientCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance of `KotlinClientCodegen`.
 */
public KotlinClientCodegen() {
    super();

    /*
     * OAuth flows supported _only_ by client explicitly setting bearer token. The "flows" are not supported.
     */
    modifyFeatureSet(features -> features
            .includeDocumentationFeatures(DocumentationFeature.Readme)
            .excludeWireFormatFeatures(WireFormatFeature.XML, WireFormatFeature.PROTOBUF)
            .excludeSecurityFeatures(
                    SecurityFeature.OpenIDConnect,
                    SecurityFeature.OAuth2_Password,
                    SecurityFeature.OAuth2_AuthorizationCode,
                    SecurityFeature.OAuth2_ClientCredentials,
                    SecurityFeature.OAuth2_Implicit
            )
            .excludeGlobalFeatures(
                    GlobalFeature.XMLStructureDefinitions,
                    GlobalFeature.Callbacks,
                    GlobalFeature.LinkObjects,
                    GlobalFeature.ParameterStyling
            )
            .excludeSchemaSupportFeatures(
                    SchemaSupportFeature.Polymorphism
            )
            .excludeParameterFeatures(
                    ParameterFeature.Cookie
            )
            .includeClientModificationFeatures(ClientModificationFeature.BasePath)
    );

    artifactId = "kotlin-client";
    packageName = "org.openapitools.client";

    // cliOptions default redefinition need to be updated
    updateOption(CodegenConstants.ARTIFACT_ID, this.artifactId);
    updateOption(CodegenConstants.PACKAGE_NAME, this.packageName);

    outputFolder = "generated-code" + File.separator + "kotlin-client";
    modelTemplateFiles.put("model.mustache", ".kt");
    apiTemplateFiles.put("api.mustache", ".kt");
    modelDocTemplateFiles.put("model_doc.mustache", ".md");
    apiDocTemplateFiles.put("api_doc.mustache", ".md");
    embeddedTemplateDir = templateDir = "kotlin-client";
    apiPackage = packageName + ".apis";
    modelPackage = packageName + ".models";

    CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
    Map<String, String> dateOptions = new HashMap<>();
    dateOptions.put(DateLibrary.THREETENBP.value, "Threetenbp - Backport of JSR310 (jvm only, preferred for jdk < 1.8)");
    dateOptions.put(DateLibrary.THREETENBP_LOCALDATETIME.value, "Threetenbp - Backport of JSR310 (jvm only, for legacy app only)");
    dateOptions.put(DateLibrary.STRING.value, "String");
    dateOptions.put(DateLibrary.JAVA8.value, "Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)");
    dateOptions.put(DateLibrary.JAVA8_LOCALDATETIME.value, "Java 8 native JSR310 (jvm only, for legacy app only)");
    dateLibrary.setEnum(dateOptions);
    dateLibrary.setDefault(this.dateLibrary);
    cliOptions.add(dateLibrary);

    CliOption collectionType = new CliOption(COLLECTION_TYPE, "Option. Collection type to use");
    Map<String, String> collectionOptions = new HashMap<>();
    collectionOptions.put(CollectionType.ARRAY.value, "kotlin.Array");
    collectionOptions.put(CollectionType.LIST.value, "kotlin.collections.List");
    collectionType.setEnum(collectionOptions);
    collectionType.setDefault(this.collectionType);
    cliOptions.add(collectionType);

    supportedLibraries.put(JVM_OKHTTP4, "[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.");
    supportedLibraries.put(JVM_OKHTTP3, "Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.");
    supportedLibraries.put(JVM_RETROFIT2, "Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.");
    supportedLibraries.put(MULTIPLATFORM, "Platform: Kotlin multiplatform. HTTP client: Ktor 1.2.4. JSON processing: Kotlinx Serialization: 0.12.0.");

    CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "Library template (sub-template) to use");
    libraryOption.setEnum(supportedLibraries);
    libraryOption.setDefault(JVM_OKHTTP4);
    cliOptions.add(libraryOption);
    setLibrary(JVM_OKHTTP4);

    CliOption requestDateConverter = new CliOption(REQUEST_DATE_CONVERTER, "JVM-Option. Defines in how to handle date-time objects that are used for a request (as query or parameter)");
    Map<String, String> requestDateConverterOptions = new HashMap<>();
    requestDateConverterOptions.put(RequestDateConverter.TO_JSON.value, "[DEFAULT] Date formater option using a json converter.");
    requestDateConverterOptions.put(RequestDateConverter.TO_STRING.value, "Use the 'toString'-method of the date-time object to retrieve the related string representation.");
    requestDateConverter.setEnum(requestDateConverterOptions);
    requestDateConverter.setDefault(this.requestDateConverter);
    cliOptions.add(requestDateConverter);

    cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
    cliOptions.add(CliOption.newBoolean(USE_RX_JAVA2, "Whether to use the RxJava2 adapter with the retrofit2 library."));
    cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines adapter with the retrofit2 library."));
}