Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
williamboman opened this issue Oct 23, 2018 · 4 comments
Open

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

williamboman opened this issue Oct 23, 2018 · 4 comments
Labels

Comments

@williamboman
Copy link

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

@fabsrc
Copy link
Contributor

fabsrc commented Oct 31, 2018

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
Copy link

gavmck commented Apr 2, 2019

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
Copy link

fbacker commented Mar 18, 2020

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
Copy link

fbacker commented Mar 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants