Merge pull request #3582 from regga-ws/compiler-customization

Adding support for JMustache compiler customization
This commit is contained in:
wing328 2016-08-16 14:21:20 +08:00 committed by GitHub
commit 9858403f2e
3 changed files with 18 additions and 2 deletions

View File

@ -10,6 +10,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.samskivert.mustache.Mustache.Compiler;
public interface CodegenConfig {
CodegenType getTag();
@ -117,6 +119,8 @@ public interface CodegenConfig {
void processSwagger(Swagger swagger);
Compiler processCompiler(Compiler compiler);
String sanitizeTag(String tag);
String toApiFilename(String name);

View File

@ -2,6 +2,8 @@ package io.swagger.codegen;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.samskivert.mustache.Mustache.Compiler;
import io.swagger.codegen.examples.ExampleGenerator;
import io.swagger.models.ArrayModel;
import io.swagger.models.ComposedModel;
@ -326,6 +328,12 @@ public class DefaultCodegen {
@SuppressWarnings("unused")
public void processSwagger(Swagger swagger) {
}
// override with any special handling of the JMustache compiler
@SuppressWarnings("unused")
public Compiler processCompiler(Compiler compiler) {
return compiler;
}
// override with any special text escaping logic
@SuppressWarnings("static-method")

View File

@ -560,7 +560,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
if(ignoreProcessor.allowsFile(new File(outputFilename))) {
if (templateFile.endsWith("mustache")) {
String template = readTemplate(templateFile);
Template tmpl = Mustache.compiler()
Mustache.Compiler compiler = Mustache.compiler();
compiler = config.processCompiler(compiler);
Template tmpl = compiler
.withLoader(new Mustache.TemplateLoader() {
@Override
public Reader getTemplate(String name) {
@ -641,7 +643,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
if(ignoreProcessor.allowsFile(new File(outputFilename.replaceAll("//", "/")))) {
String templateFile = getFullTemplateFile(config, templateName);
String template = readTemplate(templateFile);
Template tmpl = Mustache.compiler()
Mustache.Compiler compiler = Mustache.compiler();
compiler = config.processCompiler(compiler);
Template tmpl = compiler
.withLoader(new Mustache.TemplateLoader() {
@Override
public Reader getTemplate(String name) {