Giter Site home page Giter Site logo

Comments (9)

octavioamu avatar octavioamu commented on July 24, 2024 1

@jellydn Thanks for responding.
That is because the api-doc is using the static generated file swagger.json which is the 3rd option.
Same with the playground for example if you where using the 2nd to generate an api/doc probably because you want 3rd parties UI with the schemas you would use it like:

<APIDocumentUI
          apiDescriptionUrl="/api/doc"
          layout="sidebar"
          router="hash"
/>

Instead of the static one https://github.com/jellydn/next-swagger-doc/blob/main/examples/example/pages/playground.tsx#L51

A good way to test it is looking the api/doc endpoint I posted https://next-swagger-doc-demo.productsway.com/api/doc
when you run locally you will see the data will be in place when going localhost:3000/api/doc, even if you run yarn build and then yarn start api/doc will have the components schema there, which is really weird that got removed when deployed on vercel.

Spent my day yesterday testing different approach to try to see if I could make the api/doc append the schemas as local without good luck :( .

Let me know if you need some other info or I can help in any way, I will keep fighting it and post here if I realize something else.
Thanks!!

from next-swagger-doc.

octavioamu avatar octavioamu commented on July 24, 2024 1

Also because is working on local with "yarn build" and not in vercel (that runs by default the same command) which is very strange my high guess is have something todo with async code on the server taking more time than local and for that not being appended. But again, really high guess.

Adding also my project urls just in case
https://public-api-git-feat-swagger-windranger.vercel.app/api-doc (working fine)
https://public-api-git-feat-swagger-windranger.vercel.app/api/doc (empty component on prod)
https://public-api-git-feat-swagger-windranger.vercel.app/playground (use api/doc so on prod no schema are showed)

from next-swagger-doc.

octavioamu avatar octavioamu commented on July 24, 2024 1

Interesting I tried with vercel-cli to avoid deploying each time, and worked, but now that Im thinking I didn't remove the folders created by yarn dev, so maybe on my local is working because still fetching from the other folders previously created.

edit: from tests I did nextjs doesn't seems to remove comments so seems that is not the problem I believe the problem is on the path to the files. api-doc page works perfectly as it fetch the data on build time, is able to read the files and generate the static data served. The reason of that working is because is using getStaticProps which looks into the public folder /files without problem.

from next-swagger-doc.

jellydn avatar jellydn commented on July 24, 2024

Thanks, @octavioamu it does work on the demo https://next-swagger-doc-demo.productsway.com/api-doc. I will check tonight or so for the API endpoint.

from next-swagger-doc.

octavioamu avatar octavioamu commented on July 24, 2024

I think I know what is going on, you are using process.cwd() https://github.com/jellydn/next-swagger-doc/blob/main/src/swagger.ts#L39 I added a console log on the /api/doc endpoint and this is what cwd is on vercel as function are actually edge functions /var/task so the problem is how is being routed to find paths, the public folder is already "/" so probably doesn't need pwd to find the path and could go relative instead of absolute

more about this topic
vercel/next.js#36031
https://nextjs.org/docs/advanced-features/output-file-tracing
diff approach to go around this issue
vercel/next.js#32236

from next-swagger-doc.

octavioamu avatar octavioamu commented on July 24, 2024

I keep digging on this, one little suggestion is change join() to resolve() at least seems will be more secure if people input '/models/' on schemaFolders

from next-swagger-doc.

octavioamu avatar octavioamu commented on July 24, 2024

no, resolve doesn't solve it, this is the server log of urls getting generated with resolve

[GET] /api/doc
15:55:31:07
process.cwd() 1 /var/task
apiss [
  '/var/task/pages/api/**/*.ts',
  '/var/task/pages/api/**/*.tsx',
  '/var/task/pages/api/**/*.jsx',
  '/var/task/pages/api/**/*.js',
  '/var/task/pages/api/**/*.json',
  '/var/task/pages/api/**/*.swagger.yaml',
  '/var/task/.next/server/pages/api/**/*.js',
  '/var/task/.next/server/pages/api/**/*.swagger.yaml',
  '/var/task/.next/server/pages/api/**/*.json',
  '/var/task/public/**/*.swagger.yaml',
  '/var/task/public/**/*.json',
  '/types/**/*.ts',
  '/types/**/*.tsx',
  '/types/**/*.jsx',
  '/types/**/*.js',
  '/types/**/*.json',
  '/types/**/*.swagger.yaml',
  '/types/**/*.js',
  '/types/**/*.swagger.yaml',
  '/types/**/*.json',
  '/var/task/public/**/*.swagger.yaml',
  '/var/task/public/**/*.json'
]

The created structure on vercel
image

from next-swagger-doc.

jellydn avatar jellydn commented on July 24, 2024

I think we could have possible solutions here:

  • 1st solution: as far I as know, NextJs will remove comment on build project (next build) so we need to find a way to keep the comment code for generate swagger spec
  • 2nd solution: write a custom Webpack plugin to generate swagger file on build

from next-swagger-doc.

jellydn avatar jellydn commented on July 24, 2024

Hi @octavioamu I've just released version from #639 Could you take a try again? Thanks.

Also updated example aps.
0106836

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.