How to use the swagger-parser.dereference function in swagger-parser

To help you get started, we’ve selected a few swagger-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egovernments / egov-services / web / spec-directory / server.js View on Github external
] = {};
            uniqueKeyObj[allModule.toLowerCase()][allMaster.toLowerCase()] =
              allModuleData[allModule][allMaster].uniqueKeys;
          }
        }
      }
      // console.log(uniqueKeyObj);
    }
  }
);

// console.log(specificHeaderObj);

// for(module in modules){
for (var i = 0; i < urls.length; i++) {
  SwaggerParser.dereference(urls[i])
    .then(function(yamlJSON) {
      // console.log(yamlJSON)
      let module = yamlJSON["x-module"];
      if (module) {
        mainObj[module] = yamlJSON.definitions;
      } else {
        let basePath = [];
        basePath = yamlJSON.basePath.split("-")[0].split(""); // "/asset-services" type pattern should be in basepath
        let index = basePath.indexOf("/");
        if (index > -1) {
          basePath.splice(index, 1);
        }

        mainObj[basePath.join("")] = yamlJSON.definitions;
      }
github anttiviljami / openapi-backend / src / backend.ts View on Github external
public async init() {
    try {
      // parse the document
      this.document = await SwaggerParser.parse(this.inputDocument);

      // validate the document
      this.validateDefinition();

      // dereference the document into definition
      this.definition = await SwaggerParser.dereference(this.document);
    } catch (err) {
      if (this.strict) {
        // in strict-mode, fail hard and re-throw the error
        throw err;
      } else {
        // just emit a warning about the validation errors
        console.warn(err);
      }
    }

    // build schemas for all operations
    const operations = this.getOperations();
    operations.map(this.buildSchemaForOperation.bind(this));

    // now that the definition is loaded and dereferenced, we are initalized
    this.initalized = true;
github egovernments / egov-services / web / ui-auto-gen / server.js View on Github external
let parse = function(yamlPath, module, references, cb) {
    mkdirp.sync("./output/" + module);
    SwaggerParser.dereference(yamlPath)
        .then(function(yamlJSON) {
            let basePath = yamlJSON.basePath;
            let specifications = {};
            let allUiInfo = {};
            let errors = {};
            for (var i = 0; i < yamlJSON["x-ui-info"].UIInfo.length; i++) {
                if(references && references.length) {
                    if (references.indexOf(yamlJSON["x-ui-info"].UIInfo[i].referencePath) > -1) 
                        allUiInfo[yamlJSON["x-ui-info"].UIInfo[i].referencePath] = yamlJSON["x-ui-info"].UIInfo[i];
                } else {
                    allUiInfo[yamlJSON["x-ui-info"].UIInfo[i].referencePath] = yamlJSON["x-ui-info"].UIInfo[i];
                }
            }
            for (let key in yamlJSON.paths) {
                let arr = key.split("/");
                arr.splice((arr.length - 1), 1);
github dzdrazil / swagger-mock-api / src / index.js View on Github external
let parserPromise = new Promise((resolve) => {
    parser.dereference(config.swaggerFile, function(err, api) {
      if (err) throw err;

      init(api);
      resolve();
    });
  });
github stoplightio / api-spec-converter / lib / importers / swagger.js View on Github external
parser.parse(dataOrPath, options, function(err, api) {
    if (err) {
      cb(err);
    } else {
      var apiData = JSON.parse(JSON.stringify(api));

      me.data = api;

      if (typeof dataOrPath === 'string') {
        var parseFn = parser.dereference(dataOrPath, JSON.parse(JSON.stringify(api)), options);
      } else {
        parseFn = parser.dereference(JSON.parse(JSON.stringify(api)), options);
      }

      parseFn.then(function(dereferencedAPI) {
        if (options && options.expand) {
          me.data = dereferencedAPI;
        } else {
          me.dereferencedAPI = dereferencedAPI;
        }
        cb();
      })
      .catch(cb);
    }
  });
};
github saasify-sh / saasify / packages / saasify-utils / lib / parse-openapi.js View on Github external
module.exports = async (spec) => {
  const bundle = await parser.bundle(spec)
  const api = await parser.dereference(cloneDeep(spec))

  if (semver.major(api.openapi) !== 3) {
    throw new Error('OpenAPI spec must conform to version 3')
  }

  for (const path of Object.keys(api.paths)) {
    const pathItem = api.paths[path]

    if (path[0] !== '/') {
      throw new Error(`Invalid path "${path}" must start with "/"`)
    }

    const name = path.slice(1)

    if (name && !validators.service(name)) {
      if (name.includes('/')) {
github notaryio / notary / packages / notary-rest / src / parser.js View on Github external
parse: async (contract) => {
    return SwaggerParser.dereference(
      await parser.swaggerFile(contract),
      { baseDir: contract.localContentPath }
    );
  },
github DataFire / DataFire / distribution / lib / swagger-client.js View on Github external
SwaggerParser.parse(self.swagger).then(function (data) {
    return SwaggerParser.dereference(data);
  }).then(function (data) {
    for (var path in data.paths) {
github grommet / grommet-swagger / src / GrommetSwagger.js View on Github external
parserUtil = async (data) => {
    const parsedRefs = await SwaggerParser.bundle(deepClone(data));
    const parsedSwagger = await SwaggerParser.dereference(deepClone(data));
    return { parsedSwagger, parsedRefs };
  }
  onLoad = (url, theme) => {
github EricHenry / swagger-data-gen / index.js View on Github external
function successfulParse(parsedApi) {
  var swaggerDoc = parsedApi;

  swaggerDoc.definitions = requireAllProperties(swaggerDoc.definitions);

  return SwaggerParser.dereference(swaggerDoc);
}

swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser and validator for Node and browsers

MIT
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis