org.openapitools.codegen.CliOption Java Examples

The following examples show how to use org.openapitools.codegen.CliOption. 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: TypeScriptAxiosClientCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public TypeScriptAxiosClientCodegen() {
    super();

    modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));

    // clear import mapping (from default generator) as TS does not use it
    // at the moment
    importMapping.clear();

    outputFolder = "generated-code/typescript-axios";
    embeddedTemplateDir = templateDir = "typescript-axios";

    this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url of your private npmRepo in the package.json"));
    this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
    this.cliOptions.add(new CliOption(SEPARATE_MODELS_AND_API, "Put the model and api in separate folders and in separate classes", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
    this.cliOptions.add(new CliOption(WITHOUT_PREFIX_ENUMS, "Don't prefix enum names with class names", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
    this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
}
 
Example #2
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 #3
Source File: TypeScriptJqueryClientCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public TypeScriptJqueryClientCodegen() {
    super();

    modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));

    modelTemplateFiles.put("model.mustache", ".ts");
    apiTemplateFiles.put("api.mustache", ".ts");
    typeMapping.put("Date", "Date");
    apiPackage = "api";
    modelPackage = "model";

    outputFolder = "generated-code/typescript-jquery";
    embeddedTemplateDir = templateDir = "typescript-jquery";

    this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
    this.cliOptions.add(new CliOption(JQUERY_ALREADY_IMPORTED,
            "When using this in legacy app using mix of typescript and javascript, this will only declare jquery and not import it",
            SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
}
 
Example #4
Source File: JavaCXFExtServerCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public JavaCXFExtServerCodegen() {
    super();

    embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf-ext";
    cliOptions.add(CliOption.newBoolean(SUPPORT_MULTIPLE_SPRING_SERVICES,
            "Support generation of Spring services from multiple specifications"));
    cliOptions.add(CliOption.newBoolean(GENERATE_OPERATION_BODY, "Generate fully functional operation bodies"));
    cliOptions.add(CliOption.newBoolean(LOAD_TEST_DATA_FROM_FILE, "Load test data from a generated JSON file"));
    cliOptions.add(CliOption.newString(TEST_DATA_FILE, "JSON file to contain generated test data"));
    cliOptions.add(CliOption.newString(TEST_DATA_CONTROL_FILE, "JSON file to control test data generation"));
}
 
Example #5
Source File: AgServerCodegen.java    From agrest with Apache License 2.0 5 votes vote down vote up
public AgServerCodegen() {
    super();
    artifactId = "swagger-jaxrs-agrest-server";

    supportsInheritance = true;
    sourceFolder = "src/main/java";
    implFolder = "src/main/java";
    testFolder = "src/test/java";

    outputFolder = "generated-code/JavaJaxRS-Agrest";

    apiTestTemplateFiles.clear();

    modelDocTemplateFiles.remove("model_doc.mustache");
    apiDocTemplateFiles.remove("api_doc.mustache");

    typeMapping.put("date", "LocalDateTime");
    typeMapping.put("DateTime", "LocalDateTime");
    typeMapping.put("number", "Double");

    typeMapping.put("cayenneExp", "CayenneExp");
    typeMapping.put("dir", "Dir");
    typeMapping.put("exclude", "Exclude");
    typeMapping.put("include", "Include");
    typeMapping.put("sort", "Sort");
    typeMapping.put("mapBy", "MapBy");
    typeMapping.put("start", "Start");
    typeMapping.put("limit", "Limit");

    importMapping.put("LocalDate", "java.time.LocalDateTime");
    importMapping.put("LocalDateTime", "java.time.LocalDateTime");

    embeddedTemplateDir = templateDir = AbstractJavaJAXRSServerCodegen.JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "agrest";

    cliOptions.add(CliOption.newBoolean(GENERATE_FOR_TESTING, "Generates models and API's for testing purpose"));
}
 
Example #6
Source File: ConfigHelp.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
private void generateYamlSample(StringBuilder sb, CodegenConfig config) {

        for (CliOption langCliOption : config.cliOptions()) {

            sb.append("# Description: ").append(langCliOption.getDescription()).append(newline);

            Map<String, String> enums = langCliOption.getEnum();
            if (enums != null) {
                sb.append("# Available Values:").append(newline);

                for (Map.Entry<String, String> entry : enums.entrySet()) {
                    sb.append("#    ").append(entry.getKey()).append(newline);
                    sb.append("#         ").append(entry.getValue()).append(newline);
                }
            }

            String defaultValue = langCliOption.getDefault();

            if (defaultValue != null) {
                sb.append(langCliOption.getOpt()).append(": ").append(defaultValue).append(newline);
            } else {
                sb.append("# ").append(langCliOption.getOpt()).append(": ").append(newline);
            }

            sb.append(newline);
        }
    }
 
Example #7
Source File: PhpSlim4ServerCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public PhpSlim4ServerCodegen() {
    super();

    generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
            .stability(Stability.STABLE)
            .build();

    interfacesPackage = invokerPackage + "\\" + interfacesDirName;
    outputFolder = "generated-code" + File.separator + "slim4";
    embeddedTemplateDir = templateDir = "php-slim4-server";

    // override cliOptions from AbstractPhpCodegen
    updateOption(AbstractPhpCodegen.VARIABLE_NAMING_CONVENTION, "camelCase");

    // Slim 4 can use any PSR-7 implementation
    // https://www.slimframework.com/docs/v4/concepts/value-objects.html
    CliOption psr7Option = new CliOption(PSR7_IMPLEMENTATION,
            "Slim 4 provides its own PSR-7 implementation so that it works out of the box. However, you are free to replace Slim’s default PSR-7 objects with a third-party implementation. Ref: https://www.slimframework.com/docs/v4/concepts/value-objects.html");

    psr7Option.addEnum("slim-psr7", "Slim PSR-7 Message implementation")
            .addEnum("nyholm-psr7", "Nyholm PSR-7 Message implementation")
            .addEnum("guzzle-psr7", "Guzzle PSR-7 Message implementation")
            .addEnum("zend-diactoros", "Zend Diactoros PSR-7 Message implementation")
            .setDefault("slim-psr7");

    cliOptions.add(psr7Option);
}
 
Example #8
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 #9
Source File: GraphQLSchemaCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public GraphQLSchemaCodegen() {
        super();

        modifyFeatureSet(features -> features
//                .includeDocumentationFeatures(DocumentationFeature.Readme)
                .wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON))
                .securityFeatures(EnumSet.noneOf(
                        SecurityFeature.class
                ))
                .excludeGlobalFeatures(
                        GlobalFeature.XMLStructureDefinitions,
                        GlobalFeature.Callbacks,
                        GlobalFeature.LinkObjects,
                        GlobalFeature.ParameterStyling
                )
                .excludeSchemaSupportFeatures(
                        SchemaSupportFeature.Polymorphism
                )
        );

        outputFolder = "generated-code/graphql-schema";
        modelTemplateFiles.put("model.mustache", ".graphql");
        apiTemplateFiles.put("api.mustache", ".graphql");
        embeddedTemplateDir = templateDir = "graphql-schema";
        hideGenerationTimestamp = Boolean.TRUE;


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


        cliOptions.clear();
        cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "GraphQL package name (convention: lowercase).")
                .defaultValue("openapi2graphql"));
        cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "GraphQL package version.")
                .defaultValue("1.0.0"));
        cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
                .defaultValue(Boolean.TRUE.toString()));

    }
 
