Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: issues with 'fs' getting used in client

Jonathan Summers-Muirb308fedfd081
diff --git a/apps/docs/lib/refGenerator/helpers.ts b/apps/docs/lib/refGenerator/helpers.ts
index bc1c1a4b7e6..25ab9b1bf88 100644
--- a/apps/docs/lib/refGenerator/helpers.ts
+++ b/apps/docs/lib/refGenerator/helpers.ts
@@ -1,9 +1,8 @@
import React from 'react'
import { TsDoc } from '~/generator/legacy/definitions'
-// import { OpenAPIV3, OpenAPIV2 } from 'openapi-types'
+import { OpenAPIV3, OpenAPIV2 } from 'openapi-types'
import { uniqBy } from 'lodash'
-// import { slugify, toArrayWithKey, toTitle } from '~/generator/helpers'
export function extractTsDocNode(nodeToFind: string, definition: any) {
const nodePath = nodeToFind.split('.')
@@ -205,41 +204,68 @@ type enrichedOperation = OpenAPIV3.OperationObject & {
fullPath: string
operationId: string
}
-// export function gen_v3(spec: OpenAPIV3.Document, dest: string, { apiUrl }: { apiUrl: string }) {
-// const specLayout = spec.tags || []
-// const operations: enrichedOperation[] = []
-// console.log('im v3ing')
-// Object.entries(spec.paths).forEach(([key, val]) => {
-// const fullPath = `${apiUrl}${key}`
-
-// toArrayWithKey(val!, 'operation').forEach((o) => {
-// const operation = o as v3OperationWithPath
-// const enriched = {
-// ...operation,
-// path: key,
-// fullPath,
-// operationId: slugify(operation.summary!),
-
-// responseList: toArrayWithKey(operation.responses!, 'responseCode') || [],
-// }
-// operations.push(enriched)
-// })
-// })
+export function gen_v3(spec: OpenAPIV3.Document, dest: string, { apiUrl }: { apiUrl: string }) {
+ const specLayout = spec.tags || []
+ const operations: enrichedOperation[] = []
+ console.log('im v3ing')
+ Object.entries(spec.paths).forEach(([key, val]) => {
+ const fullPath = `${apiUrl}${key}`
+
+ toArrayWithKey(val!, 'operation').forEach((o) => {
+ const operation = o as v3OperationWithPath
+ const enriched = {
+ ...operation,
+ path: key,
+ fullPath,
+ operationId: slugify(operation.summary!),
+
+ responseList: toArrayWithKey(operation.responses!, 'responseCode') || [],
+ }
+ operations.push(enriched)
+ })
+ })
+
+ const sections = specLayout.map((section) => {
+ return {
+ ...section,
+ title: toTitle(section.name),
+ id: slugify(section.name),
+ operations: operations.filter((operation) => operation.tags?.includes(section.name)),
+ }
+ })
-// const sections = specLayout.map((section) => {
-// return {
-// ...section,
-// title: toTitle(section.name),
-// id: slugify(section.name),
-// operations: operations.filter((operation) => operation.tags?.includes(section.name)),
-// }
-// })
+ const content = {
+ info: spec.info,
+ sections,
+ operations,
+ }
-// const content = {
-// info: spec.info,
-// sections,
-// operations,
-// }
+ return content
+}
-// return content
-// }
+const slugify = (text: string) => {
+ return text
+ .toString()
+ .toLowerCase()
+ .replace(/[. )(]/g, '-') // Replace spaces and brackets -
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
+ .replace(/\-\-+/g, '-') // Replace multiple - with single -
+ .replace(/^-+/, '') // Trim - from start of text
+ .replace(/-+$/, '') // Trim - from end of text
+}
+
+// Uppercase the first letter of a string
+const toTitle = (text: string) => {
+ return text.charAt(0).toUpperCase() + text.slice(1)
+}
+
+/**
+ * Convert Object to Array of values
+ */
+export const toArrayWithKey = (obj: object, keyAs: string) =>
+ _.values(
+ _.mapValues(obj, (value: any, key: string) => {
+ value[keyAs] = key
+ return value
+ })
+ )