swagger-combine icon indicating copy to clipboard operation
swagger-combine copied to clipboard

How to retain the `info` field from each API?

Open williamboman opened this issue 6 years ago • 4 comments

Hi! How can I retain the information about each API (the Info Object) in the produced output?

williamboman avatar Oct 23 '18 11:10 williamboman

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?

fabsrc avatar Oct 31 '18 14:10 fabsrc

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!

gavmck avatar Apr 02 '19 11:04 gavmck

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));

fbacker avatar Mar 18 '20 13:03 fbacker

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);
    });

fbacker avatar Mar 18 '20 13:03 fbacker