Fix for the template resovling from classpath on Windows

This commit is contained in:
Fleque 2015-01-22 11:38:42 +01:00
parent a15eb6f905
commit 8f9947a20a

View File

@ -1,16 +1,35 @@
package com.wordnik.swagger.codegen; package com.wordnik.swagger.codegen;
import com.wordnik.swagger.models.*; import java.io.BufferedWriter;
import com.wordnik.swagger.models.properties.*; import java.io.File;
import com.wordnik.swagger.util.*; import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.wordnik.swagger.codegen.languages.*; import java.io.IOException;
import com.samskivert.mustache.*; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.util.*; import com.samskivert.mustache.Mustache;
import java.io.*; import com.samskivert.mustache.Template;
import com.wordnik.swagger.models.Contact;
import com.wordnik.swagger.models.Info;
import com.wordnik.swagger.models.License;
import com.wordnik.swagger.models.Model;
import com.wordnik.swagger.models.Operation;
import com.wordnik.swagger.models.Path;
import com.wordnik.swagger.models.Swagger;
import com.wordnik.swagger.util.Json;
public class DefaultGenerator implements Generator { public class DefaultGenerator implements Generator {
private CodegenConfig config; private CodegenConfig config;
@ -282,7 +301,7 @@ public class DefaultGenerator implements Generator {
public Reader getTemplateReader(String name) { public Reader getTemplateReader(String name) {
try{ try{
InputStream is = this.getClass().getClassLoader().getResourceAsStream(name); InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
if(is == null) if(is == null)
is = new FileInputStream(new File(name)); is = new FileInputStream(new File(name));
if(is == null) if(is == null)
@ -295,7 +314,13 @@ public class DefaultGenerator implements Generator {
throw new RuntimeException("can't load template " + name); throw new RuntimeException("can't load template " + name);
} }
public Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) { private String getCPResourcePath(String name) {
if (!"/".equals(File.separator))
return name.replaceAll(Pattern.quote(File.separator), "/");
return name;
}
public Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) {
Map<String, Object> operations = new HashMap<String, Object>(); Map<String, Object> operations = new HashMap<String, Object>();
Map<String, Object> objs = new HashMap<String, Object>(); Map<String, Object> objs = new HashMap<String, Object>();
objs.put("classname", config.toApiName(tag)); objs.put("classname", config.toApiName(tag));