Example #10
Source File: CSharpDotNet2ClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public CSharpDotNet2ClientCodegen() {
    super();

    modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));

    generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
            .stability(Stability.DEPRECATED)
            .build();

    // clear import mapping (from default generator) as C# (2.0) does not use it
    // at the moment
    importMapping.clear();

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

    setApiPackage(packageName + ".Api");
    setModelPackage(packageName + ".Model");
    setClientPackage(packageName + ".Client");
    setSourceFolder("src" + File.separator + "main" + File.separator + "CsharpDotNet2");

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

    cliOptions.clear();
    cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME,
            "C# package name (convention: Camel.Case).")
            .defaultValue(packageName));
    cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION,
            "C# package version.")
            .defaultValue(packageVersion));
    cliOptions.add(new CliOption(CLIENT_PACKAGE,
            "C# client package name (convention: Camel.Case).")
            .defaultValue(clientPackage));
}
 
Example #11
Source File: Generator.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public static Map<String, CliOption> getOptions(String language) {
    CodegenConfig config;
    try {
        config = CodegenConfigLoader.forName(language);
    } catch (Exception e) {
        throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
                language, e));
    }
    Map<String, CliOption> map = new LinkedHashMap<>();
    for (CliOption option : config.cliOptions()) {
        map.put(option.getOpt(), option);
    }
    return map;
}
 
