refactor: rename to prettyPrintJSON and add jsdoc
This commit is contained in:
@@ -8,5 +8,10 @@ import * as O from "fp-ts/Option"
|
||||
export const safeParseJSON = (str: string): O.Option<object> =>
|
||||
O.tryCatch(() => JSON.parse(str))
|
||||
|
||||
export const prettyPrintStringifyJSON = (jsonObject: any): O.Option<string> =>
|
||||
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<string> =>
|
||||
O.tryCatch(() => JSON.stringify(obj, null, "\t"))
|
||||
|
||||
@@ -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(() => "")
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user