How to use the api-spec-converter.getSpec function in api-spec-converter

To help you get started, we’ve selected a few api-spec-converter 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 APIs-guru / openapi-directory / scripts / collection.js View on Github external
function validateSwagger(swagger, source) {
  let target = 'swagger_2';
  if (swagger.openapi) target = 'openapi_3';
  return converter.getSpec(swagger, target)
    .then(function(spec){
      var relativeBase = source.split('/');
      relativeBase.pop();
      relativeBase = relativeBase.join('/');
      // 'relativeBase' is for the released version of sway/json-refs, the latest version uses 'location'
      let jsonRefs = {relativeBase: relativeBase, location: source, loaderOptions: {processContent:
        function (res, cb) {
          cb(undefined, YAML.safeLoad(res.text,{json:true}));
        }
      }};
      if (source.indexOf('azure.com')>=0) {
        jsonRefs.includeInvalid = true;
        jsonRefs.resolveCirculars = true;
      }
      else {
        jsonRefs.includeInvalid = false;
github APIs-guru / openapi-directory / scripts / collection.js View on Github external
function writeSpec(source, format, exPatch, command) {
  var context = {source};
  resolverContext = {
    anyDiff: false,
    called: false,
    source: source,
    format: format,
    etag: !command.slow
  };

  return converter.getSpec(source, format)
    .then(spec => {
      context.spec = spec;
      if (resolverContext.called && !resolverContext.anyDiff)
        throw Error('Warning: 304 Not modified');
      var fixup = util.readYaml(getOriginFixupPath(spec));
      jsondiffpatch.patch(spec, fixup);

      return convertToSwagger(spec,exPatch,command);
    })
    .then(swagger => {
      context.swagger = swagger;

      delete exPatch.info.version; // testing
      patchSwagger(swagger, exPatch);

      expandPathTemplates(swagger);
github kyma-incubator / varkes / modules / openapi-mock / src / server / mock.ts View on Github external
async function transformSpec(api: config.API) {
    LOGGER.debug("Transforming spec of api '%s' to swagger2 format", api.name)
    return Converter.getSpec(api.specification, 'openapi_3')
        .then((fromSpec: any) => fromSpec.convertTo('swagger_2'))
}
github kyma-incubator / varkes / modules / openapi-mock / src / server / mock.ts View on Github external
async function validateSpec(api: config.API, type: string) {
    LOGGER.debug("Validating spec of api '%s'", api.name);
    return Converter.getSpec(api.specification, type)
        .then((fromSpec: any) => {
            return fromSpec.validate()
        }).then((result: any) => {
            if (result.errors) {
                throw new Error("Validation error of api '" + api.name + "':" + pretty_yaml.stringify(result.errors));
            }
            if (result.warnings) {
                LOGGER.warn("%s", pretty_yaml.stringify(result.warnings));
            }
        });
}

api-spec-converter

Convert API descriptions between popular formats such as OpenAPI(fka Swagger), RAML, API Blueprint, WADL, etc.

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis