|
| 1 | +//---------------------- |
| 2 | +// <auto-generated> |
| 3 | +// </auto-generated> |
| 4 | +//---------------------- |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +export abstract class Base implements IBase { |
| 13 | + |
| 14 | + protected _discriminator: string; |
| 15 | + |
| 16 | + constructor(data?: IBase) { |
| 17 | + if (data) { |
| 18 | + for (var property in data) { |
| 19 | + if (data.hasOwnProperty(property)) |
| 20 | + (<any>this)[property] = (<any>data)[property]; |
| 21 | + } |
| 22 | + } |
| 23 | + this._discriminator = "Base"; |
| 24 | + } |
| 25 | + |
| 26 | + init(_data?: any) { |
| 27 | + } |
| 28 | + |
| 29 | + static fromJS(data: any): Base { |
| 30 | + data = typeof data === 'object' ? data : {}; |
| 31 | + if (data["Type"] === "OneChild") { |
| 32 | + let result = new OneChild(); |
| 33 | + result.init(data); |
| 34 | + return result; |
| 35 | + } |
| 36 | + if (data["Type"] === "SecondChild") { |
| 37 | + let result = new SecondChild(); |
| 38 | + result.init(data); |
| 39 | + return result; |
| 40 | + } |
| 41 | + throw new Error("The abstract class 'Base' cannot be instantiated."); |
| 42 | + } |
| 43 | + |
| 44 | + toJSON(data?: any) { |
| 45 | + data = typeof data === 'object' ? data : {}; |
| 46 | + data["Type"] = this._discriminator; |
| 47 | + return data; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +export interface IBase { |
| 52 | +} |
| 53 | + |
| 54 | +export class OneChild extends Base implements IOneChild { |
| 55 | + a: string; |
| 56 | + type: EBase; |
| 57 | + |
| 58 | + constructor(data?: IOneChild) { |
| 59 | + super(data); |
| 60 | + this._discriminator = "OneChild"; |
| 61 | + } |
| 62 | + |
| 63 | + init(_data?: any) { |
| 64 | + super.init(_data); |
| 65 | + if (_data) { |
| 66 | + this.a = _data["A"]; |
| 67 | + this.type = _data["Type"]; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + static fromJS(data: any): OneChild { |
| 72 | + data = typeof data === 'object' ? data : {}; |
| 73 | + let result = new OneChild(); |
| 74 | + result.init(data); |
| 75 | + return result; |
| 76 | + } |
| 77 | + |
| 78 | + toJSON(data?: any) { |
| 79 | + data = typeof data === 'object' ? data : {}; |
| 80 | + data["A"] = this.a; |
| 81 | + data["Type"] = this.type; |
| 82 | + super.toJSON(data); |
| 83 | + return data; |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +export interface IOneChild extends IBase { |
| 88 | + a: string; |
| 89 | + type: EBase; |
| 90 | +} |
| 91 | + |
| 92 | +export enum EBase { |
| 93 | + OneChild = "OneChild", |
| 94 | + SecondChild = "SecondChild", |
| 95 | +} |
| 96 | + |
| 97 | +export class SecondChild extends Base implements ISecondChild { |
| 98 | + b: string; |
| 99 | + type: EBase; |
| 100 | + |
| 101 | + constructor(data?: ISecondChild) { |
| 102 | + super(data); |
| 103 | + this._discriminator = "SecondChild"; |
| 104 | + } |
| 105 | + |
| 106 | + init(_data?: any) { |
| 107 | + super.init(_data); |
| 108 | + if (_data) { |
| 109 | + this.b = _data["B"]; |
| 110 | + this.type = _data["Type"]; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + static fromJS(data: any): SecondChild { |
| 115 | + data = typeof data === 'object' ? data : {}; |
| 116 | + let result = new SecondChild(); |
| 117 | + result.init(data); |
| 118 | + return result; |
| 119 | + } |
| 120 | + |
| 121 | + toJSON(data?: any) { |
| 122 | + data = typeof data === 'object' ? data : {}; |
| 123 | + data["B"] = this.b; |
| 124 | + data["Type"] = this.type; |
| 125 | + super.toJSON(data); |
| 126 | + return data; |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +export interface ISecondChild extends IBase { |
| 131 | + b: string; |
| 132 | + type: EBase; |
| 133 | +} |
| 134 | + |
| 135 | +export class MyClass implements IMyClass { |
| 136 | + child: OneChild | SecondChild; |
| 137 | + children: (OneChild | SecondChild)[]; |
| 138 | + |
| 139 | + constructor(data?: IMyClass) { |
| 140 | + if (data) { |
| 141 | + for (var property in data) { |
| 142 | + if (data.hasOwnProperty(property)) |
| 143 | + (<any>this)[property] = (<any>data)[property]; |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + init(_data?: any) { |
| 149 | + if (_data) { |
| 150 | + this.child = _data["Child"] ? OneChild | SecondChild.fromJS(_data["Child"]) : <any>undefined; |
| 151 | + if (Array.isArray(_data["Children"])) { |
| 152 | + this.children = [] as any; |
| 153 | + for (let item of _data["Children"]) |
| 154 | + this.children.push(OneChild | SecondChild.fromJS(item)); |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + static fromJS(data: any): MyClass { |
| 160 | + data = typeof data === 'object' ? data : {}; |
| 161 | + let result = new MyClass(); |
| 162 | + result.init(data); |
| 163 | + return result; |
| 164 | + } |
| 165 | + |
| 166 | + toJSON(data?: any) { |
| 167 | + data = typeof data === 'object' ? data : {}; |
| 168 | + data["Child"] = this.child ? this.child.toJSON() : <any>undefined; |
| 169 | + if (Array.isArray(this.children)) { |
| 170 | + data["Children"] = []; |
| 171 | + for (let item of this.children) |
| 172 | + data["Children"].push(item.toJSON()); |
| 173 | + } |
| 174 | + return data; |
| 175 | + } |
| 176 | +} |
| 177 | + |
| 178 | +export interface IMyClass { |
| 179 | + child: OneChild | SecondChild; |
| 180 | + children: (OneChild | SecondChild)[]; |
| 181 | +} |
0 commit comments