How to use the json-schema-ref-parser.dereference function in json-schema-ref-parser

To help you get started, we’ve selected a few json-schema-ref-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 cdimascio / express-openapi-validator / src / framework / index.ts View on Github external
// Because of this issue ( https://github.com/APIDevTools/json-schema-ref-parser/issues/101#issuecomment-421755168 )
    // We need this workaround ( use '$RefParser.dereference' instead of '$RefParser.bundle' ) if asked by user
    if (typeof filePath === 'string') {
      const origCwd = process.cwd();
      const specDir = path.resolve(origCwd, path.dirname(filePath));
      const absolutePath = path.resolve(origCwd, filePath);
      if (fs.existsSync(absolutePath)) {
        // Get document, or throw exception on error
        try {
          process.chdir(specDir);
          const docWithRefs = jsYaml.safeLoad(
            fs.readFileSync(absolutePath, 'utf8'),
            { json: true },
          );
          return $refParser.mode === 'dereference'
            ? $RefParser.dereference(docWithRefs)
            : $RefParser.bundle(docWithRefs);
        } finally {
          process.chdir(origCwd);
        }
      } else {
        throw new Error(
          `${this.loggingPrefix}spec could not be read at ${filePath}`,
        );
      }
    }
    return $refParser.mode === 'dereference'
      ? $RefParser.dereference(filePath)
      : $RefParser.bundle(filePath);
  }
github ExpressGateway / express-gateway / lib / services / credentials / credential.service.js View on Github external
const uuid62 = require('uuid62');
const uuidv4 = require('uuid/v4');
const refParser = require('json-schema-ref-parser');
const mergeAllOf = require('json-schema-merge-allof');
const utils = require('../utils');
const config = require('../../config');
const { validate } = require('../../../lib/schemas');
const credentialDao = require('./credential.dao.js');

const s = {};

const dereferencePromise = refParser.dereference(config.models.credentials).then(derefSchema => mergeAllOf(derefSchema));

s.insertScopes = function (scopes) {
  return validateNewScopes(scopes)
    .then(newScopes => {
      if (!newScopes) {
        return true; // no scopes to insert
      }

      return credentialDao.insertScopes(newScopes).then(v => !!v);
    });
};

s.removeScopes = function (scopes) {
  return credentialDao.removeScopes(scopes).then(v => !!v);
};
github IBM / openapi-validator / test / plugins / validation / 2and3 / security-definitions-ibm.js View on Github external
schemas: {
            SecuritySchemeModel: {
              type: 'http',
              scheme: 'basic',
              descriptions: 'example text for def with unused security def'
            }
          },
          securitySchemes: {
            scheme1: {
              $ref: '#/components/schemas/SecuritySchemeModel'
            }
          }
        }
      };

      const resolvedSpec = await resolver.dereference(spec);

      const res = validate({ resolvedSpec, isOAS3: true }, config);
      expect(res.errors.length).toEqual(0);
      expect(res.warnings.length).toEqual(1);
      expect(res.warnings[0].message).toEqual(
        'A security scheme is defined but never used: scheme1'
      );
    });
    it('should warn about an unused security definition', function() {
github loganvolkers / json-schema-resolve-allof / test / composition.js View on Github external
function resolve(obj){
  return refParser.dereference(obj).then(spec => resolveAllOf(spec));
}
github mobilcom-debitel / got-swag / test / monkeyRequest.js View on Github external
before( function () {
    return parser.dereference( 'http://petstore.swagger.io/v2/swagger.json' )
      .then( function ( api_ ) {
        api = gotSwag.annotateApi( api_ );
        gotSwag.scanApiVars( api, memory );
      } );
  } );
github loganvolkers / json-schema-resolve-allof / test / alltests.js View on Github external
function importedComplexYamlTestCase(input, expected, done){
  var inputobj = requireYaml(input);
  var expectedobj = requireYaml(expected);
  
  refParser.dereference(inputobj)
  .then(function(schema) {
    resolveAllOf(schema).should.deep.equal(expectedobj);
    done();
  })
  .catch(done);
}
github mobilcom-debitel / got-swag / test / auth.js View on Github external
before( function () {
    return parser.dereference( 'http://petstore.swagger.io/v2/swagger.json' )
      .then( function ( api_ ) {
        api = api_;
      } );
  } );
github discourse / discourse_api_docs / server.js View on Github external
fs.readFile('swagger.yml', 'utf8', function(err, data) {
    if (err) throw err;
    var json = yaml.parse(data);
    refParser.dereference(json, function(err, schema) {
      if (err) {
        console.error(err);
      } else {
        res.send(schema);
      }
    });
  });
});
github davidedantonio / create-fastify-app / lib / bundler.js View on Github external
async function dereference (json) {
  return RefParser.dereference(json, {
    dereference: {
      circular: 'ignore'
    }
  })
}
github twskj / pretty-swag / pretty-swag.js View on Github external
function parseV2(obj, dst, config, callback) {

    $RefParser.dereference(obj, function (err, input) {

        if (err) {
            return callback(err);
        }

        try {
            var marked_opt = {
                renderer: new marked.Renderer(),
                gfm: true,
                tables: true,
                breaks: false,
                pedantic: false,
                sanitize: true,
                smartLists: true,
                smartypants: false
            };