Comments (8)
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.
Thanks for reporting this issue. I will look into soon.
from next-swagger-doc.
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.
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.
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 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.
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.
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.
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)
- Module not found: Can't resolve '#apg-lite' HOT 1
- Issue with parameters and swcMinify HOT 2
- Example or Docs required to explain how to specify params?
- api doesn't load component on production HOT 9
- Compatibility issues with NodeJS 16+ (version 19.7.0 / 16.19.1) on Windows, Ubuntu, and Heroku
- `Argument of type 'Promise<typeof import("...@types/swagger-ui-react/index")>' is not assignable to parameter of type 'DynamicOptions<{ spec: any; }> | Loader<{ spec: any; }>'. HOT 1
- Authorize using Bearer or OAuth2 HOT 1
- How to manage multiple HTTP methods
- Theme | no light mode support ? HOT 1
- Next13 example project running issue HOT 4
- Swagger annotations $ref as string HOT 1
- Automated doc generation HOT 6
- Where to keep the schema.json file in next.js project?
- Not working on Next 13 HOT 1
- Issue when using different directory such as src HOT 1
- Swagger Specs Never Read HOT 4
- Empty paths in rendered JSON in Production (on Vercel) but not in Dev with NextJS 14 HOT 1
- README Documentation has a missing dependency HOT 2
- Error with yarn build with Next 14 HOT 3
- Error on build - Next.js 14 - TypeError: Class extends value undefined is not a constructor or null HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-swagger-doc.