Skip to content

Commit

Permalink
fix: Fix schema generation for oneOf when using TS-FETCH client (Op…
Browse files Browse the repository at this point in the history
…enAPITools#18154)

* fix: Fix schema generation for `oneOf` when using TS-FETCH client

This fixes the following errors:
* Spread types may only be created from object types (on `FromJSONTyped` functions).
* Module '"./BlankEnum"' has no exported member 'instanceOfBlankEnum' (enum templaces don't export function used by other API client files).

* chore: Regenerate samples
  • Loading branch information
giovannicimolin authored Mar 19, 2024
1 parent 191dc1a commit 93b76dd
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 93b76dd

Please sign in to comment.