From a92d4aad671e1061ce0f531ece0c6e45ed8463dd Mon Sep 17 00:00:00 2001 From: Flavio Stutz Date: Thu, 18 Jan 2024 02:50:06 +0100 Subject: [PATCH] create types for endpoint config --- src/wso2/wso2-api/v1/types-swagger.ts | 48 ++++++++++++++++++++++++++- src/wso2/wso2-api/wso2-api-defs.ts | 3 -- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/wso2/wso2-api/v1/types-swagger.ts b/src/wso2/wso2-api/v1/types-swagger.ts index c9d1510..6afab9f 100644 --- a/src/wso2/wso2-api/v1/types-swagger.ts +++ b/src/wso2/wso2-api/v1/types-swagger.ts @@ -330,7 +330,12 @@ export type API = { * } * } */ - endpointConfig?: { [key: string]: unknown }; + endpointConfig?: + | ({ endpoint_type: 'http' } & EndpointHttp) + | ({ endpoint_type: 'load_balance' } & EndpointLoadBalance) + | ({ endpoint_type: 'failover' } & EndpointFailover) + | ({ endpoint_type: 'default' } & EndpointHttp); + /** * @default ENDPOINT * @example INLINE @@ -544,3 +549,44 @@ export type MediationPolicy = { /** @example true */ shared?: boolean; }; + +export type EndpointTarget = { + endpoint_type?: string; + template_not_supported?: boolean; + url: string; +}; + +export type EndpointHttp = { + endpoint_type: 'http'; + sandbox_endpoints: { + url: string; + }; + production_endpoints: { + url: string; + }; +}; + +export type EndpointFailover = { + endpoint_type: 'failover'; + sandbox_endpoints: { + url: string; + }; + production_endpoints: { + url: string; + }; + production_failovers: [EndpointTarget]; + sandbox_failovers: [EndpointTarget]; +}; + +export type EndpointLoadBalance = { + endpoint_type: 'load_balance'; + algoCombo: 'org.apache.synapse.endpoints.algorithms.RoundRobin'; + sessionManagement: 'None' | 'Transport' | 'SOAP' | 'ClientID'; + sandbox_endpoints: [EndpointTarget]; + production_endpoints: [EndpointTarget]; + /** + * Session timeout in milliseconds + */ + sessionTimeOut: number; + algoClassName: 'org.apache.synapse.endpoints.algorithms.RoundRobin'; +}; diff --git a/src/wso2/wso2-api/wso2-api-defs.ts b/src/wso2/wso2-api/wso2-api-defs.ts index d17dda2..968c853 100644 --- a/src/wso2/wso2-api/wso2-api-defs.ts +++ b/src/wso2/wso2-api/wso2-api-defs.ts @@ -19,9 +19,6 @@ export const validateWso2ApiDefs = (apiDef: Wso2ApiDefinition): void => { if (!apiDef.endpointConfig) { throw new Error('endpointConfig is required'); } - if (!apiDef.gatewayEnvironments || apiDef.gatewayEnvironments.length === 0) { - throw new Error('gatewayEnvironments is required'); - } validateVisibility(apiDef); };