[meta] remove cli dependency (#2896)

This commit is contained in:
Jérémie Bresson
2019-05-19 21:25:16 +02:00
committed by GitHub
parent e85e1f112a
commit 4e579ff75b
8 changed files with 74 additions and 91 deletions

View File

@@ -0,0 +1,36 @@
package com.my.company.codegen;
import org.junit.Test;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.config.CodegenConfigurator;
/***
* This test allows you to easily launch your code generation software under a debugger.
* Then run this test under debug mode. You will be able to step through your java code
* and then see the results in the out directory.
*
* To experiment with debugging your code generator:
* 1) Set a break point in MyclientcodegenGenerator.java in the postProcessOperationsWithModels() method.
* 2) To launch this test in Eclipse: right-click | Debug As | JUnit Test
*
*/
public class MyclientcodegenGeneratorTest {
// use this test to launch you code generator in the debugger.
// this allows you to easily set break points in MyclientcodegenGenerator.
@Test
public void launchCodeGenerator() {
// to understand how the 'openapi-generator-cli' module is using 'CodegenConfigurator', have a look at the 'Generate' class:
// https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("myClientCodegen") // use this codegen library
.setInputSpec("../../../modules/openapi-generator/src/test/resources/2_0/petstore.yaml") // sample OpenAPI file
// .setInputSpec("https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml") // or from the server
.setOutputDir("out/myClientCodegen"); // output directory
final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
generator.opts(clientOptInput).generate();
}
}

View File

@@ -1,40 +0,0 @@
package org.openapitools.codegen.debug;
import org.junit.Test;
import org.openapitools.codegen.OpenAPIGenerator;
/***
* This test allows you to easily launch your code generation software under a debugger.
* Then run this test under debug mode. You will be able to step through your java code
* and then see the results in the out directory.
*
* To experiment with debugging your code generator:
* 1) Set a break point in MyclientcodegenGenerator.java in the postProcessOperationsWithModels() method.
* 2) To launch this test in Eclipse: right-click | Debug As | JUnit Test
*
*/
public class DebugCodegenLauncher
{
@Test
public void launchCodeGeneratorInDebugMode()
{
// use this test to launch you code generator in the debugger.
// this allows you to easily set break points in MyclientcodegenGenerator.
String commandLineParams =
"generate "+
"-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml "+ // sample swagger
"-t ./src/main/resources/myClientCodegen "+ // template directory
"-o out/myClientCodegen "+ // output directory
"-g myClientCodegen "; // use this codegen library
try{
OpenAPIGenerator.main( commandLineParams.split(" ") );
}
catch(Exception ex) {
System.err.println(ex.toString());
}
catch(Error er) {
System.err.println(er.toString());
}
}
}