How to use with import
vladshcherbin opened this issue · 5 comments
Hey 👋
Node 12+ has import
support, as soon as I change require
to import
openapi starts to generate nothing. Tested on repo example.
Is there a way to use this great package with imports?
I've also tried jsdoc-openapi (seems to be also yours one) and it works there. Not sure why there are duplicated packages and what's more stable to use.
jsdoc-openapi
was what we originally called it. We switched to openapi-comment-parser
this is the only package we actively publish.
I think the issue is that we bundle this as commonjs, but I think we also bundle an es module version. I’m honestly not too sure how to fix the bundling stuff though. This uses typescript so everything is using import
syntax, so I think fixing will just be a matter of tweaking the rollup config, or maybe we don’t even need rollup 🤷♂️
If you have any insights into this feel free to open a PR, otherwise I’ll do some research
Any updates on this ?
Faced same issue:
import openapi from 'openapi-comment-parser'
- generate empty spec
const openapi = require('openapi-comment-parser')
- works correctly
@Ilchuk-Mihail we use import openapi from 'openapi-comment-parser'
in our project. If it's generating a spec, but it's empty, I'm guessing that it isn't able to properly calculate the appropriate directory. Have you tried using the cwd
option?
I've had issues with paths when using typescript. Setting cwd
to __dirname
normally fixes any issues for me:
const spec = openapi({ cwd: __dirname });
@bourdakos1 This option works and fixed spec generation. Thank you!