How to use the json-refs.resolveRefs 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 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 eclipsesource / jsonforms / packages / editor / src / ide.ts View on Github external
private render(): void {
    if (!this.connected || this._store === undefined) {
      return;
    }

    if (this.editor === undefined || this.editor === null) {
      this.editor = document.createElement('json-forms') as JsonFormsElement;
      this.appendChild(this.editor);
    }

    JsonRefs.resolveRefs(getSchema(this._store.getState()))
      .then(
        resolvedSchema => {
        this.editor.setInnerComponent(
          TreeRenderer,
          {
            uischema: getUiSchema(this._store.getState()),
            schema: resolvedSchema.resolved,
            filterPredicate: this._filterPredicate,
            labelProvider: this._labelProvider,
            imageProvider: this._imageProvider
          });
        this.editor.store = this._store;

        const exportButton = document.getElementById('export-data-button') as HTMLButtonElement;
        if (exportButton !== null) {
          const exportDialog = createExportDataDialog();
github ruojs / ruo / packages / ruo / src / blueprint.js View on Github external
const blueprintDefinitions = exports.getBlueprintDefinitions(model)
      const blueprintHandlers = exports.getBlueprintHandlers(model)
      _.forEach(actions, (pathAndMethod, action) => {
        if (model.blueprint[action]) {
          if (!_.has(pathDefs, pathAndMethod)) {
            _.set(pathDefs, pathAndMethod, blueprintDefinitions[action])
          }
          if (!_.has(pathDefs, pathAndMethod.concat('__handler__'))) {
            _.set(pathDefs, pathAndMethod.concat('__handler__'), blueprintHandlers[action])
          }
        }
      })
    }
  })

  const definitionResolved = (await resolve(definition)).resolved
  return new Swagger(definitionResolved)
}
github ruojs / ruo / packages / ruo-ui / src / actions / AppActionCreators.js View on Github external
getSpec () {
    let promise
    if (typeof SWAGGER_RENDERER.spec === 'string') {
      promise = fetch(SWAGGER_RENDERER.spec, {credentials: 'include'})
                  .then((response) => response.json())
                  .then((spec) => resolve(spec))
    } else {
      promise = resolve(SWAGGER_RENDERER.spec)
    }

    promise
      .then((result) => result.resolved)
      .then((spec) => {
        _.forEach(spec.paths, (operations, path) => {
          _.forEach(operations, (operation, method) => {
            operation.path = path
            operation.method = method
          })
        })
        return spec
      })
    .then((spec) => {
      debug('spec', spec)
      Dispatcher.dispatch({
github LiskHQ / lisk-sdk / framework / src / modules / http_api / helpers / swagger.js View on Github external
function getSchemaAsJSON() {
	if (resolvedSwaggerSpec) {
		return Promise.resolve(resolvedSwaggerSpec);
	}
	const content = getSchema();

	const options = {
		includeInvalid: true,
		loaderOptions: {
			processContent(processedContent, callback) {
				callback(null, YAML.safeLoad(processedContent.text));
			},
		},
	};

	return jsonRefs.resolveRefs(content, options).then(results => {
		resolvedSwaggerSpec = results.resolved;
		return resolvedSwaggerSpec;
	});
}
github eclipsesource / jsonforms / packages / material-tree-renderer / src / resources / resource-set.ts View on Github external
registerResource(
    name: string,
    resource: Object,
    resolveReferences = false
  ): Object {
    const oldResource = this.resourceMap[name];
    if (resolveReferences) {
      const resourcePromise = JsonRefs.resolveRefs(resource, {
        includeInvalid: true
      });
      resourcePromise.then(result => {
        this.resourceMap[name] = result.resolved;
      });
    } else {
      this.resourceMap[name] = resource;
    }

    return oldResource;
  }

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

73 / 100
Full package analysis