How to use json-refs - 10 common examples

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 / sway / test / test-path.js View on Github external
it('should have proper structure', function () {
      var path = '/pet/{petId}';
      var pathObject = apiDefinition.getOperation(path, 'get').pathObject;

      assert.deepEqual(pathObject.apiDefinition, apiDefinition);
      assert.equal(pathObject.path, path);
      assert.equal(pathObject.ptr, JsonRefs.pathToPtr(['paths', path]));
      assert.deepEqual(pathObject.definition, apiDefinition.definitionRemotesResolved.paths[path]);
      assert.deepEqual(pathObject.definitionFullyResolved, apiDefinition.definitionFullyResolved.paths[path]);

      // Make sure they are of the proper type
      assert.ok(pathObject.regexp instanceof RegExp);

      // Make sure they have the proper keys
      assert.equal(1, pathObject.regexp.keys.length);
      assert.equal('petId', pathObject.regexp.keys[0].name);

      // Make sure they match the expected URLs
      assert.ok(_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/pet/1')));
      assert.ok(!_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/pets/1')));
      assert.ok(!_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/Pet/1')));
    });
github apigee-127 / sway / lib / versions / 2.0 / index.js View on Github external
cOperation.parameters = _.map(_.values(oParams), function (parameter) {
      // Used later by getOperationParameters to circumvent the chicken/egg situation (Removed there as well)
      parameter.definition.$$$ptr$$$ = JsonRefs.pathToPtr(parameter.path);

      return parameter.definition;
    });


    if (_.isUndefined(cOperation.security)) {
      cOperation.security = pathObject.api.resolved.security;
    }

    operations.push(new Operation(pathObject.api,
                                  pathObject,
                                  method,
                                  JsonRefs.pathToPtr(oPath),
                                  cOperation,
                                  cOperation.consumes || pathObject.api.resolved.consumes || [],
                                  cOperation.produces || pathObject.api.resolved.produces || []));
  });
github apigee-127 / sway / lib / validation / validators.js View on Github external
_.forEach(security, function (scopes, name) {
        var sdPath = ['securityDefinitions', name];
        var sdPtr = JsonRefs.pathToPtr(sdPath);
        var srPath = path.concat([index.toString(), name]);

        // Identify missing reference to the security definition
        if (_.indexOf(referenceable, sdPtr) === -1) {
          response.errors.push({
            code: 'UNRESOLVABLE_REFERENCE',
            message: 'Security definition could not be resolved: ' + name,
            path: srPath
          });
        } else {
          addReference(sdPtr, JsonRefs.pathToPtr(srPath));

          _.forEach(scopes, function (scope, sIndex) {
            var ssrPath = srPath.concat(sIndex.toString());
            var ssrPtr = JsonRefs.pathToPtr(sdPath.concat(['scopes', scope]));

            if (_.indexOf(referenceable, ssrPtr) === -1) {
              response.errors.push({
                code: 'UNRESOLVABLE_REFERENCE',
                message: 'Security scope definition could not be resolved: ' + scope,
                path: ssrPath
              });
            } else {
              addReference(JsonRefs.pathToPtr(sdPath.concat(['scopes', scope])), ssrPtr);
            }
          });
        }
github apigee-127 / swagger-tools / lib / specs.js View on Github external
_.each(model.subTypes, function (subType, index) {
          var subPath = ['models', subType];
          var subPtr = JsonRefs.pathToPtr(subPath);
          var subMetadata = documentMetadata.definitions[subPtr];
          var refPath = modelDefPath.concat(['subTypes', index.toString()]);

          // If the metadata does not yet exist, create it
          if (!subMetadata && documentMetadata.resolved[modelDefsProp][subType]) {
            subMetadata = getDefinitionMetadata(subPath);
          }

          // If the reference is valid, add the parent
          if (addReference(documentMetadata, subPath, refPath, results)) {
            subMetadata.parents.push(JsonRefs.pathToPtr(modelDefPath));
          }
        });
github apigee-127 / sway / lib / validation / validators.js View on Github external
var ptrPath = JsonRefs.pathFromPtr(ptr);

    if (!_.has(metadata, 'missing')) {
      // This reference is a document reference, record it for later
      if (['relative', 'remote'].indexOf(metadata.type) > -1 && metadata.fqURI.indexOf('#') === -1) {
        if (_.isUndefined(docReferences[metadata.fqURI])) {
          docReferences[metadata.fqURI] = [];
        }

        docReferences[metadata.fqURI].push(ptr);
      }

      addReference(metadata.fqURI, ptr);

      if (ptrPath[ptrPath.length - 2] === 'allOf') {
        addAncestor(JsonRefs.pathToPtr(ptrPath.slice(0, ptrPath.length - 2)), metadata.uri);
      }
    }
  });
github Bandwidth / node-bandwidth / tools / prepare-types.js View on Github external
async function main() {
	const openApiText = await readFile('openapi.yml', 'utf-8');
	const apiData = prepareApiData(
		(await resolveRefs(yaml.safeLoad(openApiText))).resolved
	);
	await mkdir('./dist').catch(() => {});
	await writeFile(
		'./dist/index.d.ts',
		`/// 
/// 
import {CancelToken} from 'axios';
${Object.keys(apiData)
			.map(o => printApiTypes(o, apiData[o]))
			.join('\n\n')}

${printTypes()}

export interface Bridges {
	/** Speak a sentence to the bridge */
	speakSentence(id: string, sentence: string, options?: SpeakSentenceOptions, cancelToken?: CancelToken): Promise;
github Bandwidth / node-bandwidth / tools / prepare-api-data.js View on Github external
async function main() {
	const openApiText = await readFile('openapi.yml', 'utf-8');
	const openapi = (await resolveRefs(yaml.safeLoad(openApiText))).resolved;
	const apiData = prepareApiData(openapi);
	await writeFile(
		'./lib/api-data.js',
		`// Generated automatically. Don't edit this file.
import * as Joi from 'joi';

export default {
	name: '${pack.name}',
	version: '${pack.version || openapi.info.version}',
	objects: {
${Object.keys(apiData)
			.map(o => printApiObject(o, apiData[o]))
			.join(',\n')}
	}
};`,
		'utf-8'
github apigee-127 / swagger-tools / lib / specs.js View on Github external
includeInvalid: true,
    loaderOptions: {
      processContent: function (res, callback) {
        callback(undefined, YAML.safeLoad(res.text));
      }
    }
  };

  if (!cacheEntry.resolved) {
    // For Swagger 1.2, we have to create real JSON References
    if (swaggerVersion === '1.2') {
      jsonRefsOptions.refPreProcessor = swagger1RefPreProcesor;
    }

    // Resolve references
    JsonRefs.resolveRefs(apiDOrSO, jsonRefsOptions)
      .then(function (results) {
        removeCirculars(results.resolved);

        // Fix circular references
        _.each(results.refs, function (refDetails, refPtr) {
          if (refDetails.circular) {
            _.set(results.resolved, JsonRefs.pathFromPtr(refPtr), {});
          }
        });

        cacheEntry.referencesMetadata = results.refs;
        cacheEntry.resolved = results.resolved;
        cacheEntry.resolvedId = SparkMD5.hash(JSON.stringify(results.resolved));

        callback();
      })
github apigee-127 / sway / index.js View on Github external
.then(function (remoteResults) {
      // Resolve local references (Remote references should had already been resolved)
      cOptions.jsonRefs.filter = 'local';

      return JsonRefs.resolveRefs(remoteResults.resolved || cOptions.definition, cOptions.jsonRefs)
        .then(function (results) {
          _.each(remoteResults.refs, function (refDetails, refPtr) {
            results.refs[refPtr] = refDetails;
          });

          return {
            // The original OpenAPI definition
            definition: _.isString(cOptions.definition) ? remoteResults.value : cOptions.definition,
            // The original OpenAPI definition with its remote references resolved
            definitionRemotesResolved: remoteResults.resolved,
            // The original OpenAPI definition with all its references resolved
            definitionFullyResolved: results.resolved,
            // Merge the local reference details with the remote reference details
            refs: results.refs
          }
        });
github ruojs / ruo / src / swagger / parameter-value.js View on Github external
constructor (parameterObject, raw) {
    let pPath = JsonRefs.pathFromPtr(parameterObject.ptr)
    let processed = false
    let schema = parameterObject.schema
    let error
    let isValid
    let processedValue

    this.parameterObject = parameterObject
    this.raw = raw

    // Use Object.defineProperty for 'value' to allow for lazy processing of the raw value
    Object.defineProperties(this, {
      error: {
        enumerable: true,
        get: function () {
          // Always call this.valid to ensure we validate the value prior to returning any values
          if (this.valid === true) {

json-refs

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

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis