maxdome / swagger-combine

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

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

Open williamboman opened 5 years ago

williamboman commented 5 years ago

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

fabsrc commented 5 years ago

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?

gavmck commented 5 years ago

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!

fbacker commented 4 years ago

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 commented 4 years ago

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