diff --git a/sdk-generation-log/foreignexchange.json b/sdk-generation-log/foreignexchange.json new file mode 100644 index 000000000..ed06ae9ca --- /dev/null +++ b/sdk-generation-log/foreignexchange.json @@ -0,0 +1,8 @@ +{ + "service": "foreignexchange", + "project": "node", + "generatedAt": "2026-10-01T14:42:10Z", + "openapiCommitSha": "45520ee6246d7e3d8074c3c5c5e991e65c2c02d6", + "automationCommitSha": "5d96c9a6b53a7052671a48c3ab6eb109bec1550b", + "libraryCommitSha": "457353822a6b1e7afe1e06a10eff5508005bc8dd" +} diff --git a/src/services/foreignExchange/index.ts b/src/services/foreignExchange/index.ts new file mode 100644 index 000000000..bd5e6ba11 --- /dev/null +++ b/src/services/foreignExchange/index.ts @@ -0,0 +1,24 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { RatesApi } from "./ratesApi"; + +import Service from "../../service"; +import Client from "../../client"; + +export default class ForeignExchangeAPI extends Service { + + public constructor(client: Client) { + super(client); + } + + public get RatesApi() { + return new RatesApi(this.client); + } +} diff --git a/src/services/foreignExchange/ratesApi.ts b/src/services/foreignExchange/ratesApi.ts new file mode 100644 index 000000000..c769d70ce --- /dev/null +++ b/src/services/foreignExchange/ratesApi.ts @@ -0,0 +1,53 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import getJsonResponse from "../../helpers/getJsonResponse"; +import Service from "../../service"; +import Client from "../../client"; +import { IRequest } from "../../typings/requestOptions"; +import Resource from "../resource"; + +import { ObjectSerializer } from "../../typings/foreignExchange/objectSerializer"; +import { CalculateRateRequest } from "../../typings/foreignExchange/models"; +import { CalculateRateResponse } from "../../typings/foreignExchange/models"; + +/** + * API handler for RatesApi + */ +export class RatesApi extends Service { + + private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/fx/api/v1"; + private baseUrl: string; + + public constructor(client: Client){ + super(client); + this.baseUrl = this.createBaseUrl(this.API_BASEPATH); + } + + /** + * @summary Calculate amount in a different currency + * @param calculateRateRequest {@link CalculateRateRequest } + * @param requestOptions {@link IRequest.Options } + * @return {@link CalculateRateResponse } + */ + public async calculate(calculateRateRequest: CalculateRateRequest, requestOptions?: IRequest.Options): Promise { + const endpoint = `${this.baseUrl}/rates/calculate`; + const resource = new Resource(this, endpoint); + + const request: CalculateRateRequest = ObjectSerializer.serialize(calculateRateRequest, "CalculateRateRequest"); + const response = await getJsonResponse( + resource, + request, + { ...requestOptions, method: "POST" } + ); + + return ObjectSerializer.deserialize(response, "CalculateRateResponse"); + } + +} diff --git a/src/typings/foreignExchange/amount.ts b/src/typings/foreignExchange/amount.ts new file mode 100644 index 000000000..4e1aea8a5 --- /dev/null +++ b/src/typings/foreignExchange/amount.ts @@ -0,0 +1,46 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + + +export class Amount { + /** + * The three-character [ISO currency code](https://docs.adyen.com/development-resources/currency-codes#currency-codes). + */ + "currency": string; + /** + * The amount of the transaction, in [minor units](https://docs.adyen.com/development-resources/currency-codes#minor-units). + */ + "value": number; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "currency", + "baseName": "currency", + "type": "string", + "format": "" + }, + { + "name": "value", + "baseName": "value", + "type": "number", + "format": "int64" + } ]; + + static getAttributeTypeMap() { + return Amount.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/calculateRateRequest.ts b/src/typings/foreignExchange/calculateRateRequest.ts new file mode 100644 index 000000000..dc1df2b52 --- /dev/null +++ b/src/typings/foreignExchange/calculateRateRequest.ts @@ -0,0 +1,42 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { CalculateRateRequestItem } from "./calculateRateRequestItem"; + +/** +* The request to calculate an amount in a different currency. +*/ + + +export class CalculateRateRequest { + /** + * An array of objects, where each object defines a currency and value for which you want to perform an exchange calculation. + */ + "exchangeCalculations": Array; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "exchangeCalculations", + "baseName": "exchangeCalculations", + "type": "Array", + "format": "" + } ]; + + static getAttributeTypeMap() { + return CalculateRateRequest.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/calculateRateRequestItem.ts b/src/typings/foreignExchange/calculateRateRequestItem.ts new file mode 100644 index 000000000..c9d2e551a --- /dev/null +++ b/src/typings/foreignExchange/calculateRateRequestItem.ts @@ -0,0 +1,67 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { Amount } from "./amount"; +import { ExchangeSide } from "./exchangeSide"; +import { RateType } from "./rateType"; + +/** +* The request parameters required to calculate an amount in a different currency. +*/ + + +export class CalculateRateRequestItem { + "exchangeSide": ExchangeSide; + "sourceAmount": Amount; + /** + * The currency to which you want to convert the source amount. + */ + "targetCurrency": string; + "type": RateType; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "exchangeSide", + "baseName": "exchangeSide", + "type": "ExchangeSide", + "format": "" + }, + { + "name": "sourceAmount", + "baseName": "sourceAmount", + "type": "Amount", + "format": "" + }, + { + "name": "targetCurrency", + "baseName": "targetCurrency", + "type": "string", + "format": "" + }, + { + "name": "type", + "baseName": "type", + "type": "RateType", + "format": "" + } ]; + + static getAttributeTypeMap() { + return CalculateRateRequestItem.attributeTypeMap; + } + + public constructor() { + } +} + +export namespace CalculateRateRequestItem { +} diff --git a/src/typings/foreignExchange/calculateRateResponse.ts b/src/typings/foreignExchange/calculateRateResponse.ts new file mode 100644 index 000000000..a651c1cba --- /dev/null +++ b/src/typings/foreignExchange/calculateRateResponse.ts @@ -0,0 +1,42 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { CalculateRateResponseItem } from "./calculateRateResponseItem"; + +/** +* The response returned when you calculate an amount in a different currency. +*/ + + +export class CalculateRateResponse { + /** + * An array of objects, where each object returns a currency and value for which you performed an exchange calculation. You can use the calculated amounts in your payment requests. + */ + "exchangeCalculations"?: Array; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "exchangeCalculations", + "baseName": "exchangeCalculations", + "type": "Array", + "format": "" + } ]; + + static getAttributeTypeMap() { + return CalculateRateResponse.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/calculateRateResponseItem.ts b/src/typings/foreignExchange/calculateRateResponseItem.ts new file mode 100644 index 000000000..4069122f4 --- /dev/null +++ b/src/typings/foreignExchange/calculateRateResponseItem.ts @@ -0,0 +1,76 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { Amount } from "./amount"; + +/** +* The response parameters returned when you calculate an amount in a different currency. +*/ + + +export class CalculateRateResponseItem { + /** + * The exchange rate to convert the source currency to the target currency. This includes Adyen\'s markup. + */ + "appliedExchangeRate"?: number; + /** + * The operation performed on the source amount. Possible values: * **buy** * **sell** + */ + "exchangeSide"?: string; + "sourceAmount"?: Amount | null; + "targetAmount"?: Amount | null; + /** + * The type of transaction. Possible values: * **splitPayment**: for payments * **splitRefund**: for refunds + */ + "type"?: string; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "appliedExchangeRate", + "baseName": "appliedExchangeRate", + "type": "number", + "format": "" + }, + { + "name": "exchangeSide", + "baseName": "exchangeSide", + "type": "string", + "format": "" + }, + { + "name": "sourceAmount", + "baseName": "sourceAmount", + "type": "Amount | null", + "format": "" + }, + { + "name": "targetAmount", + "baseName": "targetAmount", + "type": "Amount | null", + "format": "" + }, + { + "name": "type", + "baseName": "type", + "type": "string", + "format": "" + } ]; + + static getAttributeTypeMap() { + return CalculateRateResponseItem.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/defaultErrorResponseEntity.ts b/src/typings/foreignExchange/defaultErrorResponseEntity.ts new file mode 100644 index 000000000..ec4bf859a --- /dev/null +++ b/src/typings/foreignExchange/defaultErrorResponseEntity.ts @@ -0,0 +1,112 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +import { InvalidField } from "./invalidField"; + +/** +* Standardized error response following RFC-7807 format +*/ + + +export class DefaultErrorResponseEntity { + /** + * A human-readable explanation specific to this occurrence of the problem. + */ + "detail"?: string; + /** + * Unique business error code. + */ + "errorCode"?: string; + /** + * A URI that identifies the specific occurrence of the problem if applicable. + */ + "instance"?: string; + /** + * Array of fields with validation errors when applicable. + */ + "invalidFields"?: Array; + /** + * The unique reference for the request. + */ + "requestId"?: string; + /** + * The HTTP status code. + */ + "status"?: number; + /** + * A short, human-readable summary of the problem type. + */ + "title"?: string; + /** + * A URI that identifies the validation error type. It points to human-readable documentation for the problem type. + */ + "type"?: string; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "detail", + "baseName": "detail", + "type": "string", + "format": "" + }, + { + "name": "errorCode", + "baseName": "errorCode", + "type": "string", + "format": "" + }, + { + "name": "instance", + "baseName": "instance", + "type": "string", + "format": "" + }, + { + "name": "invalidFields", + "baseName": "invalidFields", + "type": "Array", + "format": "" + }, + { + "name": "requestId", + "baseName": "requestId", + "type": "string", + "format": "" + }, + { + "name": "status", + "baseName": "status", + "type": "number", + "format": "int32" + }, + { + "name": "title", + "baseName": "title", + "type": "string", + "format": "" + }, + { + "name": "type", + "baseName": "type", + "type": "string", + "format": "" + } ]; + + static getAttributeTypeMap() { + return DefaultErrorResponseEntity.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/exchangeSide.ts b/src/typings/foreignExchange/exchangeSide.ts new file mode 100644 index 000000000..3e7d5d565 --- /dev/null +++ b/src/typings/foreignExchange/exchangeSide.ts @@ -0,0 +1,13 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +export enum ExchangeSide { + Buy = 'buy', + Sell = 'sell' +} diff --git a/src/typings/foreignExchange/invalidField.ts b/src/typings/foreignExchange/invalidField.ts new file mode 100644 index 000000000..d558415f1 --- /dev/null +++ b/src/typings/foreignExchange/invalidField.ts @@ -0,0 +1,56 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + + +export class InvalidField { + /** + * The field that has an invalid value. + */ + "name": string; + /** + * The invalid value. + */ + "value": string; + /** + * Description of the validation error. + */ + "message": string; + + static readonly discriminator: string | undefined = undefined; + + static readonly mapping: {[index: string]: string} | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "name", + "baseName": "name", + "type": "string", + "format": "" + }, + { + "name": "value", + "baseName": "value", + "type": "string", + "format": "" + }, + { + "name": "message", + "baseName": "message", + "type": "string", + "format": "" + } ]; + + static getAttributeTypeMap() { + return InvalidField.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/src/typings/foreignExchange/models.ts b/src/typings/foreignExchange/models.ts new file mode 100644 index 000000000..ffce9d7ca --- /dev/null +++ b/src/typings/foreignExchange/models.ts @@ -0,0 +1,12 @@ +export * from "./amount" +export * from "./calculateRateRequest" +export * from "./calculateRateRequestItem" +export * from "./calculateRateResponse" +export * from "./calculateRateResponseItem" +export * from "./defaultErrorResponseEntity" +export * from "./exchangeSide" +export * from "./invalidField" +export * from "./rateType" + +// serializing and deserializing typed objects +export * from "./objectSerializer" \ No newline at end of file diff --git a/src/typings/foreignExchange/objectSerializer.ts b/src/typings/foreignExchange/objectSerializer.ts new file mode 100644 index 000000000..7d5a02376 --- /dev/null +++ b/src/typings/foreignExchange/objectSerializer.ts @@ -0,0 +1,374 @@ +export * from "./models"; + +import { Amount } from "./amount"; +import { CalculateRateRequest } from "./calculateRateRequest"; +import { CalculateRateRequestItem } from "./calculateRateRequestItem"; +import { CalculateRateResponse } from "./calculateRateResponse"; +import { CalculateRateResponseItem } from "./calculateRateResponseItem"; +import { DefaultErrorResponseEntity } from "./defaultErrorResponseEntity"; +import { InvalidField } from "./invalidField"; + +/* tslint:disable:no-unused-variable */ +let primitives = [ + "string", + "boolean", + "double", + "integer", + "long", + "float", + "number", + "any" + ]; + +let enumsMap: Set = new Set([ + "ExchangeSide", + "RateType", +]); + +let typeMap: {[index: string]: any} = { + "Amount": Amount, + "CalculateRateRequest": CalculateRateRequest, + "CalculateRateRequestItem": CalculateRateRequestItem, + "CalculateRateResponse": CalculateRateResponse, + "CalculateRateResponseItem": CalculateRateResponseItem, + "DefaultErrorResponseEntity": DefaultErrorResponseEntity, + "InvalidField": InvalidField, +} + +type MimeTypeDescriptor = { + type: string; + subtype: string; + subtypeTokens: string[]; +}; + +/** + * Every mime-type consists of a type, subtype, and optional parameters. + * The subtype can be composite, including information about the content format. + * For example: `application/json-patch+json`, `application/merge-patch+json`. + * + * This helper transforms a string mime-type into an internal representation. + * This simplifies the implementation of predicates that in turn define common rules for parsing or stringifying + * the payload. + */ +const parseMimeType = (mimeType: string): MimeTypeDescriptor => { + const [type = '', subtype = ''] = mimeType.split('/'); + return { + type, + subtype, + subtypeTokens: subtype.split('+'), + }; +}; + +type MimeTypePredicate = (mimeType: string) => boolean; + +// This factory creates a predicate function that checks a string mime-type against defined rules. +const mimeTypePredicateFactory = (predicate: (descriptor: MimeTypeDescriptor) => boolean): MimeTypePredicate => (mimeType) => predicate(parseMimeType(mimeType)); + +// Use this factory when you need to define a simple predicate based only on type and, if applicable, subtype. +const mimeTypeSimplePredicateFactory = (type: string, subtype?: string): MimeTypePredicate => mimeTypePredicateFactory((descriptor) => { + if (descriptor.type !== type) return false; + if (subtype != null && descriptor.subtype !== subtype) return false; + return true; +}); + +// Creating a set of named predicates that will help us determine how to handle different mime-types +const isTextLikeMimeType = mimeTypeSimplePredicateFactory('text'); +const isJsonMimeType = mimeTypeSimplePredicateFactory('application', 'json'); +const isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === 'application' && descriptor.subtypeTokens.some((item) => item === 'json')); +const isOctetStreamMimeType = mimeTypeSimplePredicateFactory('application', 'octet-stream'); +const isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory('application', 'x-www-form-urlencoded'); + +// Defining a list of mime-types in the order of prioritization for handling. +const supportedMimeTypePredicatesWithPriority: MimeTypePredicate[] = [ + isJsonMimeType, + isJsonLikeMimeType, + isTextLikeMimeType, + isOctetStreamMimeType, + isFormUrlencodedMimeType, +]; + +const nullableSuffix = " | null"; +const optionalSuffix = " | undefined"; +const arrayPrefix = "Array<"; +const arraySuffix = ">"; +const setPrefix = "Set<"; +const mapPrefix = "{ [key: string]: "; +const mapSuffix = "; }"; + +export class ObjectSerializer { + public static findCorrectType(data: any, expectedType: string) { + if (data == undefined) { + return expectedType; + } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { + return expectedType; + } else if (expectedType === "Date") { + return expectedType; + } else { + if (enumsMap.has(expectedType)) { + return expectedType; + } + + if (!typeMap[expectedType]) { + return expectedType; // w/e we don't know the type + } + + // Check the discriminator + let discriminatorProperty = typeMap[expectedType].discriminator; + if (discriminatorProperty == null) { + return expectedType; // the type does not have a discriminator. use it. + } else { + if (data[discriminatorProperty]) { + var discriminatorType = data[discriminatorProperty]; + let mapping = typeMap[expectedType].mapping; + if (mapping != undefined && mapping[discriminatorType]) { + return mapping[discriminatorType]; // use the type given in the discriminator + } else if(typeMap[discriminatorType]) { + return discriminatorType; + } else { + return expectedType; // discriminator did not map to a type + } + } else { + return expectedType; // discriminator was not present (or an empty string) + } + } + } + } + + /** + * Serializes a value into a plain JSON-compatible object based on its type. + * + * Supports primitives, arrays, maps, dates, enums, and classes defined in `typeMap`. + * Falls back to raw data if type is unknown or lacks `getAttributeTypeMap()`. + * + * @param data - The value to serialize. + * @param type - The expected type name as a string. + * @param format - Format hint (e.g. "date" or "date-time"). Default is an empty string. + * @returns A JSON-compatible representation of `data`. + */ + public static serialize(data: any, type: string, format: string = ""): any { + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.endsWith(nullableSuffix)) { + let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type + return ObjectSerializer.serialize(data, subType, format); + } else if (type.endsWith(optionalSuffix)) { + let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type + return ObjectSerializer.serialize(data, subType, format); + } else if (type.startsWith(arrayPrefix)) { + let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array => Type + let transformedData: any[] = []; + for (let date of data) { + transformedData.push(ObjectSerializer.serialize(date, subType, format)); + } + return transformedData; + } else if (type.startsWith(setPrefix)) { + let subType: string = type.slice(setPrefix.length, -arraySuffix.length); // Set => Type + let transformedData: any[] = []; + for (let item of data) { + transformedData.push(ObjectSerializer.serialize(item, subType, format)); + } + return transformedData; + } else if (type.startsWith(mapPrefix)) { + let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type + let transformedData: { [key: string]: any } = {}; + for (let key in data) { + transformedData[key] = ObjectSerializer.serialize( + data[key], + subType, + format, + ); + } + return transformedData; + } else if (type === "Date") { + if (format == "date") { + let month = data.getMonth()+1 + month = month < 10 ? "0" + month.toString() : month.toString() + let day = data.getDate(); + day = day < 10 ? "0" + day.toString() : day.toString(); + + return data.getFullYear() + "-" + month + "-" + day; + } else { + return data.toISOString(); + } + } else { + if (enumsMap.has(type)) { + return data; + } + if (!typeMap[type]) { // in case we dont know the type + return data; + } + + // Get the actual type of this object + type = this.findCorrectType(data, type); + + const clazz = typeMap[type]; + + // Safe check for getAttributeTypeMap + if (typeof clazz.getAttributeTypeMap !== "function") { + return { ...data }; // fallback: shallow copy + } + + // get the map for the correct type. + let attributeTypes = typeMap[type].getAttributeTypeMap(); + let instance: {[index: string]: any} = {}; + for (let attributeType of attributeTypes) { + instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format); + } + return instance; + } + } + + /** + * Deserializes a plain JSON-compatible object into a typed instance. + * + * Handles primitives, arrays, maps, dates, enums, and known classes from `typeMap`. + * Uses discriminators when available to resolve polymorphic types. + * Falls back to raw data if the type is unknown or lacks `getAttributeTypeMap()`. + * + * @param data - The raw input to deserialize. + * @param type - The expected type name as a string. + * @param format - Format hint (e.g. "date" or "date-time"). Default is an empty string. + * @returns A deserialized instance or value of `data`. + */ + public static deserialize(data: any, type: string, format: string = ""): any { + // polymorphism may change the actual type. + type = ObjectSerializer.findCorrectType(data, type); + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.endsWith(nullableSuffix)) { + let subType: string = type.slice(0, -nullableSuffix.length); // Type | null => Type + return ObjectSerializer.deserialize(data, subType, format); + } else if (type.endsWith(optionalSuffix)) { + let subType: string = type.slice(0, -optionalSuffix.length); // Type | undefined => Type + return ObjectSerializer.deserialize(data, subType, format); + } else if (type.startsWith(arrayPrefix)) { + let subType: string = type.slice(arrayPrefix.length, -arraySuffix.length); // Array => Type + let transformedData: any[] = []; + for (let date of data) { + transformedData.push(ObjectSerializer.deserialize(date, subType, format)); + } + return transformedData; + } else if (type.startsWith(setPrefix)) { + let subType: string = type.slice(setPrefix.length, -arraySuffix.length); // Set => Type + let transformedData = new Set(); + for (let item of data) { + transformedData.add(ObjectSerializer.deserialize(item, subType, format)); + } + return transformedData; + } else if (type.startsWith(mapPrefix)) { + let subType: string = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type + let transformedData: { [key: string]: any } = {}; + for (let key in data) { + transformedData[key] = ObjectSerializer.deserialize( + data[key], + subType, + format, + ); + } + return transformedData; + } else if (type === "Date") { + return new Date(data); + } else { + if (enumsMap.has(type)) {// is Enum + return data; + } + + if (!typeMap[type]) { // dont know the type + return data; + } + let instance = new typeMap[type](); + + // Safe check for getAttributeTypeMap + if (typeof typeMap[type].getAttributeTypeMap !== "function") { + Object.assign(instance, data); // fallback: shallow copy + return instance; + } + + let attributeTypes = typeMap[type].getAttributeTypeMap(); + for (let attributeType of attributeTypes) { + let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format); + if (value !== undefined) { + instance[attributeType.name] = value; + } + } + return instance; + } + } + + + /** + * Normalize media type + * + * We currently do not handle any media types attributes, i.e. anything + * after a semicolon. All content is assumed to be UTF-8 compatible. + */ + public static normalizeMediaType(mediaType: string | undefined): string | undefined { + if (mediaType === undefined) { + return undefined; + } + return (mediaType.split(";")[0] ?? '').trim().toLowerCase(); + } + + /** + * From a list of possible media types, choose the one we can handle best. + * + * The order of the given media types does not have any impact on the choice + * made. + */ + public static getPreferredMediaType(mediaTypes: Array): string { + /** According to OAS 3 we should default to json */ + if (mediaTypes.length === 0) { + return "application/json"; + } + + const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType); + + for (const predicate of supportedMimeTypePredicatesWithPriority) { + for (const mediaType of normalMediaTypes) { + if (mediaType != null && predicate(mediaType)) { + return mediaType; + } + } + } + + throw new Error("None of the given media types are supported: " + mediaTypes.join(", ")); + } + + /** + * Convert data to a string according the given media type + */ + public static stringify(data: any, mediaType: string): string { + if (isTextLikeMimeType(mediaType)) { + return String(data); + } + + if (isJsonLikeMimeType(mediaType)) { + return JSON.stringify(data); + } + + throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify."); + } + + /** + * Parse data from a string according to the given media type + */ + public static parse(rawData: string, mediaType: string | undefined) { + if (mediaType === undefined) { + throw new Error("Cannot parse content. No Content-Type defined."); + } + + if (isTextLikeMimeType(mediaType)) { + return rawData; + } + + if (isJsonLikeMimeType(mediaType)) { + return JSON.parse(rawData); + } + + throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse."); + } +} diff --git a/src/typings/foreignExchange/rateType.ts b/src/typings/foreignExchange/rateType.ts new file mode 100644 index 000000000..cf673c43e --- /dev/null +++ b/src/typings/foreignExchange/rateType.ts @@ -0,0 +1,15 @@ +/* + * The version of the OpenAPI document: v1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit this class manually. + */ + +export enum RateType { + SplitPayment = 'splitPayment', + BalanceConversion = 'balanceConversion', + Transfer = 'transfer', + SplitRefund = 'splitRefund' +}