Skip to content

Commit

Permalink
hideNonSdkSnippets
Browse files Browse the repository at this point in the history
  • Loading branch information
dphuang2 committed Oct 30, 2023
1 parent d3cca62 commit 105aa7f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export const portal = z
"Relative path to logo image used for Konfig's API Portal. If an object is provided, the light logo will be used for light mode and the dark logo will be used for dark mode."
),
socials: socialObjectSchema.optional(),
hideNonSdkSnippets: z
.boolean()
.optional()
.describe(
'Do not show non-SDK snippets in the API Reference page of the API Portal. This is useful if your API is not easily usable without an SDK or if you do not want developers to use your API without an SDK.'
),
title: z.string().describe("Title to be used in Konfig's API Portal"),
documentation: documentation
.optional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { ReferencePageProps } from '../utils/generate-props-for-reference-page'
import { SocialFooter } from './SocialFooter'
import { Breadcrumbs } from './Breadcrumbs'
import { OperationReferenceResponses } from './OperationReferenceResponses'
import { Language } from './DemoCode'
import { OperationRequest } from './OperationRequest'

export function OperationReferenceMain({
Expand All @@ -67,11 +66,13 @@ export function OperationReferenceMain({
requestBodyParameter,
httpMethod,
contentType,
hideNonSdkSnippets,
}: Pick<
ReferencePageProps,
| 'pathParameters'
| 'queryParameters'
| 'contentType'
| 'hideNonSdkSnippets'
| 'httpMethod'
| 'headerParameters'
| 'cookieParameters'
Expand Down Expand Up @@ -372,6 +373,7 @@ export function OperationReferenceMain({
)}
<div className="sticky top-[calc(var(--mantine-header-height,0px)+1rem)] space-y-4">
<OperationRequest
hideNonSdkSnippets={hideNonSdkSnippets}
codegenArgs={codegenArgs}
requestInProgress={requestInProgress}
/>
Expand Down
104 changes: 56 additions & 48 deletions generator/konfig-next-app/src/components/OperationRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,69 @@ import { Tab } from '@headlessui/react'
import { LanguageExtended } from './DemoCode'
import { Fragment } from 'react'

const languages: { value: LanguageExtended; label: string }[] = [
{
value: 'typescript',
label: 'TypeScript',
},
{
value: 'python',
label: 'Python',
},
{
value: 'bash',
label: 'cURL',
},
{
value: 'java',
label: 'Java',
},
{
value: 'csharp',
label: 'C#',
},
{
value: 'ruby',
label: 'Ruby',
},
{
value: 'php',
label: 'PHP',
},
{
value: 'go',
label: 'Go',
},
{
value: 'kotlin',
label: 'Kotlin',
},
{
value: 'objectivec',
label: 'Objective-C',
},
{
value: 'swift',
label: 'Swift',
},
] as const
const languages: { value: LanguageExtended; isSdk?: boolean; label: string }[] =
[
{
value: 'typescript',
label: 'TypeScript',
isSdk: true, // TODO this should be dynamic based on konfig.yam
},
{
value: 'python',
label: 'Python',
isSdk: true,
},
{
value: 'bash',
label: 'cURL',
},
{
value: 'java',
label: 'Java',
},
{
value: 'csharp',
label: 'C#',
},
{
value: 'ruby',
label: 'Ruby',
},
{
value: 'php',
label: 'PHP',
},
{
value: 'go',
label: 'Go',
},
{
value: 'kotlin',
label: 'Kotlin',
},
{
value: 'objectivec',
label: 'Objective-C',
},
{
value: 'swift',
label: 'Swift',
},
] as const

export function OperationRequest({
codegenArgs,
requestInProgress,
hideNonSdkSnippets,
}: {
codegenArgs: CodeGeneratorConstructorArgs
requestInProgress: boolean
hideNonSdkSnippets: boolean
}) {
const { colorScheme } = useMantineTheme()
const languagesFiltered = languages.filter(({ value, isSdk }) => {
return !hideNonSdkSnippets || isSdk
})
return (
<div className="border rounded-md border-mantine-gray-400 dark:border-mantine-gray-800 overflow-hidden">
<Tab.Group>
Expand All @@ -73,7 +81,7 @@ export function OperationRequest({
className="-mb-px max-w-xs"
>
<Tab.List className="flex gap-4 text-xs font-medium pr-4">
{languages.map(({ label }) => {
{languagesFiltered.map(({ label }) => {
return (
<Tab as={Fragment} key={label}>
{({ selected }) => (
Expand All @@ -99,7 +107,7 @@ export function OperationRequest({
</ScrollArea>
</div>
<Tab.Panels>
{languages.map(({ value }) => {
{languagesFiltered.map(({ value }) => {
return (
<Tab.Panel
className="outline-brand-500 dark:outline-brand-600"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Operation = ({
repo,
oauthTokenUrl: originalOauthTokenUrl,
omitOwnerAndRepo,
hideNonSdkSnippets,
responses,
logo,
}: InferGetStaticPropsType<typeof getStaticProps>) => {
Expand Down Expand Up @@ -179,6 +180,7 @@ const Operation = ({
<OperationReferenceMain
path={path}
requestBodyParameter={requestBodyParameter}
hideNonSdkSnippets={hideNonSdkSnippets}
originalOauthTokenUrl={originalOauthTokenUrl}
contentType={contentType}
owner={owner}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type ReferencePageProps = Omit<GithubResources, 'spec'> & {
requestBodyParameter: Parameter | null
pathParameters: Parameter[]
queryParameters: Parameter[]
hideNonSdkSnippets: boolean
headerParameters: Parameter[]
cookieParameters: Parameter[]
requestBodyProperties: Record<string, SchemaObject> | null
Expand Down Expand Up @@ -262,6 +263,7 @@ export async function generatePropsForReferencePage({
...props,
title: props.konfigYaml.portal.title,
contentType,
hideNonSdkSnippets: props.konfigYaml.portal.hideNonSdkSnippets ?? false,
httpMethod: operation.method,
path: operation.path,
operationId,
Expand Down

0 comments on commit 105aa7f

Please sign in to comment.