mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-17 00:21:19 +00:00
[cli] new 'author template' command (#6441)
* [cli] new 'author template' command This new command allows users to extract templates for authoring (customization) without the complexity of finding and downloading a specific directory for their versioned artifact. Example usage: ``` openapi-generator author template -g java --library webclient ``` This will write all templates with library-specific templates to the './out' directory relative to the current directory. CLI will refer the user to https://openapi-generator.tech/docs/templating after generation * [docs] Usage of author template command * Log warning if author template fails to output requested library
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package org.openapitools.codegen.cmd;
|
||||
|
||||
import io.airlift.airline.Cli;
|
||||
import org.testng.Assert;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AuthorTemplateTest {
|
||||
Path outputDirectory;
|
||||
|
||||
@BeforeTest
|
||||
public void setUp(ITestContext ctx) throws IOException {
|
||||
outputDirectory = Files.createTempDirectory("AuthorTemplateTest");
|
||||
outputDirectory.toFile().deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smokeTestAuthorTemplateCommand(){
|
||||
Cli.CliBuilder<Runnable> builder = createBuilder();
|
||||
String[] arguments = new String[]{
|
||||
"author",
|
||||
"template",
|
||||
"-g",
|
||||
"java",
|
||||
"--library",
|
||||
"webclient",
|
||||
"--output",
|
||||
outputDirectory.toAbsolutePath().toString()
|
||||
};
|
||||
builder.build().parse(arguments).run();
|
||||
|
||||
// spot check root files
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("ApiClient.mustache")));
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("api_doc.mustache")));
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("pom.mustache")));
|
||||
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("auth/OAuth.mustache")));
|
||||
|
||||
// check libraries files and subdirectories
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("libraries/webclient/ApiClient.mustache")));
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("libraries/webclient/pom.mustache")));
|
||||
Assert.assertTrue(Files.exists(outputDirectory.resolve("libraries/webclient/auth/OAuth.mustache")));
|
||||
|
||||
// check non-existence of unselected libraries
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/feign/build.gradle.mustache")));
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/feign/auth/OAuth.mustache")));
|
||||
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/jersey2/api_doc.mustache")));
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/jersey2/auth/HttpBasicAuth.mustache")));
|
||||
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/okhttp-gson/api.mustache")));
|
||||
Assert.assertFalse(Files.exists(outputDirectory.resolve("libraries/okhttp-gson/auth/RetryingOAuth.mustache")));
|
||||
}
|
||||
|
||||
private Cli.CliBuilder<Runnable> createBuilder(){
|
||||
Cli.CliBuilder<Runnable> builder = new Cli.CliBuilder<>("openapi-generator-cli");
|
||||
|
||||
builder.withGroup("author")
|
||||
.withDescription("Utilities for authoring generators or customizing templates.")
|
||||
.withDefaultCommand(HelpCommand.class)
|
||||
.withCommands(AuthorTemplate.class);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user