forked from loafle/openapi-generator-original
added config parameters for all default parameters and a configOptions map for language specific parameters
This commit is contained in:
parent
11e56f5c9c
commit
ce6ec20fef
@ -7,10 +7,12 @@ package io.swagger.codegen.plugin;
|
||||
*/
|
||||
public final class AdditionalParams {
|
||||
public static final String TEMPLATE_DIR_PARAM = "templateDir";
|
||||
public static final String MODEL_PACKAGE_PARAM = "modelPackage";
|
||||
public static final String API_PACKAGE_PARAM = "apiPackage";
|
||||
public static final String INVOKER_PACKAGE_PARAM = "invokerPackage";
|
||||
public static final String SOURCE_FOLDER_PARAM = "sourceFolder";
|
||||
public static final String IMPL_FOLDER_PARAM = "implFolder";
|
||||
|
||||
private AdditionalParams() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package io.swagger.codegen.plugin;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.ClientOptInput;
|
||||
import io.swagger.codegen.ClientOpts;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
@ -30,16 +31,16 @@ import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.TEMPLATE_DIR_PARAM;
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.*;
|
||||
|
||||
/**
|
||||
* Goal which generates client/server code from a swagger json/yaml definition.
|
||||
*/
|
||||
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* Location of the output directory.
|
||||
*/
|
||||
@ -60,12 +61,47 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name = "templateDirectory")
|
||||
private File templateDirectory;
|
||||
|
||||
/**
|
||||
* Folder containing the template files.
|
||||
*/
|
||||
@Parameter(name = "modelPackage")
|
||||
private String modelPackage;
|
||||
|
||||
/**
|
||||
* Folder containing the template files.
|
||||
*/
|
||||
@Parameter(name = "apiPackage")
|
||||
private String apiPackage;
|
||||
|
||||
/**
|
||||
* Folder containing the template files.
|
||||
*/
|
||||
@Parameter(name = "invokerPackage")
|
||||
private String invokerPackage;
|
||||
|
||||
/**
|
||||
* Folder containing the template files.
|
||||
*/
|
||||
@Parameter(name = "implFolder")
|
||||
private String implFolder;
|
||||
|
||||
/**
|
||||
* Folder containing the template files.
|
||||
*/
|
||||
@Parameter(name = "sourceFolder")
|
||||
private File sourceFolder;
|
||||
|
||||
/**
|
||||
* Client language to generate.
|
||||
*/
|
||||
@Parameter(name = "language", required = true)
|
||||
private String language;
|
||||
|
||||
/**
|
||||
* A map of language-specific properties as passed with the -c option to the command line
|
||||
*/
|
||||
@Parameter(name ="configOptions")
|
||||
private Map configOptions;
|
||||
|
||||
/**
|
||||
* Add the output directory to the project as a source root, so that the
|
||||
@ -90,8 +126,33 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
if (null != templateDirectory) {
|
||||
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory.getAbsolutePath());
|
||||
}
|
||||
if (null != modelPackage) {
|
||||
config.additionalProperties().put(MODEL_PACKAGE_PARAM, modelPackage );
|
||||
}
|
||||
if (null != apiPackage) {
|
||||
config.additionalProperties().put(API_PACKAGE_PARAM, apiPackage);
|
||||
}
|
||||
if (null != invokerPackage) {
|
||||
config.additionalProperties().put(INVOKER_PACKAGE_PARAM, invokerPackage);
|
||||
}
|
||||
if (null != sourceFolder) {
|
||||
config.additionalProperties().put(SOURCE_FOLDER_PARAM, sourceFolder.getAbsolutePath());
|
||||
}
|
||||
if (null != implFolder) {
|
||||
config.additionalProperties().put(IMPL_FOLDER_PARAM, implFolder);
|
||||
}
|
||||
|
||||
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
|
||||
ClientOpts clientOpts = new ClientOpts();
|
||||
if( configOptions != null ){
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
if (configOptions.containsKey(langCliOption.getOpt())) {
|
||||
config.additionalProperties().put(langCliOption.getOpt(),
|
||||
configOptions.get(langCliOption.getOpt()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClientOptInput input = new ClientOptInput().opts(clientOpts).swagger(swagger);
|
||||
input.setConfig(config);
|
||||
new DefaultGenerator().opts(input).generate();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user