Giter Site home page Giter Site logo

Comments (8)

ryanli-me avatar ryanli-me commented on June 26, 2024 2

hey, it's been a while, but i think @jonmiles had it right. getStaticProps always builds every route (whether in /pages/ or not). however if we only generate doc withwithSwagger like https://github.com/jellydn/next-swagger-doc/blob/main/example/pages/api/doc.ts, the resulting doc page will not have any schema (https://next-swagger-doc-demo.productsway.com/api/doc.)

from next-swagger-doc.

jellydn avatar jellydn commented on June 26, 2024

Thanks for reporting this issue. I will look into soon.

from next-swagger-doc.

ryanli-me avatar ryanli-me commented on June 26, 2024

I ended up just moving those comment to /pages/api and point schemafolder to /pages/api. only caveat is having to put the on the handler otherwise will not get into the final build. find it here https://github.com/cyberconnecthq/cyberprofile

from next-swagger-doc.

jellydn avatar jellydn commented on June 26, 2024

I found that you've used the old version. Could you try to use the latest one? Let me know if that works for you. Thanks.

https://github.com/cyberconnecthq/cyberprofile/blob/3cd7b9978e/package.json#L28

from next-swagger-doc.

jellydn avatar jellydn commented on June 26, 2024

Demo site shows this behavior. Both have same definition that includes schema but https://next-swagger-doc-demo.productsway.com/ has no schemas while https://next-swagger-doc-demo.productsway.com/api-doc has all schema

You would see the way to scan model schema works here https://next-swagger-doc-demo.productsway.com/api-doc

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

const SwaggerUI = dynamic<{
  spec: Record<string, any>;
}>(import('swagger-ui-react'), { ssr: false });

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

export const getStaticProps: GetStaticProps = async () => {
  const spec: Record<string, any> = createSwaggerSpec({
    apiFolder: 'pages/api',
    schemaFolders: ['models'],
    definition: {
      openapi: '3.0.0',
      info: {
        title: 'Next Swagger API Example',
        version: '1.0',
      },
    },
  });

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

export default ApiDoc;

This component works as expected as NextJs will call getStaticProps on build process.

from next-swagger-doc.

jellydn avatar jellydn commented on June 26, 2024

Just FYI, I've added a new CLI tool for this package which generated swagger then you could use with any swagger UI tool. You could check out the readme (usage 3) and example app for more detail.

https://next-swagger-doc-demo.productsway.com/playground#/

from next-swagger-doc.

jonmiles avatar jonmiles commented on June 26, 2024

You would see the way to scan model schema works here https://next-swagger-doc-demo.productsway.com/api-doc

I'm also hitting this issue and unable to resolve.

I read your previous post but you're mistaken, the example is not actually working as you describe. It's only working because SwaggerUI is reading from a static file named swagger.json in the public folder.

If you look closer at the actual generated api here; https://next-swagger-doc-demo.productsway.com/api/doc. You'll see components is missing the required schemas.

May be you could take another look, I'd really love to know how to fix it.

from next-swagger-doc.

hrvojepavlinovic avatar hrvojepavlinovic commented on June 26, 2024

This indeed is an issue, it works with swagger UI, but it doesn't when you use withSwagger handler.

import { withSwagger } from 'next-swagger-doc'
import { openapiDescription } from '../../utils/openapi-config' // schemaFolders: ['models']

const swaggerHandler = withSwagger(openapiDescription)

export default swaggerHandler()

This works in dev mode, but when you build app, models directory gets lost, and you end up with empty components.

My workaround was to build spec using cli and serve static file.

from next-swagger-doc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.