Example #12
Source File: GenApiService.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public ResponseEntity<Map<String, CliOption>> getServerOptions(String framework) {
    Map<String, CliOption> opts = Generator.getOptions(framework);

    if (opts != null) {
        return ResponseEntity.ok().body(opts);
    } else {
        return ResponseEntity.notFound().build();
    }
}
 
Example #13
Source File: GenApiService.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public ResponseEntity<Map<String, CliOption>> getClientOptions(String language) {
    Map<String, CliOption> opts = Generator.getOptions(language);

    if (opts != null) {
        return ResponseEntity.ok().body(opts);
    } else {
        return ResponseEntity.notFound().build();
    }
}
 
Example #14
Source File: GenApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", tags={ "servers", })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/gen/servers/{framework}",
        produces = { "application/json" },
        method = RequestMethod.GET)
default ResponseEntity<Map<String, CliOption>> getServerOptions(@ApiParam(value = "The target language for the server framework",required=true) @PathVariable("framework") String framework) {
    return getDelegate().getServerOptions(framework);
}
 
Example #15
Source File: GenApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", tags={ "clients", })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "successful operation") })
@RequestMapping(value = "/gen/clients/{language}",
        produces = { "application/json" },
        method = RequestMethod.GET)
default ResponseEntity<Map<String, CliOption>> getClientOptions(@ApiParam(value = "The target language for the client library",required=true) @PathVariable("language") String language) {
    return getDelegate().getClientOptions(language);
}
 
Example #16
Source File: PhpClientCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public PhpClientCodegen() {
    super();

    modifyFeatureSet(features -> features
            .includeDocumentationFeatures(DocumentationFeature.Readme)
            .wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML))
            .securityFeatures(EnumSet.noneOf(SecurityFeature.class))
            .excludeGlobalFeatures(
                    GlobalFeature.XMLStructureDefinitions,
                    GlobalFeature.Callbacks,
                    GlobalFeature.LinkObjects,
                    GlobalFeature.ParameterStyling
            )
            .excludeSchemaSupportFeatures(
                    SchemaSupportFeature.Polymorphism
            )
    );

    // clear import mapping (from default generator) as php does not use it
    // at the moment
    importMapping.clear();

    setInvokerPackage("OpenAPI\\Client");
    setApiPackage(getInvokerPackage() + "\\" + apiDirName);
    setModelPackage(getInvokerPackage() + "\\" + modelDirName);
    setPackageName("OpenAPIClient-php");
    supportsInheritance = true;
    setOutputDir("generated-code" + File.separator + "php");
    modelTestTemplateFiles.put("model_test.mustache", ".php");
    embeddedTemplateDir = templateDir = "php";

    // default HIDE_GENERATION_TIMESTAMP to true
    hideGenerationTimestamp = Boolean.TRUE;

    // provide primitives to mustache template
    List sortedLanguageSpecificPrimitives = new ArrayList(languageSpecificPrimitives);
    Collections.sort(sortedLanguageSpecificPrimitives);
    String primitives = "'" + StringUtils.join(sortedLanguageSpecificPrimitives, "', '") + "'";
    additionalProperties.put("primitives", primitives);

    cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.ALLOW_UNICODE_IDENTIFIERS_DESC)
            .defaultValue(Boolean.TRUE.toString()));
}
 
Example #17
Source File: GoServerCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public GoServerCodegen() {
    super();

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

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

    cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC)
            .defaultValue(sourceFolder));

    CliOption optServerPort = new CliOption("serverPort", "The network port the generated server binds to");
    optServerPort.setType("int");
    optServerPort.defaultValue(Integer.toString(serverPort));
    cliOptions.add(optServerPort);

    CliOption optFeatureCORS = new CliOption("featureCORS", "Enable Cross-Origin Resource Sharing middleware");
    optFeatureCORS.setType("bool");
    optFeatureCORS.defaultValue(corsFeatureEnabled.toString());
    cliOptions.add(optFeatureCORS);

    /*
     * 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",
            ".go");

    /*
     * 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(
            "controller-api.mustache",   // the template to use
            ".go");       // the extension for each file to write

    /*
     * Service templates.  You can write services for each Api file with the apiTemplateFiles map.
        These services are skeletons built to implement the logic of your api using the 
        expected parameters and response.
     */
    apiTemplateFiles.put(
            "service.mustache",   // the template to use
            "_service.go");       // 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.
     */
    embeddedTemplateDir = templateDir = "go-server";

    /*
     * Reserved words.  Override this with reserved words specific to your language
     */
    setReservedWordsLowerCase(
            Arrays.asList(
                    // data type
                    "string", "bool", "uint", "uint8", "uint16", "uint32", "uint64",
                    "int", "int8", "int16", "int32", "int64", "float32", "float64",
                    "complex64", "complex128", "rune", "byte", "uintptr",

                    "break", "default", "func", "interface", "select",
                    "case", "defer", "go", "map", "struct",
                    "chan", "else", "goto", "package", "switch",
                    "const", "fallthrough", "if", "range", "type",
                    "continue", "for", "import", "return", "var", "error", "nil")
            // Added "error" as it's used so frequently that it may as well be a keyword
    );
}
 
