Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: correctly resolve inherited properties before request runs (#5418)
Nivedin711d249a4d3e
diff --git a/packages/hoppscotch-common/src/components/collections/Collection.vue b/packages/hoppscotch-common/src/components/collections/Collection.vueindex 416003199..8a7364d66 100644--- a/packages/hoppscotch-common/src/components/collections/Collection.vue+++ b/packages/hoppscotch-common/src/components/collections/Collection.vue@@ -82,7 +82,6 @@@click="emit('add-folder')"/><HoppButtonSecondary- v-if="!isEmpty"v-tippy="{ theme: 'tooltip' }":icon="IconPlaySquare":title="t('collection_runner.run_collection')"@@ -145,7 +144,6 @@"/><HoppSmartItem- v-if="!isEmpty"ref="runCollectionAction":icon="IconPlaySquare":label="t('collection_runner.run_collection')"@@ -372,28 +370,6 @@ const ordering = ref(false)const orderingLastItem = ref(false)const dropItemID = ref("")-/**- * Determines if the collection/folder is empty.- * A collection/folder is considered empty if it has no requests and no child folders.- */-const isEmpty = computed(() => {- if (!props.data) return true-- if (props.collectionsType === "my-collections") {- const collection = props.data as HoppCollection- const req = collection.requests.length- const fol = collection.folders.length-- return req === 0 && fol === 0- }-- const teamCollection = props.data as TeamCollection- const req = teamCollection.requests?.length ?? 0- const child = teamCollection.children?.length ?? 0-- return req === 0 && child === 0-})-/*** Determines if the collection/folder is sortable.* A collection/folder is sortable if it has more than one request or more than one child folder.diff --git a/packages/hoppscotch-common/src/helpers/RequestRunner.ts b/packages/hoppscotch-common/src/helpers/RequestRunner.tsindex da914d1d0..9c06f7374 100644--- a/packages/hoppscotch-common/src/helpers/RequestRunner.ts+++ b/packages/hoppscotch-common/src/helpers/RequestRunner.ts@@ -397,8 +397,30 @@ export function runRESTRequest$(const cookieJarEntries = getCookieJarEntries()+ const { request, inheritedProperties } = tab.value.document++ const requestAuth =+ request.auth.authType === "inherit" && request.auth.authActive+ ? inheritedProperties?.auth.inheritedAuth+ : request.auth++ const inheritedHeaders = inheritedProperties?.headers+ ?.filter((header) => header.inheritedHeader)+ .map((header) => header.inheritedHeader!)++ const requestHeaders: HoppRESTHeaders = [+ ...(inheritedHeaders ?? []),+ ...request.headers,+ ]++ const resolvedRequest = {+ ...tab.value.document.request,+ auth: requestAuth ?? { authType: "none", authActive: false },+ headers: requestHeaders,+ }+const res = delegatePreRequestScriptRunner(- tab.value.document.request,+ resolvedRequest,getCombinedEnvVariables(),cookieJarEntries).then(async (preRequestScriptResult) => {@@ -409,31 +431,6 @@ export function runRESTRequest$(return E.left("script_fail" as const)}- const requestAuth =- tab.value.document.request.auth.authType === "inherit" &&- tab.value.document.request.auth.authActive- ? tab.value.document.inheritedProperties?.auth.inheritedAuth- : tab.value.document.request.auth-- let requestHeaders-- const inheritedHeaders =- tab.value.document.inheritedProperties?.headers.map((header) => {- if (header.inheritedHeader) {- return header.inheritedHeader- }- return []- })-- if (inheritedHeaders) {- requestHeaders = [- ...inheritedHeaders,- ...tab.value.document.request.headers,- ]- } else {- requestHeaders = [...tab.value.document.request.headers]- }-const finalRequestVariables =tab.value.document.request.requestVariables.map((v: HoppRESTRequestVariable) => {@@ -460,9 +457,7 @@ export function runRESTRequest$(}))const finalRequest = {- ...tab.value.document.request,- auth: requestAuth ?? { authType: "none", authActive: false },- headers: requestHeaders as HoppRESTHeaders,+ ...resolvedRequest,...(preRequestScriptResult.right.updatedRequest ?? {}),}