open-api icon indicating copy to clipboard operation
open-api copied to clipboard

args.apiDoc not working when given a path to yaml

Open ivan416 opened this issue 6 years ago • 4 comments

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?

ivan416 avatar May 24 '19 17:05 ivan416

I'll bump this.

wittenator avatar Oct 30 '19 07:10 wittenator

please submit a pr

jsdevel avatar Oct 31 '19 16:10 jsdevel

It seems that this bug has been fixed.

IvanaGyro avatar Dec 05 '19 13:12 IvanaGyro

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.

prodigitalson avatar Mar 18 '24 23:03 prodigitalson