Skip to content

Instantly share code, notes, and snippets.

@klinki
Last active February 1, 2023 23:54
Show Gist options
  • Save klinki/620bbff207890b93bcd3ed17d7f533c6 to your computer and use it in GitHub Desktop.
Save klinki/620bbff207890b93bcd3ed17d7f533c6 to your computer and use it in GitHub Desktop.
OpenApi TS Inheritance Generator Bug
/* tslint:disable */
/* eslint-disable */
/**
* OpenApiBug
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
import type { Vehicle } from './Vehicle';
import {
VehicleFromJSON,
VehicleFromJSONTyped,
VehicleToJSON,
} from './Vehicle';
/**
*
* @export
* @interface Boat
*/
export interface Boat extends Vehicle {
/**
*
* @type {number}
* @memberof Boat
*/
speedKnotsPerHour?: number;
/**
*
* @type {number}
* @memberof Boat
*/
draft?: number;
/**
*
* @type {string}
* @memberof Boat
*/
readonly type?: string | null;
}
/**
* Check if a given object implements the Boat interface.
*/
export function instanceOfBoat(value: object): boolean {
let isInstance = true;
return isInstance;
}
export function BoatFromJSON(json: any): Boat {
return BoatFromJSONTyped(json, false);
}
export function BoatFromJSONTyped(json: any, ignoreDiscriminator: boolean): Boat {
if ((json === undefined) || (json === null)) {
return json;
}
return {
...VehicleFromJSONTyped(json, ignoreDiscriminator),
'speedKnotsPerHour': !exists(json, 'speedKnotsPerHour') ? undefined : json['speedKnotsPerHour'],
'draft': !exists(json, 'draft') ? undefined : json['draft'],
'type': !exists(json, 'type') ? undefined : json['type'],
};
}
export function BoatToJSON(value?: Boat | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
...VehicleToJSON(value),
'speedKnotsPerHour': value.speedKnotsPerHour,
'draft': value.draft,
};
}
/* tslint:disable */
/* eslint-disable */
/**
* OpenApiBug
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
import type { Vehicle } from './Vehicle';
import {
VehicleFromJSON,
VehicleFromJSONTyped,
VehicleToJSON,
} from './Vehicle';
/**
*
* @export
* @interface Car
*/
export interface Car extends Vehicle {
/**
*
* @type {number}
* @memberof Car
*/
speedKilometersPerHour?: number;
/**
*
* @type {string}
* @memberof Car
*/
readonly type?: string | null;
}
/**
* Check if a given object implements the Car interface.
*/
export function instanceOfCar(value: object): boolean {
let isInstance = true;
return isInstance;
}
export function CarFromJSON(json: any): Car {
return CarFromJSONTyped(json, false);
}
export function CarFromJSONTyped(json: any, ignoreDiscriminator: boolean): Car {
if ((json === undefined) || (json === null)) {
return json;
}
return {
...VehicleFromJSONTyped(json, ignoreDiscriminator),
'speedKilometersPerHour': !exists(json, 'speedKilometersPerHour') ? undefined : json['speedKilometersPerHour'],
'type': !exists(json, 'type') ? undefined : json['type'],
};
}
export function CarToJSON(value?: Car | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
...VehicleToJSON(value),
'speedKilometersPerHour': value.speedKilometersPerHour,
};
}
/* tslint:disable */
/* eslint-disable */
/**
* OpenApiBug
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import {
Boat,
instanceOfBoat,
BoatFromJSON,
BoatFromJSONTyped,
BoatToJSON,
} from './Boat';
import {
Car,
instanceOfCar,
CarFromJSON,
CarFromJSONTyped,
CarToJSON,
} from './Car';
/**
* @type GetVehicles200ResponseInner
*
* @export
*/
export type GetVehicles200ResponseInner = Boat | Car;
export function GetVehicles200ResponseInnerFromJSON(json: any): GetVehicles200ResponseInner {
return GetVehicles200ResponseInnerFromJSONTyped(json, false);
}
export function GetVehicles200ResponseInnerFromJSONTyped(json: any, ignoreDiscriminator: boolean): GetVehicles200ResponseInner {
if ((json === undefined) || (json === null)) {
return json;
}
return { ...BoatFromJSONTyped(json, true), ...CarFromJSONTyped(json, true) };
}
export function GetVehicles200ResponseInnerToJSON(value?: GetVehicles200ResponseInner | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
if (instanceOfBoat(value)) {
return BoatToJSON(value as Boat);
}
if (instanceOfCar(value)) {
return CarToJSON(value as Car);
}
return {};
}
{
"openapi": "3.0.1",
"info": {
"title": "OpenApiBug",
"version": "1.0"
},
"paths": {
"/vehicles": {
"get": {
"tags": [
"OpenApiBug"
],
"operationId": "GetVehicles",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/Car"
},
{
"$ref": "#/components/schemas/Boat"
}
]
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Boat": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Vehicle"
}
],
"properties": {
"speedKnotsPerHour": {
"type": "number",
"format": "double"
},
"draft": {
"type": "number",
"format": "double"
},
"type": {
"type": "string",
"nullable": true,
"readOnly": true
}
},
"additionalProperties": false
},
"Car": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Vehicle"
}
],
"properties": {
"speedKilometersPerHour": {
"type": "number",
"format": "double"
},
"type": {
"type": "string",
"nullable": true,
"readOnly": true
}
},
"additionalProperties": false
},
"Vehicle": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string",
"nullable": true,
"readOnly": true
},
"id": {
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "type",
"mapping": {
"car": "#/components/schemas/Car",
"boat": "#/components/schemas/Boat"
}
}
}
}
}
}
/* tslint:disable */
/* eslint-disable */
/**
* OpenApiBug
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
import {
BoatFromJSONTyped,
CarFromJSONTyped
} from './';
/**
*
* @export
* @interface Vehicle
*/
export interface Vehicle {
/**
*
* @type {string}
* @memberof Vehicle
*/
readonly type: string | null;
/**
*
* @type {number}
* @memberof Vehicle
*/
id?: number;
}
/**
* Check if a given object implements the Vehicle interface.
*/
export function instanceOfVehicle(value: object): boolean {
let isInstance = true;
isInstance = isInstance && "type" in value;
return isInstance;
}
export function VehicleFromJSON(json: any): Vehicle {
return VehicleFromJSONTyped(json, false);
}
export function VehicleFromJSONTyped(json: any, ignoreDiscriminator: boolean): Vehicle {
if ((json === undefined) || (json === null)) {
return json;
}
if (!ignoreDiscriminator) {
if (json['type'] === 'boat') {
return BoatFromJSONTyped(json, true);
}
if (json['type'] === 'car') {
return CarFromJSONTyped(json, true);
}
}
return {
'type': json['type'],
'id': !exists(json, 'id') ? undefined : json['id'],
};
}
export function VehicleToJSON(value?: Vehicle | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
'id': value.id,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment