How to use the json-refs.findRefs function in json-refs

To help you get started, we’ve selected a few json-refs 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 apigee-127 / swagger-tools / lib / specs.js View on Github external
_.each(composed.properties, function (property, name) {
      var oProp = original.properties[name];

      // Convert the string values to numerical values
      _.each(['maximum', 'minimum'], function (prop) {
        if (_.isString(property[prop])) {
          property[prop] = parseFloat(property[prop]);
        }
      });

      _.each(JsonRefs.findRefs(oProp, {
        includeInvalid: true,
        refPreProcessor: swagger1RefPreProcesor
      }), function (refDetails, refPtr) {
        var dMetadata = documentMetadata.definitions[refDetails.uri];
        var path = JsonRefs.pathFromPtr(refPtr);

        if (dMetadata.lineage.length > 0) {
          traverse(property).set(path, getOrComposeSchema(documentMetadata, refDetails.uri));
        } else {
          traverse(property).set(path.concat('title'), 'Composed ' + sanitizeRef(documentMetadata.swaggerVersion,
                                                                                 refDetails.uri));
        }
      });
    });
  }
github apigee-127 / swagger-tools / lib / specs.js View on Github external
var type = swaggerVersion === '1.2' ? 'Model' : 'Definition';

      if (iProperties.indexOf(name) === -1 && dProperties.indexOf(name) === -1) {
        createErrorOrWarning('MISSING_REQUIRED_' + type.toUpperCase() + '_PROPERTY',
                             type + ' requires property but it is not defined: ' + name,
                             defPath.concat(['required', index.toString()]), results.errors);
      }
    });
  });

  if (documentMetadata.swaggerVersion === '1.2') {
    jsonRefsOptions.refPreProcessor = swagger1RefPreProcesor;
  }

  // Process local references
  _.each(JsonRefs.findRefs(documentMetadata.original, jsonRefsOptions), function (refDetails, refPtr) {
    addReference(documentMetadata, refDetails.uri, refPtr, results);
  });

  // Process invalid references
  _.each(documentMetadata.referencesMetadata, function (refDetails, refPtr) {
    if (isRemotePtr(refDetails) && refDetails.missing === true) {
      results.errors.push({
        code: 'UNRESOLVABLE_REFERENCE',
        message: 'Reference could not be resolved: ' + sanitizeRef(documentMetadata.swaggerVersion, refDetails.uri),
        path: JsonRefs.pathFromPtr(refPtr).concat('$ref')
      });
    }
  });
};
github Azure / oav / lib / validators / specResolver.js View on Github external
if (!doc) {
      doc = self.specInJson;
    }
    if (!docPath) {
      docPath = self.specPath;
      docDir = self.specDir;
    }
    if (!docDir) {
      docDir = path.dirname(docPath);
    }
    if (filterType === 'all') {
      delete options.filter;
    }

    let allRefsRemoteRelative = JsonRefs.findRefs(doc, options);
    let promiseFactories = Object.keys(allRefsRemoteRelative).map(function (refName) {
      let refDetails = allRefsRemoteRelative[refName];
      return function () { return self.resolveRelativeReference(refName, refDetails, doc, docPath); };
    });
    if (promiseFactories.length) {
      return utils.executePromisesSequentially(promiseFactories);
    } else {
      return Promise.resolve(doc);
    }
  }
github Azure / oav / lib / util / jsonRefs.ts View on Github external
export const findRefs = (
  obj: object | ReadonlyArray,
  options?: jsonRefs.JsonRefsOptions
): sm.StringMap =>
  jsonRefs.findRefs(obj, options) as sm.StringMap
github Azure / oav / lib / wireFormatGenerator.ts View on Github external
private async resolveExamples(
    suppression: Suppression | undefined
  ): Promise> {
    const options = {
      relativeBase: this.specDir,
      filter: ["relative", "remote"]
    }

    const allRefsRemoteRelative = JsonRefs.findRefs(this.specInJson as object, options)
    const e = entries(allRefsRemoteRelative as StringMap)
    const promiseFactories = toArray(
      map(e, ([refName, refDetails]) => async () =>
        this.resolveRelativeReference(
          suppression,
          refName,
          refDetails,
          this.specInJson,
          this.specPath
        )
      )
    )
    if (promiseFactories.length) {
      return utils.executePromisesSequentially(promiseFactories)
    } else {
      return this.specInJson
github andrglo / koa-swagger-router / src / index.js View on Github external
methods[method] = spec.paths[path][method]
        } catch (error) {
          if (error.status !== 403) {
            throw error
          }
        }
      }

      if (Object.keys(methods).length) {
        paths[path] = methods
      }
    }

    const definitions = {}

    const refs = jsonRefs.findRefs(paths)

    Object.keys(refs).forEach(key => {
      const values = jsonRefs.pathFromPtr(refs[key].uri)
      const definition = values[1]
      definitions[definition] = spec.definitions[definition]
    })

    spec.paths = paths
    spec.definitions = definitions
    return spec
  }

json-refs

Various utilities for JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis