swagger-combine
swagger-combine copied to clipboard
How to retain the `info` field from each API?
Hi! How can I retain the information about each API (the Info Object) in the produced output?
Unfortunately this is not possible in the current version. Maybe we'll implement this feature in the future. Could you please describe your use case or why you need the data from the info object?
Hey there, I also need this!
We have multiple swagger specs that are considered separate APIs by the company, but require a combined set of documentation so we can plug it into Redoc. I'm using swagger-combine to solve this, just needing the info section retained and it'll be perfect!
Maybe it could be possible if we could access the raw objects from swagger-combine after it's done? Trying to do about the same but configuring security schemas. Would like to not load all the external files again myself to solve this.
const swaggerCombine = require('swagger-combine');
swaggerCombine('config.json')
.then(res => {
// make special combines before exporting file, securitySchemas, info e.g.
// get all loaded documentations and loop
console.log(JSON.stringify(res));
})
.catch(err => console.error(err));
My solution became this
const fs = require('fs');
const SwaggerCombine = require('swagger-combine');
const output = 'parsed.json';
const config = 'config.json';
const opts = {};
const combinedSchemaData = new SwaggerCombine.SwaggerCombine(config, opts);
const postOutput = (schema)=>{
fs.writeFileSync(output, JSON.stringify(schema, null, 2));
console.log("done and happy");
}
const postProcess = (parsedObject)=>{
let obj = {...parsedObject.combinedSchema};
parsedObject.schemas.forEach((item)=>{
console.log("Add things to obj");
})
postOutput(obj);
}
combinedSchemaData.combine()
.then(result => {
postProcess(result);
})
.catch(error => {
console.error(error.message);
process.exit(1);
});