Example #18
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 #19
Source File: ApexClientCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public ApexClientCodegen() {
    super();

    importMapping.clear();

    embeddedTemplateDir = templateDir = "apex";
    outputFolder = "generated-code" + File.separator + "apex";
    modelPackage = apiPackage = srcPath + "classes";
    testPackage = "force-app.main.default.classes";
    modelNamePrefix = classPrefix;

    apiTemplateFiles.put("api.mustache", ".cls");
    apiTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml");
    apiTestTemplateFiles.put("api_test.mustache", ".cls");
    apiTestTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml");
    modelTemplateFiles.put("model.mustache", ".cls");
    modelTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml");
    modelTestTemplateFiles.put("model_test.mustache", ".cls");
    modelTestTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml");

    cliOptions.add(CliOption.newString(CLASS_PREFIX, "Prefix for generated classes. Set this to avoid overwriting existing classes in your org."));
    cliOptions.add(CliOption.newString(API_VERSION, "The Metadata API version number to use for components in this package."));
    cliOptions.add(CliOption.newString(BUILD_METHOD, "The build method for this package."));
    cliOptions.add(CliOption.newString(NAMED_CREDENTIAL, "The named credential name for the HTTP callouts"));

    supportingFiles.add(new SupportingFile("OAS.cls", srcPath + "classes", "OAS.cls"));
    supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OAS.cls-meta.xml"));
    supportingFiles.add(new SupportingFile("OASTest.cls", srcPath + "classes", "OASTest.cls"));
    supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OASTest.cls-meta.xml"));
    supportingFiles.add(new SupportingFile("OASResponseMock.cls", srcPath + "classes", "OASResponseMock.cls"));
    supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", "OASResponseMock.cls-meta.xml"));

    typeMapping.put("BigDecimal", "Double");
    typeMapping.put("binary", "String");
    typeMapping.put("ByteArray", "Blob");
    typeMapping.put("date", "Date");
    typeMapping.put("DateTime", "Datetime");
    typeMapping.put("file", "Blob");
    typeMapping.put("float", "Double");
    typeMapping.put("number", "Double");
    typeMapping.put("short", "Integer");
    typeMapping.put("UUID", "String");
    typeMapping.put("URI", "String");

    // https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reserved_words.htm
    setReservedWordsLowerCase(
            Arrays.asList("abstract", "activate", "and", "any", "array", "as", "asc", "autonomous",
                    "begin", "bigdecimal", "blob", "break", "bulk", "by", "byte", "case", "cast",
                    "catch", "char", "class", "collect", "commit", "const", "continue",
                    "convertcurrency", "currency", "date", "datetime", "decimal", "default", "delete", "desc", "do", "else",
                    "end", "enum", "exception", "exit", "export", "extends", "false", "final",
                    "finally", "float", "for", "from", "future", "global", "goto", "group", "having",
                    "hint", "if", "implements", "import", "in", "inner", "insert", "instanceof", "int",
                    "interface", "into", "join", "last_90_days", "last_month", "last_n_days",
                    "last_week", "like", "limit", "list", "long", "loop", "map", "merge", "new",
                    "next_90_days", "next_month", "next_n_days", "next_week", "not", "null", "nulls",
                    "number", "object", "of", "on", "or", "outer", "override", "package", "parallel",
                    "pragma", "private", "protected", "public", "retrieve", "return", "returning",
                    "rollback", "savepoint", "search", "select", "set", "short", "sort", "stat",
                    "static", "super", "switch", "synchronized", "system", "testmethod", "then", "this",
                    "this_month", "this_week", "throw", "time", "today", "tolabel", "tomorrow", "transaction",
                    "trigger", "true", "try", "type", "undelete", "update", "upsert", "using",
                    "virtual", "webservice", "when", "where", "while", "yesterday"
            ));

    languageSpecificPrimitives = new HashSet<String>(
            Arrays.asList("Blob", "Boolean", "Date", "Datetime", "Decimal", "Double", "ID",
                    "Integer", "Long", "Object", "String", "Time"
            ));

    primitiveDefaults.put("Boolean", true);
    primitiveDefaults.put("Decimal", 1);
    primitiveDefaults.put("Double", 1);
    primitiveDefaults.put("Integer", 1);
    primitiveDefaults.put("Long", 1);
    primitiveDefaults.put("String", "");

    instantiationTypes.put("array", "List");
    instantiationTypes.put("map", "Map");

}
 
