Skip to content

Commit

Permalink
[typescript-fetch] Restore pre-es2017 compatibility in modelEnum temp…
Browse files Browse the repository at this point in the history
…late (#18418)

* [typescript-fetch] Restore pre-es2017 compatibility in modelEnum template

Restore pre-es2017 compatibility in modelEnum template by not using Object.values in instanceOf{{classname}} function

* [typescript-fetch] Regenerate samples

* [typescript-fetch] Regenerate samples documentation

* [typescript-fetch] Add curly brackets

* [typescript-fetch] Regenerate samples

* [typescript-fetch] Use typed comparison

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>

* [typescript-fetch] Regenerate samples

---------

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>
  • Loading branch information
manuel-covas and macjohnny authored May 5, 2024
1 parent fde8c77 commit 296a6ac
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{{>modelEnumInterfaces}}

export function instanceOf{{classname}}(value: any): boolean {
return Object.values({{classname}}).includes(value);
for (const key in {{classname}}) {
if (Object.prototype.hasOwnProperty.call({{classname}}, key)) {
if ({{classname}}[key] === value) {
return true;
}
}
}
return false;
}

export function {{classname}}FromJSON(json: any): {{classname}} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type EnumClass = typeof EnumClass[keyof typeof EnumClass];


export function instanceOfEnumClass(value: any): boolean {
return Object.values(EnumClass).includes(value);
for (const key in EnumClass) {
if (Object.prototype.hasOwnProperty.call(EnumClass, key)) {
if (EnumClass[key] === value) {
return true;
}
}
}
return false;
}

export function EnumClassFromJSON(json: any): EnumClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum];


