diff --git a/GUI/src/components/ApiEndpointCard/Endpoints/OpenAPI/index.tsx b/GUI/src/components/ApiEndpointCard/Endpoints/OpenAPI/index.tsx index 3f157dffd..40dce71fe 100644 --- a/GUI/src/components/ApiEndpointCard/Endpoints/OpenAPI/index.tsx +++ b/GUI/src/components/ApiEndpointCard/Endpoints/OpenAPI/index.tsx @@ -12,7 +12,6 @@ import { PreDefinedEndpointEnvVariables, } from "../../../../types/endpoint"; import { RequestVariablesRowData } from "../../../../types/request-variables"; -import useServiceStore from "store/new-services.store"; import api from "../../../../services/api-dev"; type EndpointOpenAPIProps = { @@ -30,14 +29,13 @@ const EndpointOpenAPI: React.FC = ({ requestTab, setRequestTab, }) => { - const [openApiUrl, setOpenApiUrl] = useState(endpoint.openApiUrl ?? ""); + const [openApiUrl, setOpenApiUrl] = useState(endpoint?.definitions[0]?.openApiUrl ?? ""); const [selectedEndpoint, setSelectedEndpoint] = useState( endpoint.definitions.find((e) => e.isSelected) ); const [openApiEndpoints, setOpenApiEndpoints] = useState(endpoint.definitions ?? []); const [key, setKey] = useState(0); const { t } = useTranslation(); - const { setEndpoints } = useServiceStore(); useEffect(() => setKey(key + 1), [isLive]); @@ -165,10 +163,11 @@ const EndpointOpenAPI: React.FC = ({ label, path, url: endpointUrl, + openApiUrl, type: "openApi", methodType: method, - supported: false, - isSelected: false, + supported: true, + isSelected: true, dataType: "custom", }); return; @@ -185,9 +184,10 @@ const EndpointOpenAPI: React.FC = ({ type: "openApi", methodType: method, supported: true, - isSelected: false, + isSelected: true, description: data.summary ?? data.description, url: endpointUrl, + openApiUrl, dataType: "custom", body: body ? { @@ -212,14 +212,8 @@ const EndpointOpenAPI: React.FC = ({ }); }); setOpenApiEndpoints(paths); - setEndpoints((prevEndpoints) => { - prevEndpoints.forEach((prevEndpoint) => { - if (prevEndpoint.endpointId !== endpoint.endpointId) return; - prevEndpoint.definitions = paths; - prevEndpoint.openApiUrl = openApiUrl; - }); - return prevEndpoints; - }); + endpoint.definitions = paths; + endpoint.definitions[0].openApiUrl = openApiUrl; setKey(key + 1); }; @@ -239,25 +233,12 @@ const EndpointOpenAPI: React.FC = ({ const onSelectEndpoint = (selection: Option | null) => { const newSelectedEndpoint = openApiEndpoints.find((openApiEndpoint) => openApiEndpoint.label === selection?.label); setSelectedEndpoint(newSelectedEndpoint); - setEndpoints((prevEndpoints) => { - return updateSelectedEndpoint(prevEndpoints, newSelectedEndpoint); - }); + if (!newSelectedEndpoint) return; + endpoint.definitions = []; + endpoint.definitions.push(newSelectedEndpoint); setKey(key + 1); }; - const updateSelectedEndpoint = ( - prevEndpoints: EndpointData[], - newSelectedEndpoint: EndpointDefinition | undefined - ) => { - return prevEndpoints.map((prevEndpoint) => { - if (prevEndpoint.endpointId !== endpoint.endpointId) return prevEndpoint; - prevEndpoint.definitions.forEach((definedEndpoint) => { - definedEndpoint.isSelected = definedEndpoint === newSelectedEndpoint; - }); - return prevEndpoint; - }); - }; - return (
diff --git a/GUI/src/components/ApiEndpointCard/Endpoints/RequestVariables/index.tsx b/GUI/src/components/ApiEndpointCard/Endpoints/RequestVariables/index.tsx index 42637fd80..e45bd4fae 100644 --- a/GUI/src/components/ApiEndpointCard/Endpoints/RequestVariables/index.tsx +++ b/GUI/src/components/ApiEndpointCard/Endpoints/RequestVariables/index.tsx @@ -127,6 +127,7 @@ const RequestVariables: React.FC = ({ const getInitialTabsRawData = (): RequestVariablesTabsRawData => { return tabs.reduce((tabsRawData, tab) => { const endpointData = endpoint.definitions[0]; + if (!endpointData || !endpointData[tab]) return tabsRawData; return { ...tabsRawData, [tab]: endpointData[tab]?.rawData[isLive ? "value" : "testValue"] ?? "" }; }, {}); }; @@ -165,7 +166,9 @@ const RequestVariables: React.FC = ({ row[field] = newValue; }); - newRowsData[requestTab.tab] = maintainSingleEmptyRow(newRowsData[requestTab.tab] || []); + if (endpoint.type === "custom") { + newRowsData[requestTab.tab] = maintainSingleEmptyRow(newRowsData[requestTab.tab] || []); + } updateEndpointData(newRowsData, endpoint); if (requestTab.tab === "params") onParametersChange( diff --git a/GUI/src/store/new-services.store.ts b/GUI/src/store/new-services.store.ts index 3c6c1f69f..bcebb015d 100644 --- a/GUI/src/store/new-services.store.ts +++ b/GUI/src/store/new-services.store.ts @@ -787,6 +787,8 @@ const useServiceStore = create((set, get, store) => ({ })); function extractMapValues(element: any) { + if (!element) return {}; + if (element.rawData && element.rawData.length > 0) { return element.rawData.value; } diff --git a/GUI/src/types/endpoint/endpoint-data.ts b/GUI/src/types/endpoint/endpoint-data.ts index 3ee5db220..f6288ae7c 100644 --- a/GUI/src/types/endpoint/endpoint-data.ts +++ b/GUI/src/types/endpoint/endpoint-data.ts @@ -8,7 +8,6 @@ export type EndpointData = { type?: EndpointType; isCommon?: boolean; isNew?: boolean; - openApiUrl?: string; hasTestEnv?: boolean; serviceId?: string; definitions: EndpointDefinition[]; diff --git a/GUI/src/types/endpoint/endpoint-definition.ts b/GUI/src/types/endpoint/endpoint-definition.ts index 83d1adc7b..e3e8517e0 100644 --- a/GUI/src/types/endpoint/endpoint-definition.ts +++ b/GUI/src/types/endpoint/endpoint-definition.ts @@ -12,6 +12,7 @@ export type EndpointDefinition = { supported: boolean; isSelected: boolean; url?: string; + openApiUrl?: string; description?: string; params?: { variables: EndpointVariableData[];