scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.42k stars 225 forks source link

Loading swagger.json from url parsing error. Misinterpreting as YAML? #345

Closed guilhermewerner closed 1 year ago

guilhermewerner commented 1 year ago

I'm trying to load the openapi spec from an url, but a parse error occurs, and if I download the spec and require the json, everything works normally.

An error appears in the console about parse of yaml, and the file is a json, the api returns the mime type as normal json and everything.

const express = require("express");
const swaggerUi = require("swagger-ui-express");

const PORT = parseInt(process.env.PORT || "5502");

const app = express();

const options = {
    explorer: true,
    swaggerOptions: {
        urls: [
            {
                url: "http:/localhost:5000/swagger.json",
                name: "TribuFu Services v1"
            }
        ]
    }
};

app.use("/", swaggerUi.serve, swaggerUi.setup(null, options));

app.listen(PORT, () => {
    console.log(`Server listen on port: ${PORT}`);
});

image

guilhermewerner commented 1 year ago

My bad, it was syntax error and after that cors. Sorry for the inconvenience.