Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example must be updated #230

Closed
mbrain-io opened this issue Apr 21, 2022 · 1 comment
Closed

Example must be updated #230

mbrain-io opened this issue Apr 21, 2022 · 1 comment

Comments

@mbrain-io
Copy link

mbrain-io commented Apr 21, 2022

@jellydn Because of newest swagger-ui-react, this example must be updated.

Otherwise current example produces this error.

This code works with the newest swagger-ui-react:

import { GetStaticProps, InferGetStaticPropsType } from 'next';
import dynamic from "next/dynamic";
import { createSwaggerSpec } from 'next-swagger-doc';
import 'swagger-ui-react/swagger-ui.css';

const SwaggerUI = dynamic(import('swagger-ui-react'), { ssr: false });

const ApiDoc = ({ spec }: InferGetStaticPropsType<typeof getStaticProps>) => {
    return (
        <SwaggerUI spec={spec} />
    );
};

export const getStaticProps: GetStaticProps = async ctx => {
    const spec: Record<string, any> = createSwaggerSpec({
        definition: {
            openapi: '3.0.0',
            info: {
                title: 'NextJS Swagger',
                version: '0.1.0',
            },
        },
    });

    return {
        props: {
            spec,
        },
    };
};

export default ApiDoc;
@jellydn
Copy link
Owner

jellydn commented Apr 21, 2022

Thanks @mbrain-io Closed by 931514e

@jellydn jellydn closed this as completed Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants