Adding an index file and avoiding the use of the model.d.ts files because typescript doesn't compile it correctly.

This commit is contained in:
Kristof Vrolijkx 2016-04-20 11:10:29 +02:00
parent 2af29fa831
commit 1825a467d8
7 changed files with 29 additions and 18 deletions

View File

@ -37,7 +37,15 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
public void processOpts() {
super.processOpts();
supportingFiles.clear();
supportingFiles.add(new SupportingFile("model.d.mustache", modelPackage().replace('.', File.separatorChar), "model.d.ts"));
supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts"));
supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts"));
supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts"));
}
private String getIndexDirectory() {
String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.')));
return indexPackage.replace('.', File.separatorChar);
}
@Override
@ -69,7 +77,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
if (languageSpecificPrimitives.contains(type))
return type;
} else
type = "model." + swaggerType;
type = "models." + swaggerType;
return type;
}
@ -78,4 +86,5 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
super.postProcessParameter(parameter);
parameter.dataType = addModelPrefix(parameter.dataType);
}
}

View File

@ -1,7 +1,7 @@
import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http';
import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import * as model from "../model/model.d.ts"
import * as models from "../model/models.ts"
/* tslint:disable:no-unused-variable member-ordering */

View File

@ -1,11 +1,3 @@
{{#models}}
{{#model}}
export * from './{{{ classname }}}';
{{/model}}
{{/models}}
{{#apiInfo}}
{{#apis}}
{{#operations}}

View File

@ -0,0 +1,2 @@
export * from './api/apis.ts';
export * from './model/models.ts';

View File

@ -1,14 +1,14 @@
{{#models}}
{{#model}}
'use strict';
import * as model from "./model.d.ts"
import * as models from "./models.ts"
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
export interface {{classname}} {{#parent}}extends model.{{{parent}}} {{/parent}}{
export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}

View File

@ -0,0 +1,8 @@
{{#models}}
{{#model}}
export * from './{{{ classname }}}';
{{/model}}
{{/models}}

View File

@ -119,10 +119,10 @@ public class TypeScriptAngular2ModelTest {
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "children");
Assert.assertEquals(property1.datatype, "model.Children");
Assert.assertEquals(property1.datatype, "models.Children");
Assert.assertEquals(property1.name, "children");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertEquals(property1.baseType, "model.Children");
Assert.assertEquals(property1.baseType, "models.Children");
Assert.assertNull(property1.required);
Assert.assertTrue(property1.isNotContainer);
}
@ -143,8 +143,8 @@ public class TypeScriptAngular2ModelTest {
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "children");
Assert.assertEquals(property1.complexType, "model.Children");
Assert.assertEquals(property1.datatype, "Array<model.Children>");
Assert.assertEquals(property1.complexType, "models.Children");
Assert.assertEquals(property1.datatype, "Array<models.Children>");
Assert.assertEquals(property1.name, "children");
Assert.assertEquals(property1.baseType, "Array");
Assert.assertNull(property1.required);
@ -178,6 +178,6 @@ public class TypeScriptAngular2ModelTest {
Assert.assertEquals(cm.description, "a map model");
Assert.assertEquals(cm.vars.size(), 0);
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("model.Children")).size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("models.Children")).size(), 1);
}
}