Java Code Examples for org.openapitools.codegen.config.CodegenConfigurator#setGeneratorName()

The following examples show how to use org.openapitools.codegen.config.CodegenConfigurator#setGeneratorName() . 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: APIClientGenerationManager.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to generate SDK for a API for a given language
 *
 * @param apiName             name of the API
 * @param specLocation        location of the swagger spec for the API
 * @param sdkLanguage         preferred SDK language
 * @param temporaryOutputPath temporary location where the SDK archive is saved until downloaded
 */
private void generateClient(String apiName, String specLocation, String sdkLanguage, String temporaryOutputPath) {

    APIManagerConfiguration config = getAPIManagerConfiguration();
    CodegenConfigurator codegenConfigurator = new CodegenConfigurator();
    codegenConfigurator.setGroupId(config.getFirstProperty(APIConstants.CLIENT_CODEGEN_GROUPID));
    codegenConfigurator.setArtifactId(config.getFirstProperty(APIConstants.CLIENT_CODEGEN_ARTIFACTID) + apiName);
    codegenConfigurator
            .setModelPackage(config.getFirstProperty(APIConstants.CLIENT_CODEGEN_MODAL_PACKAGE) + apiName);
    codegenConfigurator.setApiPackage(config.getFirstProperty(APIConstants.CLIENT_CODEGEN_API_PACKAGE) + apiName);
    codegenConfigurator.setInputSpec(specLocation);
    codegenConfigurator.setGeneratorName(sdkLanguage);
    codegenConfigurator.setOutputDir(temporaryOutputPath);
    final ClientOptInput clientOptInput = codegenConfigurator.toClientOptInput();
    new DefaultGenerator().opts(clientOptInput).generate();

}
 
Example 2
Source File: GeneratorTest.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
private void generateServiceCombCode(String programmingModel)
    throws IOException, URISyntaxException, IllegalAccessException, NoSuchFieldException {

  Path tempDir = Files.createTempDirectory(null);
  Path specFilePath = Paths.get(GeneratorTest.class.getClassLoader().getResource("swagger.yaml").toURI());
  CodegenConfigurator configurator = new CodegenConfigurator();

  configurator.setGeneratorName("ServiceComb");
  configurator.setLibrary(programmingModel);
  configurator.setOutputDir(tempDir.toFile().getCanonicalPath() + "/ServiceComb");
  configurator.setInputSpec(specFilePath.toFile().getCanonicalPath());
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.PROVIDER_PROJECT_NAME, "mock-provider");
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.CONSUMER_PROJECT_NAME, "mock-consumer");
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.MODEL_PROJECT_NAME, "mock-model");
  DefaultCodeGenerator codeGenerator = new DefaultCodeGenerator();
  codeGenerator.configure(Collections.singletonMap("configurators", Collections.singletonList(configurator)));

  try {
    codeGenerator.generate();
  } catch (RuntimeException e) {
    fail("Run 'testGenerateProgrammingModels' failed while input " + programmingModel
        + " unexpected to catch RuntimeException: " + e.getMessage());
  }

  Object internalGenerator = ReflectUtils.getProperty(codeGenerator, "generator");
  Assert.assertEquals(MultiContractGenerator.class, internalGenerator.getClass());
  Object swaggerCodegenConfig = ReflectUtils.getProperty(internalGenerator, "config");
  Assert.assertEquals(ServiceCombCodegen.class, swaggerCodegenConfig.getClass());
  Assert.assertEquals("ServiceComb", ((ServiceCombCodegen) swaggerCodegenConfig).getName());
  Assert.assertEquals(CodegenType.SERVER, ((ServiceCombCodegen) swaggerCodegenConfig).getTag());

  tempDir.toFile().deleteOnExit();
}
 
Example 3
Source File: GeneratorTest.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Test
public void generateSpringCloudProject()
    throws IOException, URISyntaxException, IllegalAccessException, NoSuchFieldException {

  Path tempDir = Files.createTempDirectory(null);
  Path specFilePath = Paths.get(GeneratorTest.class.getClassLoader().getResource("swagger.yaml").toURI());
  CodegenConfigurator configurator = new CodegenConfigurator();

  configurator.setGeneratorName("SpringCloud");
  configurator.setOutputDir(tempDir.toFile().getCanonicalPath() + "/SpringCloud");
  configurator.setInputSpec(specFilePath.toFile().getCanonicalPath());
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.PROVIDER_PROJECT_NAME, "mock-provider");
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.CONSUMER_PROJECT_NAME, "mock-consumer");
  configurator.addAdditionalProperty(GeneratorExternalConfigConstant.MODEL_PROJECT_NAME, "mock-model");
  DefaultCodeGenerator codeGenerator = new DefaultCodeGenerator();
  codeGenerator.configure(Collections.singletonMap("configurators", Collections.singletonList(configurator)));

  try {
    codeGenerator.generate();
  } catch (RuntimeException e) {
    fail("Run 'testGenerateProgrammingModels' failed. Unexpected to catch RuntimeException: " + e.getMessage());
  }

  Object internalGenerator = ReflectUtils.getProperty(codeGenerator, "generator");
  Assert.assertEquals(MultiContractGenerator.class, internalGenerator.getClass());
  Object swaggerCodegenConfig = ReflectUtils.getProperty(internalGenerator, "config");
  Assert.assertEquals(SpringCloudCodegen.class, swaggerCodegenConfig.getClass());
  Assert.assertEquals("SpringCloud", ((SpringCloudCodegen) swaggerCodegenConfig).getName());
  Assert.assertEquals(CodegenType.SERVER, ((SpringCloudCodegen) swaggerCodegenConfig).getTag());
  Assert
      .assertEquals("Generates a SpringCloud server library.", ((SpringCloudCodegen) swaggerCodegenConfig).getHelp());

  tempDir.toFile().deleteOnExit();
}
 
Example 4
Source File: ApiGenerator.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
protected void generate(MustacheFactory mf, File javaSrcDir, Database database, HashMap<String, String> parentMap)
        throws Exception {
    log.info("Starting to Generate the Java classes for OpenAPI document: " + this.openApiFile.getCanonicalPath());
    String packageName = parentMap.get("packageName");
    String outputDir = this.outputDirectory.getAbsolutePath();

    CodegenConfigurator configurator = new CodegenConfigurator();
    configurator.setPackageName(packageName);
    configurator.setApiPackage(packageName);
    configurator.addDynamicProperty("configPackage", packageName);
    configurator.addDynamicProperty("basePackage", packageName);
    configurator.setModelPackage(packageName);

    //configurator.addSystemProperty("models", "");
    //configurator.addSystemProperty("modelDocs", "false");
    //configurator.addSystemProperty("modelTests", "false");

    configurator.setInputSpec(this.openApiFile.getAbsolutePath());

    configurator.setGeneratorName("org.teiid.maven.TeiidCodegen");
    configurator.setOutputDir(outputDir);
    configurator.setLibrary("spring-boot");
    configurator.addDynamicProperty("delegatePattern", "true");
    configurator.setIgnoreFileOverride(null);

    final ClientOptInput input = configurator.toClientOptInput();
    new DefaultGenerator().opts(input).generate();

    log.info("Generated the Java classes for OpenAPI document: " + this.openApiFile.getCanonicalPath());
}