-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Agora-1928] Serve spec at /api/v1/spec + swagger UI at /api_v1 (#236)
* π» serve raw spec from /api/v1/spec * π»π¦π add packages + page for swagger react ui * π»β¨ add swagger ui in pages router
- Loading branch information
1 parent
e8b5b18
commit 62948be
Showing
6 changed files
with
1,701 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export async function GET(request: Request) { | ||
const fp = path.join(process.cwd(), "spec/oas_v1.yaml"); | ||
|
||
try { | ||
const data = fs.readFileSync(fp, "utf8"); | ||
// set headers | ||
const headers = new Headers(); | ||
headers.set("Content-Type", "application/x-yaml"); | ||
|
||
return new Response(data, { | ||
headers, | ||
status: 200, | ||
}); | ||
} catch (err) { | ||
if (err) { | ||
console.error(err); | ||
return new Response(JSON.stringify(`{result: "error"}`), { | ||
status: 500, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Head from "next/head"; | ||
import { Inter } from "next/font/google"; | ||
import SwaggerUI from "swagger-ui-react"; | ||
import "swagger-ui-react/swagger-ui.css"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export default function SpecUI() { | ||
return ( | ||
<> | ||
<Head> | ||
<title>Agora API</title> | ||
<meta | ||
name="description" | ||
content="Open API Specification for Agora's public API" | ||
/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</Head> | ||
<main className={`${inter.className}`}> | ||
<SwaggerUI url="/api/v1/spec" /> | ||
</main> | ||
</> | ||
); | ||
} |
Oops, something went wrong.