Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: add generate data schema option in spotlight searcher (#4356)

Anwarul Islam421e6b76c938
diff --git a/packages/hoppscotch-common/src/services/spotlight/searchers/response.searcher.ts b/packages/hoppscotch-common/src/services/spotlight/searchers/response.searcher.ts
index 40832e563..88b918681 100644
--- a/packages/hoppscotch-common/src/services/spotlight/searchers/response.searcher.ts
+++ b/packages/hoppscotch-common/src/services/spotlight/searchers/response.searcher.ts
@@ -9,6 +9,7 @@ import {
import IconDownload from "~icons/lucide/download"
import IconCopy from "~icons/lucide/copy"
+import IconNetwork from "~icons/lucide/network"
import { Container } from "dioc"
type Doc = {
@@ -40,6 +41,8 @@ export class ResponseSpotlightSearcherService extends StaticSpotlightSearcherSer
"response.file.download"
)
+ private dataSchemaActionEnabled = isActionBound("response.schema.toggle")
+
private documents: Record<string, Doc> = reactive({
copy_response: {
text: this.t("spotlight.response.copy"),
@@ -55,6 +58,12 @@ export class ResponseSpotlightSearcherService extends StaticSpotlightSearcherSer
() => !this.downloadResponseActionEnabled.value
),
},
+ generate_data_schema: {
+ text: this.t("response.generate_data_schema"),
+ alternates: ["generate", "data", "schema", "typescript", "response"],
+ icon: markRaw(IconNetwork),
+ excludeFromSearch: computed(() => !this.dataSchemaActionEnabled.value),
+ },
})
// TODO: Constructors are no longer recommended as of dioc > 3, move to onServiceInit
@@ -87,5 +96,6 @@ export class ResponseSpotlightSearcherService extends StaticSpotlightSearcherSer
public onDocSelected(id: string): void {
if (id === "copy_response") invokeAction(`response.copy`)
if (id === "download_response") invokeAction(`response.file.download`)
+ if (id === "generate_data_schema") invokeAction(`response.schema.toggle`)
}
}