Example #20
Source File: RubyOnRailsServerCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public RubyOnRailsServerCodegen() {
    super();

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

    outputFolder = "generated-code" + File.separator + "rails5";
    apiPackage = "app/controllers";
    apiTemplateFiles.put("controller.mustache", ".rb");

    modelPackage = "app/models";
    modelTemplateFiles.put("model.mustache", ".rb");

    embeddedTemplateDir = templateDir = "ruby-on-rails-server";

    // In order to adapt to DB migrate script, overwrite typeMapping
    typeMapping.put("string", "string");
    typeMapping.put("int", "integer");
    typeMapping.put("integer", "integer");
    typeMapping.put("long", "integer");
    typeMapping.put("short", "integer");
    typeMapping.put("DateTime", "datetime");
    typeMapping.put("boolean", "boolean");

    // remove modelPackage and apiPackage added by default
    cliOptions.clear();

    cliOptions.add(new CliOption(CodegenConstants.DATABASE_ADAPTER, CodegenConstants.DATABASE_ADAPTER_DESC).
            defaultValue("sqlite"));
}
 
Example #21
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."));
}
 
Example #22
Source File: GoClientCodegen.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
public GoClientCodegen() {
    super();

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

    outputFolder = "generated-code/go";
    modelTemplateFiles.put("model.mustache", ".go");
    apiTemplateFiles.put("api.mustache", ".go");

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

    embeddedTemplateDir = templateDir = "go";

    // default HIDE_GENERATION_TIMESTAMP to true
    hideGenerationTimestamp = Boolean.TRUE;

    cliOptions.add(CliOption.newBoolean(CodegenConstants.IS_GO_SUBMODULE, CodegenConstants.IS_GO_SUBMODULE_DESC));
    cliOptions.add(CliOption.newBoolean(WITH_GO_CODEGEN_COMMENT, "whether to include Go codegen comment to disable Go Lint and collapse by default in GitHub PRs and diffs"));
    cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
    cliOptions.add(CliOption.newBoolean(CodegenConstants.ENUM_CLASS_PREFIX, CodegenConstants.ENUM_CLASS_PREFIX_DESC));
    cliOptions.add(CliOption.newBoolean(STRUCT_PREFIX, "whether to prefix struct with the class name. e.g. DeletePetOpts => PetApiDeletePetOpts"));
    cliOptions.add(CliOption.newBoolean(WITH_AWSV4_SIGNATURE, "whether to include AWS v4 signature support"));

    // option to change the order of form/body parameter
    cliOptions.add(CliOption.newBoolean(
            CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS,
            CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS_DESC)
            .defaultValue(Boolean.FALSE.toString()));
}
 
Example #23
Source File: GenApiDelegate.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * @param framework The target generator name (framework is a slight misnomer here, as we may have a framework like Spring implemented in multiple languages).
 * @see GenApi#getServerOptions
 * @return A {@link ResponseEntity} of {@link CliOption}, grouped by framework (generator name).
 */
default ResponseEntity<Map<String, CliOption>> getServerOptions( String  framework) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example #24
Source File: GenApiDelegate.java    From openapi-generator with Apache License 2.0 2 votes vote down vote up
/**
 * @param language The target generator (language is a misnomer here, but kept for API consistency).
 * @see GenApi#getClientOptions
 * @return A {@link ResponseEntity} of {@link CliOption}, grouped by language (generator name).
 */
default ResponseEntity<Map<String, CliOption>> getClientOptions(String  language) {
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}