Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

2.2K
Visualizações
Next.js with Swagger

Is there a way to have a swagger documentation for NEXT.js API routes? I'm using Next.js for both front-end and back-end development and I want to have a swagger documentation for the APIs I develop with Next.js.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can use the following project to bootstrap the integration between Next.js and Swagger

  • https://github.com/jellydn/next-swagger-doc
  • https://www.npmjs.com/package/next-swagger-doc
  • Demo
yarn add next-swagger-doc swagger-ui-react
import { GetStaticProps, InferGetStaticPropsType } from 'next';

import { createSwaggerSpec } from 'next-swagger-doc';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';

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

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

export default ApiDoc;

The actual definition of a Next.js API route endpoint looks like this:

/**
 * @swagger
 * /api/hello:
 *   get:
 *     description: Returns the hello world
 *     responses:
 *       200:
 *         description: hello world
 */
const handler = (_req: NextApiRequest, res: NextApiResponse) => {
  res.status(200).json({
    result: 'hello world',
  });
};
over 4 years ago · Santiago Trujillo Relatório

0

I made a little npm library that auto-generates Swagger docs from your NextJS project. No user input needed!

Still very Beta but hope it's useful. https://www.npmjs.com/package/nextjs-routes-docs

Just run

npx nextjs-routes-docs [dir]
over 4 years ago · Santiago Trujillo Relatório

0

You got to have the swagger json files or specification for the APIS and can use libs such as Swagger UI or Redoc

Using Redoc you can do a /doc/[slug].js and do dynamic fetching on the .json or yaml files for your documentation (or swagger ui)

This website: https://openapi.tools/ , has a lot of tools for React and OpenAPI in general that you can use it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda