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

[typescript-fetch] fix serialization/deserialization with inheritance #3767

Merged
merged 4 commits into from
Aug 28, 2019
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
Expand Up @@ -12,6 +12,10 @@ export enum {{classname}} {
}

export function {{classname}}FromJSON(json: any): {{classname}} {
return {{classname}}FromJSONTyped(json, false);
}

export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boolean): {{classname}} {
return json as {{classname}};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import {
{{#imports}}
{{{.}}},
{{.}}FromJSON,
{{.}}FromJSONTyped,
{{.}}ToJSON,
{{/imports}}
} from './';

{{/hasImports}}
{{#discriminator}}
import {
{{#discriminator.mappedModels}}
{{modelName}}FromJSONTyped
{{/discriminator.mappedModels}}
} from './';

{{/discriminator}}
/**
* {{{description}}}
* @export
Expand All @@ -29,8 +38,25 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
}

export function {{classname}}FromJSON(json: any): {{classname}} {
return {{classname}}FromJSONTyped(json, false);
}

export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boolean): {{classname}} {
{{#hasVars}}
if ((json === undefined) || (json === null)) {
return json;
}
{{#discriminator}}
if (!ignoreDiscriminator) {
{{#discriminator.mappedModels}}
if (json['{{discriminator.propertyName}}'] === '{{modelName}}') {
return {{modelName}}FromJSONTyped(json, true);
}
{{/discriminator.mappedModels}}
}
{{/discriminator}}
return {
{{#parent}}...{{{parent}}}FromJSONTyped(json, ignoreDiscriminator),{{/parent}}
{{#additionalPropertiesType}}
...json,
{{/additionalPropertiesType}}
Expand Down Expand Up @@ -79,7 +105,11 @@ export function {{classname}}ToJSON(value?: {{classname}}): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
{{#parent}}...{{{parent}}}ToJSON(value),{{/parent}}
{{#additionalPropertiesType}}
...value,
{{/additionalPropertiesType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ export interface Category {
}

export function CategoryFromJSON(json: any): Category {
return CategoryFromJSONTyped(json, false);
}

export function CategoryFromJSONTyped(json: any, ignoreDiscriminator: boolean): Category {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'name': !exists(json, 'name') ? undefined : json['name'],
};
Expand All @@ -43,7 +51,11 @@ export function CategoryToJSON(value?: Category): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'name': value.name,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ export interface ModelApiResponse {
}

export function ModelApiResponseFromJSON(json: any): ModelApiResponse {
return ModelApiResponseFromJSONTyped(json, false);
}

export function ModelApiResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): ModelApiResponse {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'code': !exists(json, 'code') ? undefined : json['code'],
'type': !exists(json, 'type') ? undefined : json['type'],
'message': !exists(json, 'message') ? undefined : json['message'],
Expand All @@ -50,7 +58,11 @@ export function ModelApiResponseToJSON(value?: ModelApiResponse): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'code': value.code,
'type': value.type,
'message': value.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ export interface Order {
}

export function OrderFromJSON(json: any): Order {
return OrderFromJSONTyped(json, false);
}

export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Order {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'petId': !exists(json, 'petId') ? undefined : json['petId'],
'quantity': !exists(json, 'quantity') ? undefined : json['quantity'],
Expand All @@ -71,7 +79,11 @@ export function OrderToJSON(value?: Order): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'petId': value.petId,
'quantity': value.quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
CategoryFromJSONTyped,
CategoryToJSON,
Tag,
TagFromJSON,
TagFromJSONTyped,
TagToJSON,
} from './';

Expand Down Expand Up @@ -66,7 +68,15 @@ export interface Pet {
}

export function PetFromJSON(json: any): Pet {
return PetFromJSONTyped(json, false);
}

export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'category': !exists(json, 'category') ? undefined : CategoryFromJSON(json['category']),
'name': json['name'],
Expand All @@ -80,7 +90,11 @@ export function PetToJSON(value?: Pet): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'category': CategoryToJSON(value.category),
'name': value.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ export interface Tag {
}

export function TagFromJSON(json: any): Tag {
return TagFromJSONTyped(json, false);
}

export function TagFromJSONTyped(json: any, ignoreDiscriminator: boolean): Tag {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'name': !exists(json, 'name') ? undefined : json['name'],
};
Expand All @@ -43,7 +51,11 @@ export function TagToJSON(value?: Tag): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'name': value.name,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ export interface User {
}

export function UserFromJSON(json: any): User {
return UserFromJSONTyped(json, false);
}

export function UserFromJSONTyped(json: any, ignoreDiscriminator: boolean): User {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'username': !exists(json, 'username') ? undefined : json['username'],
'firstName': !exists(json, 'firstName') ? undefined : json['firstName'],
Expand All @@ -85,7 +93,11 @@ export function UserToJSON(value?: User): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'username': value.username,
'firstName': value.firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ export interface Category {
}

export function CategoryFromJSON(json: any): Category {
return CategoryFromJSONTyped(json, false);
}

export function CategoryFromJSONTyped(json: any, ignoreDiscriminator: boolean): Category {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'name': !exists(json, 'name') ? undefined : json['name'],
};
Expand All @@ -43,7 +51,11 @@ export function CategoryToJSON(value?: Category): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'name': value.name,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ export interface ModelApiResponse {
}

export function ModelApiResponseFromJSON(json: any): ModelApiResponse {
return ModelApiResponseFromJSONTyped(json, false);
}

export function ModelApiResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): ModelApiResponse {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'code': !exists(json, 'code') ? undefined : json['code'],
'type': !exists(json, 'type') ? undefined : json['type'],
'message': !exists(json, 'message') ? undefined : json['message'],
Expand All @@ -50,7 +58,11 @@ export function ModelApiResponseToJSON(value?: ModelApiResponse): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'code': value.code,
'type': value.type,
'message': value.message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ export interface Order {
}

export function OrderFromJSON(json: any): Order {
return OrderFromJSONTyped(json, false);
}

export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Order {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'petId': !exists(json, 'petId') ? undefined : json['petId'],
'quantity': !exists(json, 'quantity') ? undefined : json['quantity'],
Expand All @@ -71,7 +79,11 @@ export function OrderToJSON(value?: Order): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'petId': value.petId,
'quantity': value.quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { exists, mapValues } from '../runtime';
import {
Category,
CategoryFromJSON,
CategoryFromJSONTyped,
CategoryToJSON,
Tag,
TagFromJSON,
TagFromJSONTyped,
TagToJSON,
} from './';

Expand Down Expand Up @@ -66,7 +68,15 @@ export interface Pet {
}

export function PetFromJSON(json: any): Pet {
return PetFromJSONTyped(json, false);
}

export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet {
if ((json === undefined) || (json === null)) {
return json;
}
return {

'id': !exists(json, 'id') ? undefined : json['id'],
'category': !exists(json, 'category') ? undefined : CategoryFromJSON(json['category']),
'name': json['name'],
Expand All @@ -80,7 +90,11 @@ export function PetToJSON(value?: Pet): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {

'id': value.id,
'category': CategoryToJSON(value.category),
'name': value.name,
Expand Down
Loading