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] Make OpenAPI Generator serialize subclasses properly #102

Merged
merged 2 commits into from
May 28, 2018
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 @@ -47,7 +47,12 @@ class ObjectSerializer {
return expectedType; // the type does not have a discriminator. use it.
} else {
if (data[discriminatorProperty]) {
return data[discriminatorProperty]; // use the type given in the discriminator
var discriminatorType = data[discriminatorProperty];
if(typeMap[discriminatorType]){
return discriminatorType; // use the type given in the discriminator
} else {
return expectedType; // discriminator did not map to a type
}
} else {
return expectedType; // discriminator was not present (or an empty string)
}
Expand Down Expand Up @@ -78,6 +83,9 @@ class ObjectSerializer {
if (!typeMap[type]) { // in case we dont know the type
return data;
}

// Get the actual type of this object
type = this.findCorrectType(data, type);

// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
Expand Down
22 changes: 15 additions & 7 deletions samples/client/petstore/typescript-node/default/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ class ObjectSerializer {
return expectedType; // the type does not have a discriminator. use it.
} else {
if (data[discriminatorProperty]) {
return data[discriminatorProperty]; // use the type given in the discriminator
var discriminatorType = data[discriminatorProperty];
if(typeMap[discriminatorType]){
return discriminatorType; // use the type given in the discriminator
} else {
return expectedType; // discriminator did not map to a type
}
} else {
return expectedType; // discriminator was not present (or an empty string)
}
Expand Down Expand Up @@ -87,6 +92,9 @@ class ObjectSerializer {
if (!typeMap[type]) { // in case we dont know the type
return data;
}

// Get the actual type of this object
type = this.findCorrectType(data, type);

// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
Expand Down Expand Up @@ -144,7 +152,7 @@ export class ApiResponse {
'type'?: string;
'message'?: string;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down Expand Up @@ -175,7 +183,7 @@ export class Category {
'id'?: number;
'name'?: string;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down Expand Up @@ -208,7 +216,7 @@ export class Order {
'status'?: Order.StatusEnum;
'complete'?: boolean;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down Expand Up @@ -268,7 +276,7 @@ export class Pet {
*/
'status'?: Pet.StatusEnum;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down Expand Up @@ -321,7 +329,7 @@ export class Tag {
'id'?: number;
'name'?: string;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down Expand Up @@ -356,7 +364,7 @@ export class User {
*/
'userStatus'?: number;

static discriminator = undefined;
static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
Expand Down