Skip to content

Commit

Permalink
add free form object support to ts fetch (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Apr 4, 2019
1 parent d9ae80f commit 9368bea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public AbstractTypeScriptClientCodegen() {
"any",
"File",
"Error",
"Map"
"Map",
"object"
));

languageGenericTypes = new HashSet<String>(Arrays.asList(
Expand All @@ -106,7 +107,7 @@ public AbstractTypeScriptClientCodegen() {
typeMapping.put("short", "number");
typeMapping.put("char", "string");
typeMapping.put("double", "number");
typeMapping.put("object", "any");
typeMapping.put("object", "object");
typeMapping.put("integer", "number");
typeMapping.put("Map", "any");
typeMapping.put("map", "any");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function {{classname}}FromJSON(json: any): {{classname}} {
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}(json['{{baseName}}'] as Array<any>).map({{#items}}{{datatype}}{{/items}}FromJSON),
{{/isContainer}}
{{^isContainer}}
{{^isFreeFormObject}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}{{datatype}}FromJSON(json['{{baseName}}']),
{{/isFreeFormObject}}
{{#isFreeFormObject}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}json['{{baseName}}'],
{{/isFreeFormObject}}
{{/isContainer}}
{{/isPrimitiveType}}
{{/allVars}}
Expand All @@ -77,7 +82,12 @@ export function {{classname}}ToJSON(value?: {{classname}}): any {
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}(value.{{name}} as Array<any>).map({{#items}}{{datatype}}{{/items}}ToJSON),
{{/isContainer}}
{{^isContainer}}
{{^isFreeFormObject}}
'{{baseName}}': {{datatype}}ToJSON(value.{{name}}),
{{/isFreeFormObject}}
{{#isFreeFormObject}}
'{{baseName}}': value.{{name}},
{{/isFreeFormObject}}
{{/isContainer}}
{{/isPrimitiveType}}
{{/isReadOnly}}
Expand Down Expand Up @@ -106,4 +116,4 @@ export enum {{classname}}{{enumName}} {
{{/isEnum}}
{{/vars}}

{{/hasEnums}}
{{/hasEnums}}

0 comments on commit 9368bea

Please sign in to comment.