How to use amf-client-js - 10 common examples

To help you get started, we’ve selected a few amf-client-js 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 advanced-rest-client / arc-electron / scripts / packages / amf-service / lib / amf-resolver.js View on Github external
process.on('message', (data) => {
  const {model, type} = data;
  amf.Core.init()
  .then(() => modelToDoc(model))
  .then((doc) => generateEditingResolvedModel(doc, type))
  .then((result) => {
    process.send({api: result});
  })
  .catch((cause) => {
    let m = `AMF parser: Unable to resolve AMF ld+json model.\n`;
    if (cause.message) {
      m += cause.message;
    } else if (cause.toString) {
      m += cause.toString();
    }
    process.send({error: m});
  });
});
github mulesoft-labs / api-console-cli / lib / generate-json.js View on Github external
run() {
    let msg = 'Generating API model from ' + this.apiFile;
    msg += ' using ' + this.apiType + ' parser';
    this.logger.info(msg);

    amf.plugins.document.WebApi.register();
    amf.plugins.document.Vocabularies.register();
    amf.plugins.features.AMFValidation.register();
    return amf.Core.init()
    .then(() => this.gaUsage())
    .then(() => this._parse(this.apiFile, this.apiType))
    .then((doc) => this._validate(doc, this.apiType))
    .then((doc) => this._resolve(doc, this.apiType))
    .then((doc) => this._save(doc, this.output));
  }
  /**
github mulesoft-labs / api-console-cli / lib / generate-json.js View on Github external
run() {
    let msg = 'Generating API model from ' + this.apiFile;
    msg += ' using ' + this.apiType + ' parser';
    this.logger.info(msg);

    amf.plugins.document.WebApi.register();
    amf.plugins.document.Vocabularies.register();
    amf.plugins.features.AMFValidation.register();
    return amf.Core.init()
    .then(() => this.gaUsage())
    .then(() => this._parse(this.apiFile, this.apiType))
    .then((doc) => this._validate(doc, this.apiType))
    .then((doc) => this._resolve(doc, this.apiType))
    .then((doc) => this._save(doc, this.output));
  }
  /**
github advanced-rest-client / arc-electron / scripts / packages / amf-service / lib / amf-resolver.js View on Github external
function generateEditingResolvedModel(doc, type) {
  const resolver = amf.Core.resolver(type);
  doc = resolver.resolve(doc, 'editing');
  const generator = amf.Core.generator('AMF Graph', 'application/ld+json');
  const opts = amf.render.RenderOptions().withSourceMaps.withCompactUris;
  return generator.generateString(doc, opts);
}
github mulesoft-labs / api-console-cli / lib / generate-json.js View on Github external
_resolve(doc, type) {
    this.logger.info('Resolving API model for API components...');
    const resolver = amf.Core.resolver(type);
    return resolver.resolve(doc, 'editing');
  }
  /**
github advanced-rest-client / arc-electron / scripts / packages / amf-service / lib / amf-resolver.js View on Github external
const amf = require('amf-client-js');
amf.plugins.document.WebApi.register();
amf.plugins.document.Vocabularies.register();
amf.plugins.features.AMFValidation.register();
/**
 * Parses AMF ld+json model to AMF document.
 * The model has to be unresolved.
 *
 * @param {String} model
 * @return {Promise} AMF document.
 */
function modelToDoc(model) {
  const parser = amf.Core.parser('AMF Graph', 'application/ld+json');
  return parser.parseStringAsync(model);
}
/**
 * Generates resolved AMF model using editing pipeline (required by API console).
 * @param {Object} doc Parsed API document to AMF object.
github advanced-rest-client / arc-electron / scripts / packages / amf-service / lib / amf-resolver.js View on Github external
const amf = require('amf-client-js');
amf.plugins.document.WebApi.register();
amf.plugins.document.Vocabularies.register();
amf.plugins.features.AMFValidation.register();
/**
 * Parses AMF ld+json model to AMF document.
 * The model has to be unresolved.
 *
 * @param {String} model
 * @return {Promise} AMF document.
 */
function modelToDoc(model) {
  const parser = amf.Core.parser('AMF Graph', 'application/ld+json');
  return parser.parseStringAsync(model);
}
/**
 * Generates resolved AMF model using editing pipeline (required by API console).
 * @param {Object} doc Parsed API document to AMF object.
 * @param {String} type API original type (RAML 1.0, OAS 2.0, etc)
 * @return {Promise} A promise resolved to AMF object.
github advanced-rest-client / arc-electron / scripts / packages / amf-service / lib / amf-resolver.js View on Github external
function generateEditingResolvedModel(doc, type) {
  const resolver = amf.Core.resolver(type);
  doc = resolver.resolve(doc, 'editing');
  const generator = amf.Core.generator('AMF Graph', 'application/ld+json');
  const opts = amf.render.RenderOptions().withSourceMaps.withCompactUris;
  return generator.generateString(doc, opts);
}
github mulesoft-labs / api-console-cli / lib / generate-json.js View on Github external
_save(doc, file) {
    this.logger.info('Generating json-ld model...');
    const opts = amf.render.RenderOptions().withSourceMaps.withCompactUris;
    const generator = amf.Core.generator('AMF Graph', 'application/ld+json');
    const start = Date.now();
    return generator.generateString(doc, opts)
    .then((data) => {
      const time = Date.now() - start;
      this.logger.info(`Model ready in ${time} milliseconds`);
      this.logger.info('Storing API data model to file: ' + file);
      const dir = path.dirname(file);
      return fs.ensureDir(dir)
      .then(() => fs.writeFile(file, data, 'utf8'));
    });
  }
github mulesoft-labs / api-console-cli / lib / generate-json.js View on Github external
_validate(doc, type) {
    this.logger.info('API parsed.');
    this.logger.info('Validating API...');
    let validateProfile;
    switch (type) {
      case 'RAML 1.0': validateProfile = amf.ProfileNames.RAML; break;
      case 'RAML 0.8': validateProfile = amf.ProfileNames.RAML08; break;
      case 'OAS 2.0':
      case 'OAS 3.0':
        validateProfile = amf.ProfileNames.OAS;
        break;
    }
    return amf.AMF.validate(doc, validateProfile)
    .then((report) => {
      if (!report.conforms) {
        this.logger.warn(report.toString());
      } else {
        this.logger.info('API valid.');
      }
      return doc;
    });
  }
  /**

amf-client-js

AMF Library

Apache-2.0
Latest version published 8 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages