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.41k stars 225 forks source link

4.3.* version produces skew reference on mult-file schema #282

Closed Warkanlock closed 2 years ago

Warkanlock commented 2 years ago

I've using swagger-ui-express for a while under version 4.1.4

Today, after upgrading packages I found that 4.3.* produces warning messages about null-reference and missing schema errors.

I'm using a multi-file spec as a .js file, looking like:

module.exports = {
  openapi: "3.0.0",
  info: {
    version: "1.0.0",
    title: "API",
  },
  paths: {
    ...require("./paths/A/{name}.spec"),
    ...require("./paths/B/{name}.spec"),
    ...require("./paths/C/{name}.spec"),
  },
  tags: require("./tags"),
  components: {
    schemas: require("./schema"),
    securitySchemes: {
         ...
    },
  },
};

The error looks like the following snippet but the list is for every spec I defined:

  {
    "keyword": "required",
    "dataPath": ".paths[]['post'].requestBody",
    "schemaPath": "#/definitions/Reference/required",
    "params": {
      "missingProperty": "$ref"
    },
    "message": "should have required property '$ref'"
  },
  {
    "keyword": "oneOf",
    "dataPath": ".paths[]['post'].requestBody",
    "schemaPath": "#/properties/requestBody/oneOf",
    "params": {
      "passingSchemas": null
    },
    "message": "should match exactly one schema in oneOf"
  }

Anyone experiencing this kind of issue? I can try to fix it but I don't know if there's any dev involved in a breaking change to this specific part of the library

Warkanlock commented 2 years ago

Nevermind, if you convert the whole object to an JSON.stringify() and pass it to the setup you will get what you want :smile: