Freddy Bonda
Freddy Bonda

Reputation: 1259

Swagger error swaggerDocument = require('./swagger.yaml');

I really don't like that Swagger has literally no documentation out there. If anyone knows of a good alternative to Swagger, please let me know. Anyways.

swaggerDocument = require('./swagger.yaml');

I am trying to get my Swagger UI to host correctly. I have tested this line with swagger.json, then my json works fine. But when I test it with yaml, the I get this error:

(function (exports, require, module, __filename, __dirname) { openapi: 3.0.0
                                                                          ^^
SyntaxError: Unexpected number

Here is my swagger.json:

openapi: 3.0.0
info:
  title: Feedback API
  version: 1.0.0
servers:
  - url: http://197.189.225.218:{port}/VBS
    description: Dev

Can anyone help me understand why this is not working. Thank you :)

Upvotes: 1

Views: 1116

Answers (1)

Freddy Bonda
Freddy Bonda

Reputation: 1259

Ok I found a solution. You need to install a yamp to json converter by running npm install --save yamljs

Then replace the swaggerDocument = require('./swagger.yaml'); line with:

YAML = require('yamljs');
swaggerDocument = YAML.load('./swagger.yaml');

I found the answer here: https://www.npmjs.com/package/swagger-ui-express

Upvotes: 2

Related Questions