#1809 Adding basic angular2 typescript codegen.

This commit is contained in:
Kristof Vrolijkx
2016-04-19 11:02:36 +02:00
parent 3332692d30
commit f4fc88c6be
9 changed files with 482 additions and 8 deletions

View File

@@ -1,8 +1,9 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.SupportingFile;
import java.io.File;
import io.swagger.codegen.SupportingFile;
public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
@Override
@@ -14,14 +15,13 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public String getHelp() {
return "Generates a TypeScript AngularJS client library.";
}
@Override
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage().replace('.', File.separatorChar), "api.d.ts"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
@Override
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage().replace('.', File.separatorChar), "api.d.ts"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}

View File

@@ -0,0 +1,81 @@
package io.swagger.codegen.languages;
import java.io.File;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCodegen {
public TypeScriptAngular2ClientCodegen() {
super();
this.outputFolder = "generated-code/typescript-angular2";
embeddedTemplateDir = templateDir = "typescript-angular2";
modelTemplateFiles.put("model.mustache", ".ts");
apiTemplateFiles.put("api.mustache", ".ts");
typeMapping.put("Date","Date");
apiPackage = "api";
modelPackage = "model";
}
@Override
public String getName() {
return "TypeScript-Angular2";
}
@Override
public String getHelp() {
return "Generates a TypeScript Angular2 client library.";
}
@Override
public void processOpts() {
super.processOpts();
supportingFiles.clear();
supportingFiles.add(new SupportingFile("model.d.mustache", modelPackage().replace('.', File.separatorChar), "model.d.ts"));
}
@Override
public String getTypeDeclaration(Property p) {
Property inner;
if(p instanceof ArrayProperty) {
ArrayProperty mp1 = (ArrayProperty)p;
inner = mp1.getItems();
return this.getSwaggerType(p) + "<" + this.getTypeDeclaration(inner) + ">";
} else if(p instanceof MapProperty) {
MapProperty mp = (MapProperty)p;
inner = mp.getAdditionalProperties();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else {
return p instanceof FileProperty ? "any" : super.getTypeDeclaration(p);
}
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
return addModelPrefix(swaggerType);
}
private String addModelPrefix(String swaggerType) {
String type = null;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type))
return type;
} else
type = "model." + swaggerType;
return type;
}
@Override
public void postProcessParameter(CodegenParameter parameter) {
super.postProcessParameter(parameter);
parameter.dataType = addModelPrefix(parameter.dataType);
}
}