Surnet/swagger-jsdoc

Load servers and info from yaml files

information-security opened this issue · 2 comments

I am not sure if this is an indented behavior or bug, so please feel free to re-label this to bug report.

Is your feature request related to a problem? Please describe.
I am not able to read a few parts of the spec from yaml files. For example (servers and info). But It is great that I can do this with other parts like tags and components.

Describe the solution you'd like
I want to split the spec into multiple yaml files. For instance, servers.yaml, tags.yaml, info.yaml, components.yaml, etc.
And afterward, I shall be able to initialize the SwaggerJSDoc like below.

const options: swaggerJSDoc.OAS3Options = {


	apis       : [ `${rootPath}/src/routes/**/*.js`, `${rootPath}/src/docs/swagger/*.yaml` ]
};

const swaggerSpec = swaggerJSDoc.default(options);

Describe alternatives you've considered
I am currently keeping the info and servers parts of the spec in a json file and then load it into the SwaggerJSDoc constructor.

const options: swaggerJSDoc.OAS3Options = {

	definition : config.swaggerDefinition as swaggerJSDoc.OAS3Definition,

	apis       : [ `${rootPath}/src/routes/**/*.js`, `${rootPath}/src/docs/swagger/*.yaml` ]
};

const swaggerSpec = swaggerJSDoc.default(options);

Additional context
N/A

Hi @information-security

Can you provide a repo where you reproduce the error related above?

Hi dear @daniloab

I have prepared a repo to reproduce the issue.

How to reproduce:

  1. Clone the repo
  2. yarn install
  3. yarn start
  4. Go to http://localhost:3000/docs
  5. You would see that info and servers are not loaded/parsed while tags and components/schemas are.

If you set loadFromYaml variable (Line 9) to false, then it loads the servers and info from the config file passed to the constructor.

Thanks for your time.