diff --git a/packages/hoppscotch-app/helpers/functional/json.ts b/packages/hoppscotch-app/helpers/functional/json.ts index a9cbaa7a5..db5931932 100644 --- a/packages/hoppscotch-app/helpers/functional/json.ts +++ b/packages/hoppscotch-app/helpers/functional/json.ts @@ -8,5 +8,10 @@ import * as O from "fp-ts/Option" export const safeParseJSON = (str: string): O.Option => O.tryCatch(() => JSON.parse(str)) -export const prettyPrintStringifyJSON = (jsonObject: any): O.Option => - O.tryCatch(() => JSON.stringify(jsonObject, null, "\t")) +/** + * Generates a prettified JSON representation of an object + * @param obj The object to get the representation of + * @returns The prettified JSON string of the object + */ +export const prettyPrintJSON = (obj: unknown): O.Option => + O.tryCatch(() => JSON.stringify(obj, null, "\t")) diff --git a/packages/hoppscotch-app/helpers/import-export/import/openapi/exampleV2.ts b/packages/hoppscotch-app/helpers/import-export/import/openapi/exampleV2.ts index 2923bc12f..63f36b052 100644 --- a/packages/hoppscotch-app/helpers/import-export/import/openapi/exampleV2.ts +++ b/packages/hoppscotch-app/helpers/import-export/import/openapi/exampleV2.ts @@ -2,7 +2,7 @@ import { OpenAPIV2 } from "openapi-types" import * as O from "fp-ts/Option" import { pipe, flow } from "fp-ts/function" import * as A from "fp-ts/Array" -import { prettyPrintStringifyJSON } from "~/helpers/functional/json" +import { prettyPrintJSON } from "~/helpers/functional/json" type PrimitiveSchemaType = "string" | "integer" | "number" | "boolean" @@ -182,7 +182,7 @@ export const generateRequestBodyExampleFromOpenAPIV2Body = ( O.getOrElse(() => "" as RequestBodyExampleType), (requestBodyExample) => pipe( - prettyPrintStringifyJSON(requestBodyExample), + prettyPrintJSON(requestBodyExample), O.getOrElse(() => "") ) ) diff --git a/packages/hoppscotch-app/helpers/import-export/import/openapi/index.ts b/packages/hoppscotch-app/helpers/import-export/import/openapi/index.ts index 37117930b..ac5168922 100644 --- a/packages/hoppscotch-app/helpers/import-export/import/openapi/index.ts +++ b/packages/hoppscotch-app/helpers/import-export/import/openapi/index.ts @@ -29,7 +29,7 @@ import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "../" import { generateRequestBodyExampleFromMediaObject as generateExampleV31 } from "./exampleV31" import { generateRequestBodyExampleFromMediaObject as generateExampleV3 } from "./exampleV3" import { generateRequestBodyExampleFromOpenAPIV2Body } from "./exampleV2" -import { prettyPrintStringifyJSON } from "~/helpers/functional/json" +import { prettyPrintJSON } from "~/helpers/functional/json" export const OPENAPI_DEREF_ERROR = "openapi/deref_error" as const @@ -207,7 +207,7 @@ const parseOpenAPIV3Body = ( ] = objs[0] const exampleBody = pipe( - prettyPrintStringifyJSON( + prettyPrintJSON( isV31Request ? generateExampleV31(media as OpenAPIV31.MediaTypeObject) : generateExampleV3(media as OpenAPIV3.MediaTypeObject)