Add file response support for typescript-node

This commit is contained in:
www2k 2016-10-31 01:59:19 +09:00
parent e14be8bab9
commit ed1b6075e9
2 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package io.swagger.codegen.languages; package io.swagger.codegen.languages;
import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.Property;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,6 +29,8 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
public TypeScriptNodeClientCodegen() { public TypeScriptNodeClientCodegen() {
super(); super();
typeMapping.put("file", "Buffer");
// clear import mapping (from default generator) as TS does not use it // clear import mapping (from default generator) as TS does not use it
// at the moment // at the moment
importMapping.clear(); importMapping.clear();
@ -92,6 +96,19 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
return "Generates a TypeScript nodejs client library."; return "Generates a TypeScript nodejs client library.";
} }
@Override
public boolean isDataTypeFile(final String dataType) {
return dataType != null && dataType.equals("Buffer");
}
@Override
public String getTypeDeclaration(Property p) {
if (p instanceof FileProperty) {
return "Buffer";
}
return super.getTypeDeclaration(p);
}
public void setNpmName(String npmName) { public void setNpmName(String npmName) {
this.npmName = npmName; this.npmName = npmName;

View File

@ -235,7 +235,12 @@ export class {{classname}} {
headers: headerParams, headers: headerParams,
uri: localVarPath, uri: localVarPath,
useQuerystring: this._useQuerystring, useQuerystring: this._useQuerystring,
{{^isResponseFile}}
json: true, json: true,
{{/isResponseFile}}
{{#isResponseFile}}
encoding: null,
{{/isResponseFile}}
{{#bodyParam}} {{#bodyParam}}
body: {{paramName}}, body: {{paramName}},
{{/bodyParam}} {{/bodyParam}}