From aff740b08ac591af9f2362d1d9c518e503f9af22 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Thu, 24 Nov 2022 17:54:49 -0330 Subject: [PATCH] Start Storage api file --- apps/docs/generator/api.ts | 2 +- apps/docs/layouts/ref/RefSubLayout.tsx | 2 +- apps/docs/lib/refGenerator/helpers.ts | 6 +- .../pages/new/reference/storage/[...slug].tsx | 166 ++++++++++++++++-- 4 files changed, 161 insertions(+), 15 deletions(-) diff --git a/apps/docs/generator/api.ts b/apps/docs/generator/api.ts index 9358306f733..6682e3a65ff 100644 --- a/apps/docs/generator/api.ts +++ b/apps/docs/generator/api.ts @@ -33,7 +33,7 @@ export default async function gen(inputFileName: string, outputDir: string, apiU type v3OperationWithPath = OpenAPIV3.OperationObject & { path: string } -type enrichedOperation = OpenAPIV3.OperationObject & { +export type enrichedOperation = OpenAPIV3.OperationObject & { path: string fullPath: string operationId: string diff --git a/apps/docs/layouts/ref/RefSubLayout.tsx b/apps/docs/layouts/ref/RefSubLayout.tsx index 56659cde177..fccc89c3340 100644 --- a/apps/docs/layouts/ref/RefSubLayout.tsx +++ b/apps/docs/layouts/ref/RefSubLayout.tsx @@ -43,7 +43,7 @@ const Section: FC = (props) => { interface ISectionDetails extends FC {} -const Details: FC = (props) => { +const Details: FC = (props: any) => { return
{props.children}
} diff --git a/apps/docs/lib/refGenerator/helpers.ts b/apps/docs/lib/refGenerator/helpers.ts index 9adb3335ee6..7057a768cd3 100644 --- a/apps/docs/lib/refGenerator/helpers.ts +++ b/apps/docs/lib/refGenerator/helpers.ts @@ -1,6 +1,6 @@ import { TsDoc } from '~/generator/legacy/definitions' -import { uniqBy } from 'lodash' +import { uniqBy, values, mapValues } from 'lodash' import { OpenAPIV3 } from 'openapi-types' export function extractTsDocNode(nodeToFind: string, definition: any) { @@ -231,8 +231,8 @@ const toTitle = (text: string) => { * Convert Object to Array of values */ export const toArrayWithKey = (obj: object, keyAs: string) => - _.values( - _.mapValues(obj, (value: any, key: string) => { + values( + mapValues(obj, (value: any, key: string) => { value[keyAs] = key return value }) diff --git a/apps/docs/pages/new/reference/storage/[...slug].tsx b/apps/docs/pages/new/reference/storage/[...slug].tsx index d3116180ae0..16688f0f148 100644 --- a/apps/docs/pages/new/reference/storage/[...slug].tsx +++ b/apps/docs/pages/new/reference/storage/[...slug].tsx @@ -1,16 +1,162 @@ import specFile from '~/../../spec/storage_v0_openapi.json' assert { type: 'json' } -import { gen_v3 } from '~/lib/refGenerator/helpers' +import { gen_v3, enrichedOperation } from '~/lib/refGenerator/helpers' +import { Tabs } from '~/../../packages/ui' +// @ts-ignore +import CodeBlock from '~/components/CodeBlock/CodeBlock' +import Options from '~/components/Options' +import Param from '~/components/Params' +import RefSubLayout from '~/layouts/ref/RefSubLayout' + +export type AcceptedValue = { + id: string + name: string + type: 'string' | 'boolean' | 'object' + description?: string +} + +export type Flag = { + id: string + name: string + description: string + default_value: string + accepted_values: AcceptedValue[] +} + +export type ApiParameter = { + example: string + in: string + name: string + required: boolean + schema: { + type: string + example: string + } +} // @ts-ignore -const specGen = gen_v3(specFile, 'wat', { apiUrl: 'apiv0' }) - -console.log({ specGen }) - -export default function Ref(props) { - console.log({ specFile }) +const generatedSpec = gen_v3(specFile, 'wat', { apiUrl: 'apiv0' }) +console.log('zans', generatedSpec) +export default function Config() { return ( -
-
hay?
-
+ +
+
+
+

{generatedSpec.info.title}

+

{generatedSpec.info.description}

+
+ +
+ {generatedSpec.sections.map((section) => { + return ( + + +
+
+

{section.description}

+
+ {section.operations.map((operation: enrichedOperation) => ( + <> +
+

{operation.summary}

+
+ + {operation.operation} + {operation.fullPath} + +
+
+

Path parameters

+
    + {operation.parameters && + operation.parameters + .filter((parameter) => parameter.in === 'path') + .map((parameter: ApiParameter) => ( +
  • +
    + {parameter.name} + + {parameter.required && 'required'} + +
    +
    + Example: + + {parameter.example} + +
    +
  • + ))} +
+
+ +
+

Header parameters

+
    + {operation.parameters && + operation.parameters + .filter((parameter) => parameter.in === 'header') + .map((parameter: ApiParameter) => ( +
  • +
    + {parameter.name} + + {parameter.required && 'required'} + +
    +
    + Example: + + {parameter.example} + +
    +
  • + ))} +
+
+
+ +

Responses

+ + {operation.responseList.map((response) => ( + +

{response.description}

+ {response?.content && response?.content['application/json'] && ( +
+ + {JSON.stringify( + response.content['application/json'], + null, + 2 + )} + +
+ )} +
+ ))} +
+ + ))} +
+
+
+
+ + right side +
+ ) + })} +
+
+
+
) }