maxdome / swagger-combine

Combines multiple Swagger schemas into one dereferenced schema.
MIT License
132 stars 36 forks source link

swaggerCombine function "format" option not working #91

Open Mcourt opened 4 years ago

Mcourt commented 4 years ago

Describe the bug

When using the swaggerCombine function in javascript with dynamic configuration, the { format : 'yaml' } is not taken into account, and a json is still being returned.

To Reproduce

  1. Given the following code :
const swaggerJson = {
  swagger: "2.0",
  info: {
    title: "Swagger Combine Rename by regular expression Example",
    version: "1.0.0"
  },
  apis: [
    {
      url: "http://petstore.swagger.io/v2/swagger.json",
      paths: {
        rename: [
          { 
            type: "regex",
            from: /\/pet\/(.*)/,
            to: "/pet/alive/$1"
          },
          { 
            type: "function",
            to: (path) => path === "/pet/alive/{petId}" ? "/pet/alive/{petAliveId}" : path
          }
        ]
      }
    },
    {
      url: "https://api.apis.guru/v2/specs/medium.com/1.0.0/swagger.yaml"
    }
  ]
}

swaggerCombine(swaggerJson, { format: 'yaml' }, (err, result) => {
  if(err){
    console.log(err);
    return;
  }

  console.log(result); // "result" is still a json object
}  )

Expected behavior The swaggerCombine callback should have the combined schema in yml format as parameter.

Additional context I might be wrong, but it seems the "toString()" method of the SwaggerCombine class is never called.