export function instanceOfOuterEnum(value: any): boolean {
return Object.values(OuterEnum).includes(value);
for (const key in OuterEnum) {
if (Object.prototype.hasOwnProperty.call(OuterEnum, key)) {
if (OuterEnum[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumFromJSON(json: any): OuterEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof Ou


export function instanceOfOuterEnumDefaultValue(value: any): boolean {
return Object.values(OuterEnumDefaultValue).includes(value);
for (const key in OuterEnumDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumDefaultValue, key)) {
if (OuterEnumDefaultValue[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumDefaultValueFromJSON(json: any): OuterEnumDefaultValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInt


export function instanceOfOuterEnumInteger(value: any): boolean {
return Object.values(OuterEnumInteger).includes(value);
for (const key in OuterEnumInteger) {
if (Object.prototype.hasOwnProperty.call(OuterEnumInteger, key)) {
if (OuterEnumInteger[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumIntegerFromJSON(json: any): OuterEnumInteger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[k


export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean {
return Object.values(OuterEnumIntegerDefaultValue).includes(value);
for (const key in OuterEnumIntegerDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumIntegerDefaultValue, key)) {
if (OuterEnumIntegerDefaultValue[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumIntegerDefaultValueFromJSON(json: any): OuterEnumIntegerDefaultValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType];


export function instanceOfSingleRefType(value: any): boolean {
return Object.values(SingleRefType).includes(value);
for (const key in SingleRefType) {
if (Object.prototype.hasOwnProperty.call(SingleRefType, key)) {
if (SingleRefType[key] === value) {
return true;
}
}
}
return false;
}

export function SingleRefTypeFromJSON(json: any): SingleRefType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type NumberEnum = typeof NumberEnum[keyof typeof NumberEnum];


export function instanceOfNumberEnum(value: any): boolean {
return Object.values(NumberEnum).includes(value);
for (const key in NumberEnum) {
if (Object.prototype.hasOwnProperty.call(NumberEnum, key)) {
if (NumberEnum[key] === value) {
return true;
}
}
}
return false;
}

export function NumberEnumFromJSON(json: any): NumberEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type StringEnum = typeof StringEnum[keyof typeof StringEnum];


export function instanceOfStringEnum(value: any): boolean {
return Object.values(StringEnum).includes(value);
for (const key in StringEnum) {
if (Object.prototype.hasOwnProperty.call(StringEnum, key)) {
if (StringEnum[key] === value) {
return true;
}
}
}
return false;
}

export function StringEnumFromJSON(json: any): StringEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type BehaviorType = typeof BehaviorType[keyof typeof BehaviorType];


export function instanceOfBehaviorType(value: any): boolean {
return Object.values(BehaviorType).includes(value);
for (const key in BehaviorType) {
if (Object.prototype.hasOwnProperty.call(BehaviorType, key)) {
if (BehaviorType[key] === value) {
return true;
}
}
}
return false;
}

export function BehaviorTypeFromJSON(json: any): BehaviorType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export type DeploymentRequestStatus = typeof DeploymentRequestStatus[keyof typeo


export function instanceOfDeploymentRequestStatus(value: any): boolean {
return Object.values(DeploymentRequestStatus).includes(value);
for (const key in DeploymentRequestStatus) {
if (Object.prototype.hasOwnProperty.call(DeploymentRequestStatus, key)) {
if (DeploymentRequestStatus[key] === value) {
return true;
}
}
}
return false;
}

export function DeploymentRequestStatusFromJSON(json: any): DeploymentRequestStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];


export function instanceOfErrorCode(value: any): boolean {
return Object.values(ErrorCode).includes(value);
for (const key in ErrorCode) {
if (Object.prototype.hasOwnProperty.call(ErrorCode, key)) {
if (ErrorCode[key] === value) {
return true;
}
}
}
return false;
}

export function ErrorCodeFromJSON(json: any): ErrorCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type PetPartType = typeof PetPartType[keyof typeof PetPartType];


export function instanceOfPetPartType(value: any): boolean {
return Object.values(PetPartType).includes(value);
for (const key in PetPartType) {
if (Object.prototype.hasOwnProperty.call(PetPartType, key)) {
if (PetPartType[key] === value) {
return true;
}
}
}
return false;
}

export function PetPartTypeFromJSON(json: any): PetPartType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type WarningCode = typeof WarningCode[keyof typeof WarningCode];


export function instanceOfWarningCode(value: any): boolean {
return Object.values(WarningCode).includes(value);
for (const key in WarningCode) {
if (Object.prototype.hasOwnProperty.call(WarningCode, key)) {
if (WarningCode[key] === value) {
return true;
}
}
}
return false;
}

export function WarningCodeFromJSON(json: any): WarningCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type EnumClass = typeof EnumClass[keyof typeof EnumClass];


export function instanceOfEnumClass(value: any): boolean {
return Object.values(EnumClass).includes(value);
for (const key in EnumClass) {
if (Object.prototype.hasOwnProperty.call(EnumClass, key)) {
if (EnumClass[key] === value) {
return true;
}
}
}
return false;
}

export function EnumClassFromJSON(json: any): EnumClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnum = typeof OuterEnum[keyof typeof OuterEnum];


export function instanceOfOuterEnum(value: any): boolean {
return Object.values(OuterEnum).includes(value);
for (const key in OuterEnum) {
if (Object.prototype.hasOwnProperty.call(OuterEnum, key)) {
if (OuterEnum[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumFromJSON(json: any): OuterEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumDefaultValue = typeof OuterEnumDefaultValue[keyof typeof Ou


export function instanceOfOuterEnumDefaultValue(value: any): boolean {
return Object.values(OuterEnumDefaultValue).includes(value);
for (const key in OuterEnumDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumDefaultValue, key)) {
if (OuterEnumDefaultValue[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumDefaultValueFromJSON(json: any): OuterEnumDefaultValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumInteger = typeof OuterEnumInteger[keyof typeof OuterEnumInt


export function instanceOfOuterEnumInteger(value: any): boolean {
return Object.values(OuterEnumInteger).includes(value);
for (const key in OuterEnumInteger) {
if (Object.prototype.hasOwnProperty.call(OuterEnumInteger, key)) {
if (OuterEnumInteger[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumIntegerFromJSON(json: any): OuterEnumInteger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export type OuterEnumIntegerDefaultValue = typeof OuterEnumIntegerDefaultValue[k


export function instanceOfOuterEnumIntegerDefaultValue(value: any): boolean {
return Object.values(OuterEnumIntegerDefaultValue).includes(value);
for (const key in OuterEnumIntegerDefaultValue) {
if (Object.prototype.hasOwnProperty.call(OuterEnumIntegerDefaultValue, key)) {
if (OuterEnumIntegerDefaultValue[key] === value) {
return true;
}
}
}
return false;
}

export function OuterEnumIntegerDefaultValueFromJSON(json: any): OuterEnumIntegerDefaultValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export type SingleRefType = typeof SingleRefType[keyof typeof SingleRefType];


export function instanceOfSingleRefType(value: any): boolean {
return Object.values(SingleRefType).includes(value);
for (const key in SingleRefType) {
if (Object.prototype.hasOwnProperty.call(SingleRefType, key)) {
if (SingleRefType[key] === value) {
return true;
}
}
}
return false;
}

export function SingleRefTypeFromJSON(json: any): SingleRefType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export enum NumberEnum {


export function instanceOfNumberEnum(value: any): boolean {
return Object.values(NumberEnum).includes(value);
for (const key in NumberEnum) {
if (Object.prototype.hasOwnProperty.call(NumberEnum, key)) {
if (NumberEnum[key] === value) {
return true;
}
}
}
return false;
}

export function NumberEnumFromJSON(json: any): NumberEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export enum StringEnum {


export function instanceOfStringEnum(value: any): boolean {
return Object.values(StringEnum).includes(value);
for (const key in StringEnum) {
if (Object.prototype.hasOwnProperty.call(StringEnum, key)) {
if (StringEnum[key] === value) {
return true;
}
}
}
return false;
}

export function StringEnumFromJSON(json: any): StringEnum {
Expand Down

0 comments on commit 296a6ac

Please sign in to comment.