forked from loafle/openapi-generator-original
[TypeScript] Make OpenAPI Generator serialize subclasses properly (#102)
* Make SwaggerCodeGen serialize subclasses properly (PHNX-859) (#1) Motivation ---- Previously, when serializing as subclass of a property, generated swagger clients would only serialize properties of the parent class causing some values to not be pass through Modifications ---- Before serializing attributes of a given type, we check to see if there is a specific type to be serialized so that we don't miss any properties. * Fix improper whitespace in mustache template (PHNX-859) (#2) Motivation ---- OpenAPI Generator upstream requested whitespace fixes (from tabs to 4 spaces) Modifications ---- Fixed whitespace
This commit is contained in:
parent
71b5de3ed5
commit
9b8602311e
@ -47,7 +47,12 @@ class ObjectSerializer {
|
|||||||
return expectedType; // the type does not have a discriminator. use it.
|
return expectedType; // the type does not have a discriminator. use it.
|
||||||
} else {
|
} else {
|
||||||
if (data[discriminatorProperty]) {
|
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 {
|
} else {
|
||||||
return expectedType; // discriminator was not present (or an empty string)
|
return expectedType; // discriminator was not present (or an empty string)
|
||||||
}
|
}
|
||||||
@ -78,6 +83,9 @@ class ObjectSerializer {
|
|||||||
if (!typeMap[type]) { // in case we dont know the type
|
if (!typeMap[type]) { // in case we dont know the type
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the actual type of this object
|
||||||
|
type = this.findCorrectType(data, type);
|
||||||
|
|
||||||
// get the map for the correct type.
|
// get the map for the correct type.
|
||||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||||
|
@ -56,7 +56,12 @@ class ObjectSerializer {
|
|||||||
return expectedType; // the type does not have a discriminator. use it.
|
return expectedType; // the type does not have a discriminator. use it.
|
||||||
} else {
|
} else {
|
||||||
if (data[discriminatorProperty]) {
|
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 {
|
} else {
|
||||||
return expectedType; // discriminator was not present (or an empty string)
|
return expectedType; // discriminator was not present (or an empty string)
|
||||||
}
|
}
|
||||||
@ -87,6 +92,9 @@ class ObjectSerializer {
|
|||||||
if (!typeMap[type]) { // in case we dont know the type
|
if (!typeMap[type]) { // in case we dont know the type
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the actual type of this object
|
||||||
|
type = this.findCorrectType(data, type);
|
||||||
|
|
||||||
// get the map for the correct type.
|
// get the map for the correct type.
|
||||||
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
let attributeTypes = typeMap[type].getAttributeTypeMap();
|
||||||
@ -144,7 +152,7 @@ export class ApiResponse {
|
|||||||
'type'?: string;
|
'type'?: string;
|
||||||
'message'?: string;
|
'message'?: string;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
@ -175,7 +183,7 @@ export class Category {
|
|||||||
'id'?: number;
|
'id'?: number;
|
||||||
'name'?: string;
|
'name'?: string;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
@ -208,7 +216,7 @@ export class Order {
|
|||||||
'status'?: Order.StatusEnum;
|
'status'?: Order.StatusEnum;
|
||||||
'complete'?: boolean;
|
'complete'?: boolean;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
@ -268,7 +276,7 @@ export class Pet {
|
|||||||
*/
|
*/
|
||||||
'status'?: Pet.StatusEnum;
|
'status'?: Pet.StatusEnum;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
@ -321,7 +329,7 @@ export class Tag {
|
|||||||
'id'?: number;
|
'id'?: number;
|
||||||
'name'?: string;
|
'name'?: string;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
@ -356,7 +364,7 @@ export class User {
|
|||||||
*/
|
*/
|
||||||
'userStatus'?: number;
|
'userStatus'?: number;
|
||||||
|
|
||||||
static discriminator = undefined;
|
static discriminator: string | undefined = undefined;
|
||||||
|
|
||||||
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user