swagger api generator
This commit is contained in:
parent
c90bfd4b47
commit
8fe74710e0
|
@ -39,4 +39,6 @@ Check out our [Next.js deployment documentation](https://nextjs.org/docs/deploym
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT NOT NULL, alias TEXT NOT NULL, pending INTEGER DEFAULT 0, temporary INTEGER DEFAULT 0);
|
CREATE TABLE aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT NOT NULL, alias TEXT NOT NULL, pending INTEGER DEFAULT 0, temporary INTEGER DEFAULT 0);
|
||||||
CREATE TABLE temp_alias_requests (key TEXT PRIMARY KEY, address TEXT NOT NULL, alias TEXT NOT NULL, expires INTEGER NOT NULL);
|
CREATE TABLE temp_alias_requests (key TEXT PRIMARY KEY, address TEXT NOT NULL, alias TEXT NOT NULL, expires INTEGER NOT NULL);
|
||||||
|
|
||||||
|
CREATE TABLE api_keys (id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT NOT NULL, token TEXT NOT NULL);
|
||||||
```
|
```
|
||||||
|
|
19
src/app/(dashboard)/api-keys/page.tsx
Normal file
19
src/app/(dashboard)/api-keys/page.tsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Button, Flex, Heading, Text } from "@radix-ui/themes";
|
||||||
|
import { ExternalLinkIcon } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function ApiKeys() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Flex justify="between" align="center" direction="row" gap="5">
|
||||||
|
<Flex direction="column">
|
||||||
|
<Heading>API keys</Heading>
|
||||||
|
<Text size="3" weight="light">Generate long lasting API keys that can be used to perform certain actions programatically.</Text>
|
||||||
|
</Flex>
|
||||||
|
<Link href="/api-doc" target="_blank">
|
||||||
|
<Button variant="outline">API docs <ExternalLinkIcon size="16" /></Button>
|
||||||
|
</Link>
|
||||||
|
</Flex>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
11
src/app/(swagger)/api-doc/page.tsx
Normal file
11
src/app/(swagger)/api-doc/page.tsx
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { getApiDocs } from '@/lib/swagger';
|
||||||
|
import ReactSwagger from './swagger';
|
||||||
|
|
||||||
|
export default async function IndexPage() {
|
||||||
|
const spec = await getApiDocs();
|
||||||
|
return (
|
||||||
|
<section className="container">
|
||||||
|
<ReactSwagger spec={spec} />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
14
src/app/(swagger)/api-doc/swagger.tsx
Normal file
14
src/app/(swagger)/api-doc/swagger.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import SwaggerUI from 'swagger-ui-react';
|
||||||
|
import 'swagger-ui-react/swagger-ui.css';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
spec: Record<string, any>,
|
||||||
|
};
|
||||||
|
|
||||||
|
function ReactSwagger({ spec }: Props) {
|
||||||
|
return <SwaggerUI spec={spec} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ReactSwagger;
|
13
src/app/(swagger)/layout.tsx
Normal file
13
src/app/(swagger)/layout.tsx
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
export default async function RootLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
{children}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
15
src/app/api/test/route.ts
Normal file
15
src/app/api/test/route.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/test:
|
||||||
|
* get:
|
||||||
|
* description: Returns the hello world
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Hello World!
|
||||||
|
*/
|
||||||
|
export async function GET(_request: Request) {
|
||||||
|
// Do whatever you want
|
||||||
|
return new Response('Hello World!', {
|
||||||
|
status: 200,
|
||||||
|
});
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { isAdmin } from "@/lib/util";
|
import { isAdmin } from "@/lib/util";
|
||||||
import { Avatar, Button, Card, Flex, IconButton, Popover, ScrollArea, Text, Tooltip } from "@radix-ui/themes";
|
import { Avatar, Button, Card, Flex, IconButton, Popover, ScrollArea, Text, Tooltip } from "@radix-ui/themes";
|
||||||
import { BookUserIcon, HomeIcon, ScrollTextIcon, Users2Icon } from "lucide-react";
|
import { BookUserIcon, HomeIcon, KeyRoundIcon, ScrollTextIcon, Users2Icon } from "lucide-react";
|
||||||
import { signOut, useSession } from "next-auth/react";
|
import { signOut, useSession } from "next-auth/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
@ -67,6 +67,14 @@ export default function NavigationPanel({ mobileUi }: { mobileUi?: boolean }) {
|
||||||
</Link>
|
</Link>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip content="API Keys" side={tooltipSide}>
|
||||||
|
<Link href="/api-keys">
|
||||||
|
<IconButton variant="outline" size='4'>
|
||||||
|
<KeyRoundIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Link>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
{isAdmin(session.data) && (
|
{isAdmin(session.data) && (
|
||||||
<>
|
<>
|
||||||
<Tooltip content="Users" side={tooltipSide}>
|
<Tooltip content="Users" side={tooltipSide}>
|
||||||
|
|
25
src/lib/swagger.ts
Normal file
25
src/lib/swagger.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { createSwaggerSpec } from 'next-swagger-doc';
|
||||||
|
|
||||||
|
export const getApiDocs = async () => {
|
||||||
|
const spec = createSwaggerSpec({
|
||||||
|
apiFolder: 'src/app/api', // define api folder under app folder
|
||||||
|
definition: {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
|
title: 'Maddy Panel API',
|
||||||
|
version: '1.0',
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
securitySchemes: {
|
||||||
|
BearerAuth: {
|
||||||
|
type: 'http',
|
||||||
|
scheme: 'bearer',
|
||||||
|
bearerFormat: 'JWT',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
security: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return spec;
|
||||||
|
};
|
Loading…
Reference in a new issue