open-api
open-api copied to clipboard
args.apiDoc not working when given a path to yaml
In the Getting Started section, there is a comment that if using yaml you can provide a path relative to process.cwd(), however this does not work.
// ./app.js
import express from 'express';
import { initialize } from 'express-openapi';
import v1WorldsService from './api-v1/services/worldsService';
import v1ApiDoc from './api-v1/api-doc';
const app = express();
initialize({
app,
// NOTE: If using yaml you can provide a path relative to process.cwd() e.g.
// apiDoc: './api-v1/api-doc.yml',
apiDoc: v1ApiDoc,
dependencies: {
worldsService: v1WorldsService
},
paths: './api-v1/paths'
});
app.listen(3000);
Looking at the handleFilePath method in utils.ts it seems that in case of passing a path to yaml file, the method would use require to try to load it. However require cannot be used to load a yaml file. It should go to a catch block and read the file fs.readFileSync(absolutePath, 'utf8').
In the sample project basic-usage-with-central-apiDoc provided, apiDoc is passed as apiDoc: fs.readFileSync(path.resolve(__dirname, 'api-doc.yml'), 'utf8').
Have I found a bug or was apiDoc parameter designed to not take string path?
I'll bump this.
please submit a pr
It seems that this bug has been fixed.
The Docs still say it should be possible, at least in the docs for args.operations its specifically given as the way to do this but i'm having the same issue.