|
1 | 1 | # Welcome to next-swagger-doc 👋
|
2 | 2 |
|
3 | 3 | <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
| 4 | + |
4 | 5 | [](#contributors-)
|
| 6 | + |
5 | 7 | <!-- ALL-CONTRIBUTORS-BADGE:END -->
|
6 | 8 |
|
7 | 9 | [](https://npmjs.org/package/next-swagger-doc)
|
@@ -44,25 +46,29 @@ yarn add next-swagger-doc swagger-ui-react
|
44 | 46 |
|
45 | 47 | ```typescript
|
46 | 48 | import { GetStaticProps, InferGetStaticPropsType } from 'next';
|
47 |
| - |
48 | 49 | import { createSwaggerSpec } from 'next-swagger-doc';
|
49 |
| -import SwaggerUI from 'swagger-ui-react'; |
| 50 | +import dynamic from 'next/dynamic'; |
50 | 51 | import 'swagger-ui-react/swagger-ui.css';
|
51 | 52 |
|
52 |
| -const ApiDoc = ({ spec }: InferGetStaticPropsType<typeof getStaticProps>) => { |
| 53 | +const SwaggerUI = dynamic<{ |
| 54 | + spec: any; |
| 55 | +}>(import('swagger-ui-react'), { ssr: false }); |
| 56 | + |
| 57 | +function ApiDoc({ spec }: InferGetStaticPropsType<typeof getStaticProps>) { |
53 | 58 | return <SwaggerUI spec={spec} />;
|
54 |
| -}; |
| 59 | +} |
55 | 60 |
|
56 |
| -export const getStaticProps: GetStaticProps = async ctx => { |
| 61 | +export const getStaticProps: GetStaticProps = async () => { |
57 | 62 | const spec: Record<string, any> = createSwaggerSpec({
|
58 | 63 | definition: {
|
59 | 64 | openapi: '3.0.0',
|
60 | 65 | info: {
|
61 |
| - title: 'NextJS Swagger', |
62 |
| - version: '0.1.0', |
| 66 | + title: 'Next Swagger API Example', |
| 67 | + version: '1.0', |
63 | 68 | },
|
64 | 69 | },
|
65 | 70 | });
|
| 71 | + |
66 | 72 | return {
|
67 | 73 | props: {
|
68 | 74 | spec,
|
|
0 commit comments