Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS][Fetch] Add support for openapi maps/dictionaries to be generated as typescript map #2913

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
{{#hasImports}}
import {
{{#imports}}
Expand Down Expand Up @@ -46,17 +46,22 @@ export function {{classname}}FromJSON(json: any): {{classname}} {
{{/isDate}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isContainer}}
{{#isListContainer}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}(json['{{baseName}}'] as Array<any>).map({{#items}}{{datatype}}{{/items}}FromJSON),
{{/isContainer}}
{{^isContainer}}
{{/isListContainer}}
{{#isMapContainer}}
'{{name}}': {{^required}}!exists(json, '{{baseName}}') ? undefined : {{/required}}mapValues(json['{{baseName}}'], {{#items}}{{datatype}}{{/items}}FromJSON),
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^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}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{/allVars}}
};
Expand All @@ -78,17 +83,22 @@ export function {{classname}}ToJSON(value?: {{classname}}): any {
'{{baseName}}': {{#isDate}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}value.{{name}}.toISOString().substr(0,10){{/isDate}}{{#isDateTime}}{{^required}}value.{{name}} === undefined ? undefined : {{/required}}value.{{name}}.toISOString(){{/isDateTime}}{{^isDate}}{{^isDateTime}}value.{{name}}{{/isDateTime}}{{/isDate}},
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isContainer}}
{{#isListContainer}}
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}(value.{{name}} as Array<any>).map({{#items}}{{datatype}}{{/items}}ToJSON),
{{/isContainer}}
{{^isContainer}}
{{/isListContainer}}
{{#isMapContainer}}
'{{baseName}}': {{^required}}value.{{name}} === undefined ? undefined : {{/required}}mapValues(value.{{name}}, {{#items}}{{datatype}}{{/items}}ToJSON),
{{/isMapContainer}}
{{^isListContainer}}
{{^isMapContainer}}
{{^isFreeFormObject}}
'{{baseName}}': {{datatype}}ToJSON(value.{{name}}),
{{/isFreeFormObject}}
{{#isFreeFormObject}}
'{{baseName}}': value.{{name}},
{{/isFreeFormObject}}
{{/isContainer}}
{{/isMapContainer}}
{{/isListContainer}}
{{/isPrimitiveType}}
{{/isReadOnly}}
{{/allVars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ export function querystring(params: HTTPQuery, prefix: string = ''): string {
.join('&');
}

export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce(
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
{}
);
}

export interface RequestContext {
fetch: FetchAPI;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A category for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* Describes the result of uploading an image resource
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* An order for a pets from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A tag for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A User who is purchasing from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ export function querystring(params: HTTPQuery, prefix: string = ''): string {
.join('&');
}

export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce(
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
{}
);
}

export interface RequestContext {
fetch: FetchAPI;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A category for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* Describes the result of uploading an image resource
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* An order for a pets from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A tag for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A User who is purchasing from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ export function querystring(params: HTTPQuery, prefix: string = ''): string {
.join('&');
}

export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce(
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
{}
);
}

export interface RequestContext {
fetch: FetchAPI;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A category for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* Describes the result of uploading an image resource
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* An order for a pets from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A tag for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A User who is purchasing from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ export function querystring(params: HTTPQuery, prefix: string = ''): string {
.join('&');
}

export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce(
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
{}
);
}

export interface RequestContext {
fetch: FetchAPI;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A category for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* Describes the result of uploading an image resource
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* An order for a pets from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A tag for a pet
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Do not edit the class manually.
*/

import { exists } from '../runtime';
import { exists, mapValues } from '../runtime';
/**
* A User who is purchasing from the pet store
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ export function querystring(params: HTTPQuery, prefix: string = ''): string {
.join('&');
}

export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce(
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
{}
);
}

export interface RequestContext {
fetch: FetchAPI;
url: string;
Expand Down