Merge branch 'angular2-standalone-enums-support' of https://github.com/SamuelBeliveau/swagger-codegen into SamuelBeliveau-angular2-standalone-enums-support

This commit is contained in:
wing328 2016-12-15 00:09:34 +08:00
commit 7b7e5e25ee
8 changed files with 60 additions and 39 deletions

View File

@ -26,6 +26,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
protected String modelPropertyNaming= "camelCase";
protected Boolean supportsES6 = true;
protected HashSet<String> languageGenericTypes;
public AbstractTypeScriptClientCodegen() {
super();
@ -58,6 +59,11 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
"any",
"Error"
));
languageGenericTypes = new HashSet<String>(Arrays.asList(
"Array"
));
instantiationTypes.put("array", "Array");
typeMapping = new HashMap<String, String>();

View File

@ -132,7 +132,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
if(languageSpecificPrimitives.contains(swaggerType)) {
if(isLanguagePrimitive(swaggerType) || isLanguageGenericType(swaggerType)) {
return swaggerType;
}
return addModelPrefix(swaggerType);
@ -146,15 +146,19 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
type = swaggerType;
}
if (!startsWithLanguageSpecificPrimitiv(type)) {
if (!isLanguagePrimitive(type) && !isLanguageGenericType(type)) {
type = "models." + swaggerType;
}
return type;
}
private boolean startsWithLanguageSpecificPrimitiv(String type) {
for (String langPrimitive:languageSpecificPrimitives) {
if (type.startsWith(langPrimitive)) {
private boolean isLanguagePrimitive(String type) {
return languageSpecificPrimitives.contains(type);
}
private boolean isLanguageGenericType(String type) {
for (String genericType: languageGenericTypes) {
if (type.startsWith(genericType + "<")) {
return true;
}
}

View File

@ -8,35 +8,6 @@ import * as models from './models';
* {{{description}}}
*/
{{/description}}
export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{
{{#additionalPropertiesType}}
[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};
{{/additionalPropertiesType}}
{{#vars}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
{{/vars}}
}
{{#hasEnums}}
export namespace {{classname}} {
{{#vars}}
{{#isEnum}}
export enum {{enumName}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}
{{/isEnum}}
{{/vars}}
}
{{/hasEnums}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}
{{/model}}
{{/models}}
{{/models}}

View File

@ -0,0 +1,12 @@
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
export enum {{classname}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}

View File

@ -0,0 +1,28 @@
export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{
{{#additionalPropertiesType}}
[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};
{{/additionalPropertiesType}}
{{#vars}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
{{/vars}}
}{{#hasEnums}}
export namespace {{classname}} {
{{#vars}}
{{#isEnum}}
export enum {{enumName}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}
{{/isEnum}}
{{/vars}}
}{{/hasEnums}}

View File

@ -27,7 +27,7 @@ import { Configuration } from '../configurat
@Injectable()
export class PetApi {
protected basePath = 'http://petstore.swagger.io/v2';
protected basePath = '';
public defaultHeaders: Headers = new Headers();
public configuration: Configuration = new Configuration();

View File

@ -27,7 +27,7 @@ import { Configuration } from '../configurat
@Injectable()
export class StoreApi {
protected basePath = 'http://petstore.swagger.io/v2';
protected basePath = '';
public defaultHeaders: Headers = new Headers();
public configuration: Configuration = new Configuration();

View File

@ -27,7 +27,7 @@ import { Configuration } from '../configurat
@Injectable()
export class UserApi {
protected basePath = 'http://petstore.swagger.io/v2';
protected basePath = '';
public defaultHeaders: Headers = new Headers();
public configuration: Configuration = new Configuration();