diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelEnum.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelEnum.mustache index 55a39a4ff3de..79c0ee1d59ee 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelEnum.mustache @@ -1,5 +1,9 @@ {{>modelEnumInterfaces}} +export function instanceOf{{classname}}(value: any): boolean { + return Object.values({{classname}}).includes(value); +} + export function {{classname}}FromJSON(json: any): {{classname}} { return {{classname}}FromJSONTyped(json, false); } diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache index 96cac044f519..3b9fefaedf06 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache @@ -24,14 +24,14 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole switch (json['{{discriminator.propertyBaseName}}']) { {{#discriminator.mappedModels}} case '{{mappingName}}': - return {...{{modelName}}FromJSONTyped(json, true), {{discriminator.propertyName}}: '{{mappingName}}'}; + return Object.assign({}, {{modelName}}FromJSONTyped(json, true), { {{discriminator.propertyName}}: '{{mappingName}}' }); {{/discriminator.mappedModels}} default: throw new Error(`No variant of {{classname}} exists with '{{discriminator.propertyName}}=${json['{{discriminator.propertyName}}']}'`); } {{/discriminator}} {{^discriminator}} - return { {{#oneOf}}...{{{.}}}FromJSONTyped(json, true){{^-last}}, {{/-last}}{{/oneOf}} }; + return Object.assign({}, {{#oneOf}}{{{.}}}FromJSONTyped(json, true){{^-last}}, {{/-last}}{{/oneOf}}); {{/discriminator}} } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumClass.ts index c00557690de0..2642db808993 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumClass.ts @@ -25,6 +25,10 @@ export const EnumClass = { export type EnumClass = typeof EnumClass[keyof typeof EnumClass]; +export function instanceOfEnumClass(value: any): boolean { + return Object.values(EnumClass).includes(value); +} + export function EnumClassFromJSON(json: any): EnumClass { return EnumClassFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnum.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnum.ts index 4f6998297086..1e1bb96977f0 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnum.ts @@ -25,6 +25,10 @@ export const OuterEnum = { export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum]; +export function instanceOfOuterEnum(value: any): boolean { + return Object.values(OuterEnum).includes(value); +} + export function OuterEnumFromJSON(json: any): OuterEnum { return OuterEnumFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumDefaultValue.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumDefaultValue.ts index d10e8eeded17..93a84658c1ce 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumDefaultValue.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumDefaultValue.ts @@ -25,6 +25,10 @@ export const OuterEnumDefaultValue = { export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof OuterEnumDefaultValue]; +export function instanceOfOuterEnumDefaultValue(value: any): boolean { + return Object.values(OuterEnumDefaultValue).includes(value); +} + export function OuterEnumDefaultValueFromJSON(json: any): OuterEnumDefaultValue { return OuterEnumDefaultValueFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumInteger.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumInteger.ts index cdedced1d2db..9ca8643211c8 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumInteger.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumInteger.ts @@ -25,6 +25,10 @@ export const OuterEnumInteger = { export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInteger]; +export function instanceOfOuterEnumInteger(value: any): boolean { + return Object.values(OuterEnumInteger).includes(value); +} + export function OuterEnumIntegerFromJSON(json: any): OuterEnumInteger { return OuterEnumIntegerFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumIntegerDefaultValue.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumIntegerDefaultValue.ts index 4fc05d435a2c..7daa71a99ec6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumIntegerDefaultValue.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterEnumIntegerDefaultValue.ts @@ -25,6 +25,10 @@ export const OuterEnumIntegerDefaultValue = { export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[keyof typeof OuterEnumIntegerDefaultValue]; +export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean { + return Object.values(OuterEnumIntegerDefaultValue).includes(value); +} + export function OuterEnumIntegerDefaultValueFromJSON(json: any): OuterEnumIntegerDefaultValue { return OuterEnumIntegerDefaultValueFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SingleRefType.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SingleRefType.ts index 2b76381c67a7..60d49d6f22a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SingleRefType.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SingleRefType.ts @@ -24,6 +24,10 @@ export const SingleRefType = { export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType]; +export function instanceOfSingleRefType(value: any): boolean { + return Object.values(SingleRefType).includes(value); +} + export function SingleRefTypeFromJSON(json: any): SingleRefType { return SingleRefTypeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/NumberEnum.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/NumberEnum.ts index e3d47c556ade..a884536c2ccf 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/NumberEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/NumberEnum.ts @@ -25,6 +25,10 @@ export const NumberEnum = { export type NumberEnum = typeof NumberEnum[keyof typeof NumberEnum]; +export function instanceOfNumberEnum(value: any): boolean { + return Object.values(NumberEnum).includes(value); +} + export function NumberEnumFromJSON(json: any): NumberEnum { return NumberEnumFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/StringEnum.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/StringEnum.ts index 074fdce65877..503619ddd8aa 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/StringEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/StringEnum.ts @@ -25,6 +25,10 @@ export const StringEnum = { export type StringEnum = typeof StringEnum[keyof typeof StringEnum]; +export function instanceOfStringEnum(value: any): boolean { + return Object.values(StringEnum).includes(value); +} + export function StringEnumFromJSON(json: any): StringEnum { return StringEnumFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/BehaviorType.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/BehaviorType.ts index 3a5daedd3e57..b2ce4c035d58 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/BehaviorType.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/BehaviorType.ts @@ -25,6 +25,10 @@ export const BehaviorType = { export type BehaviorType = typeof BehaviorType[keyof typeof BehaviorType]; +export function instanceOfBehaviorType(value: any): boolean { + return Object.values(BehaviorType).includes(value); +} + export function BehaviorTypeFromJSON(json: any): BehaviorType { return BehaviorTypeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DeploymentRequestStatus.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DeploymentRequestStatus.ts index f034ad5bb3f7..ee1f52f20a27 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DeploymentRequestStatus.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DeploymentRequestStatus.ts @@ -34,6 +34,10 @@ export const DeploymentRequestStatus = { export type DeploymentRequestStatus = typeof DeploymentRequestStatus[keyof typeof DeploymentRequestStatus]; +export function instanceOfDeploymentRequestStatus(value: any): boolean { + return Object.values(DeploymentRequestStatus).includes(value); +} + export function DeploymentRequestStatusFromJSON(json: any): DeploymentRequestStatus { return DeploymentRequestStatusFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ErrorCode.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ErrorCode.ts index c5171d088e07..a562973d2684 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ErrorCode.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ErrorCode.ts @@ -40,6 +40,10 @@ export const ErrorCode = { export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode]; +export function instanceOfErrorCode(value: any): boolean { + return Object.values(ErrorCode).includes(value); +} + export function ErrorCodeFromJSON(json: any): ErrorCode { return ErrorCodeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetPartType.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetPartType.ts index a531fb00ffa4..bf2426212c35 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetPartType.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetPartType.ts @@ -25,6 +25,10 @@ export const PetPartType = { export type PetPartType = typeof PetPartType[keyof typeof PetPartType]; +export function instanceOfPetPartType(value: any): boolean { + return Object.values(PetPartType).includes(value); +} + export function PetPartTypeFromJSON(json: any): PetPartType { return PetPartTypeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/WarningCode.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/WarningCode.ts index 8b1030e648a3..8906f49dd92f 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/WarningCode.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/WarningCode.ts @@ -25,6 +25,10 @@ export const WarningCode = { export type WarningCode = typeof WarningCode[keyof typeof WarningCode]; +export function instanceOfWarningCode(value: any): boolean { + return Object.values(WarningCode).includes(value); +} + export function WarningCodeFromJSON(json: any): WarningCode { return WarningCodeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumClass.ts index c00557690de0..2642db808993 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumClass.ts @@ -25,6 +25,10 @@ export const EnumClass = { export type EnumClass = typeof EnumClass[keyof typeof EnumClass]; +export function instanceOfEnumClass(value: any): boolean { + return Object.values(EnumClass).includes(value); +} + export function EnumClassFromJSON(json: any): EnumClass { return EnumClassFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnum.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnum.ts index 4f6998297086..1e1bb96977f0 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnum.ts @@ -25,6 +25,10 @@ export const OuterEnum = { export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum]; +export function instanceOfOuterEnum(value: any): boolean { + return Object.values(OuterEnum).includes(value); +} + export function OuterEnumFromJSON(json: any): OuterEnum { return OuterEnumFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumDefaultValue.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumDefaultValue.ts index d10e8eeded17..93a84658c1ce 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumDefaultValue.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumDefaultValue.ts @@ -25,6 +25,10 @@ export const OuterEnumDefaultValue = { export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof OuterEnumDefaultValue]; +export function instanceOfOuterEnumDefaultValue(value: any): boolean { + return Object.values(OuterEnumDefaultValue).includes(value); +} + export function OuterEnumDefaultValueFromJSON(json: any): OuterEnumDefaultValue { return OuterEnumDefaultValueFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumInteger.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumInteger.ts index cdedced1d2db..9ca8643211c8 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumInteger.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumInteger.ts @@ -25,6 +25,10 @@ export const OuterEnumInteger = { export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInteger]; +export function instanceOfOuterEnumInteger(value: any): boolean { + return Object.values(OuterEnumInteger).includes(value); +} + export function OuterEnumIntegerFromJSON(json: any): OuterEnumInteger { return OuterEnumIntegerFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumIntegerDefaultValue.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumIntegerDefaultValue.ts index 4fc05d435a2c..7daa71a99ec6 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumIntegerDefaultValue.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterEnumIntegerDefaultValue.ts @@ -25,6 +25,10 @@ export const OuterEnumIntegerDefaultValue = { export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[keyof typeof OuterEnumIntegerDefaultValue]; +export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean { + return Object.values(OuterEnumIntegerDefaultValue).includes(value); +} + export function OuterEnumIntegerDefaultValueFromJSON(json: any): OuterEnumIntegerDefaultValue { return OuterEnumIntegerDefaultValueFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SingleRefType.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SingleRefType.ts index 2b76381c67a7..60d49d6f22a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SingleRefType.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SingleRefType.ts @@ -24,6 +24,10 @@ export const SingleRefType = { export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType]; +export function instanceOfSingleRefType(value: any): boolean { + return Object.values(SingleRefType).includes(value); +} + export function SingleRefTypeFromJSON(json: any): SingleRefType { return SingleRefTypeFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/NumberEnum.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/NumberEnum.ts index 04e7eaa4a68f..e65639e50eba 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/NumberEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/NumberEnum.ts @@ -24,6 +24,10 @@ export enum NumberEnum { } +export function instanceOfNumberEnum(value: any): boolean { + return Object.values(NumberEnum).includes(value); +} + export function NumberEnumFromJSON(json: any): NumberEnum { return NumberEnumFromJSONTyped(json, false); } diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/StringEnum.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/StringEnum.ts index 96ce9786594d..d8720fe1fe2b 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/StringEnum.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/StringEnum.ts @@ -24,6 +24,10 @@ export enum StringEnum { } +export function instanceOfStringEnum(value: any): boolean { + return Object.values(StringEnum).includes(value); +} + export function StringEnumFromJSON(json: any): StringEnum { return StringEnumFromJSONTyped(json, false); }