-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implements swagger API documentation (#161)
- Loading branch information
Showing
16 changed files
with
2,513 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
|
||
import React, { useState, useEffect } from "react"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const DynamicReactSwagger = dynamic(() => import("./react-swagger"), { | ||
ssr: false, | ||
loading: () => <div>Loading...</div>, | ||
}); | ||
|
||
export default function IndexPage() { | ||
const [spec, setSpec] = useState(null); | ||
|
||
useEffect(() => { | ||
async function fetchSpecs() { | ||
const response = await fetch("/api/getSwaggerDocs"); | ||
|
||
if (response.ok) { | ||
const fetchedSpec = await response.json(); | ||
setSpec(fetchedSpec); | ||
} else { | ||
console.error("Failed to fetch API docs"); | ||
} | ||
} | ||
|
||
fetchSpecs(); | ||
}, []); | ||
|
||
if (!spec) return <div>Loading...</div>; | ||
|
||
return ( | ||
<section className="container"> | ||
<DynamicReactSwagger spec={spec} /> | ||
</section> | ||
); | ||
} |
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,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; |
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,85 @@ | ||
"use client"; | ||
import "../globals.scss"; | ||
import { Inter } from "next/font/google"; | ||
import React, { useState, useEffect } from "react"; | ||
import { checkBackendAvailable } from "@/utils/checkBackendAvailable"; | ||
import { List, Notification, Row } from "@canonical/react-components"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import Navigation from "@/components/Navigation"; | ||
import PageContent from "@/components/PageContent"; | ||
import Loader from "@/components/Loader"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
const queryClient = new QueryClient(); | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
noLayout?: boolean; | ||
}) { | ||
const [backendAvailable, setBackendAvailable] = useState<null | boolean>( | ||
null, | ||
); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const isBackendAvailable = await checkBackendAvailable(); | ||
setBackendAvailable(isBackendAvailable); | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<html lang="en"> | ||
<head> | ||
<title>SD Core</title> | ||
<link | ||
rel="shortcut icon" | ||
href="https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png" | ||
type="image/x-icon" | ||
/> | ||
</head> | ||
<body className={inter.className}> | ||
<div className="l-application" role="presentation"> | ||
<Navigation /> | ||
<main className="l-main"> | ||
<div className="p-panel"> | ||
{backendAvailable === null && <Loader text="Loading..." />} | ||
{backendAvailable === false && ( | ||
<PageContent> | ||
<Notification severity="negative" title="Error"> | ||
{"Backend not available"} | ||
</Notification> | ||
</PageContent> | ||
)} | ||
{backendAvailable === true && ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
)} | ||
</div> | ||
<footer className="l-footer--sticky p-strip--light"> | ||
<Row> | ||
<p> | ||
© 2023 Canonical Ltd. <a href="#">Ubuntu</a> and{" "} | ||
<a href="#">Canonical</a> are registered trademarks of | ||
Canonical Ltd. | ||
</p> | ||
<List | ||
items={[ | ||
<a key="Legal information" href="https://ubuntu.com/legal"> | ||
Legal information | ||
</a>, | ||
]} | ||
middot | ||
/> | ||
</Row> | ||
</footer> | ||
</main> | ||
</div> | ||
</body> | ||
</html> | ||
); | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,86 +1,18 @@ | ||
"use client"; | ||
import "./globals.scss"; | ||
import { Inter } from "next/font/google"; | ||
import React, { useState, useEffect } from "react"; | ||
import { checkBackendAvailable } from "@/utils/checkBackendAvailable"; | ||
import { | ||
List, | ||
Notification, | ||
Row, | ||
} from "@canonical/react-components"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import Navigation from "@/components/Navigation"; | ||
import PageContent from "@/components/PageContent"; | ||
import Loader from "@/components/Loader"; | ||
import type { Metadata } from "next"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
const queryClient = new QueryClient(); | ||
export const metadata: Metadata = { | ||
title: "SD Core", | ||
description: "SD Core NMS", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const [backendAvailable, setBackendAvailable] = useState<null | boolean>( | ||
null, | ||
); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const isBackendAvailable = await checkBackendAvailable(); | ||
setBackendAvailable(isBackendAvailable); | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<html lang="en"> | ||
<head> | ||
<title>SD Core</title> | ||
<link rel="shortcut icon" href="https://assets.ubuntu.com/v1/49a1a858-favicon-32x32.png" type="image/x-icon" /> | ||
</head> | ||
<body className={inter.className}> | ||
<div className="l-application" role="presentation"> | ||
<Navigation /> | ||
<main className="l-main"> | ||
<div className="p-panel"> | ||
{backendAvailable === null && ( | ||
<Loader text="Loading..." /> | ||
)} | ||
{backendAvailable === false && ( | ||
<PageContent> | ||
<Notification severity="negative" title="Error"> | ||
{"Backend not available"} | ||
</Notification> | ||
</PageContent> | ||
)} | ||
{backendAvailable === true && ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
)} | ||
</div> | ||
<footer className="l-footer--sticky p-strip--light"> | ||
<Row> | ||
<p> | ||
© 2023 Canonical Ltd. <a href="#">Ubuntu</a> and{" "} | ||
<a href="#">Canonical</a> are registered trademarks of Canonical | ||
Ltd. | ||
</p> | ||
<List | ||
items={[ | ||
<a key="Legal information" href="https://ubuntu.com/legal"> | ||
Legal information | ||
</a>, | ||
]} | ||
middot | ||
/> | ||
</Row> | ||
</footer> | ||
</main> | ||
</div> | ||
</body> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,8 +1 @@ | ||
import type { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
title: "SD Core", | ||
description: "SD Core NMS", | ||
}; | ||
|
||
export default function Page() {} |
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
Oops, something went wrong.