-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
withSwagger doesn't include schema stored in non /pages/ folder to serve in vercel #246
Comments
Thanks for reporting this issue. I will look into soon. |
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 |
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 |
You would see the way to scan 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 |
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. |
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 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. |
hey, it's been a while, but i think @jonmiles had it right. |
This indeed is an issue, it works with swagger UI, but it doesn't when you use withSwagger handler.
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. |
following up on #26, where the fix was to include
.next/server
in file search. However, models defined in/models/
or non/pages/
directories are not picked up.Demo site shows this behavior. Both have same definition that includes schema but
https://next-swagger-doc-demo.productsway.com/
has no schemas whilehttps://next-swagger-doc-demo.productsway.com/api-doc
has all schemasThe text was updated successfully, but these errors were encountered: