How to use openapi-sampler - 8 common examples

To help you get started, we’ve selected a few openapi-sampler 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 Mermade / widdershins / lib / common.js View on Github external
function getSampleInner(orig,options,samplerOptions,api){
    if (!options.samplerErrors) options.samplerErrors = new Map();
    let obj = circularClone(orig);
    let defs = api; //Object.assign({},api,orig);
    if (options.sample && obj) {
        try {
            var sample = sampler.sample(obj,samplerOptions,defs); // was api
            if (sample && typeof sample.$ref !== 'undefined') {
                obj = JSON.parse(safejson(orig));
                sample = sampler.sample(obj,samplerOptions,defs);
            }
            if (typeof sample !== 'undefined') {
                if (sample !== null && Object.keys(sample).length) return sample
                else {
                    return sampler.sample({ type: 'object', properties: { anonymous: obj}},samplerOptions,defs).anonymous;
                }
            }
        }
        catch (ex) {
            if (options.samplerErrors.has(ex.message)) {
                process.stderr.write('.');
            }
            else {
                console.error('# sampler ' + ex.message);
                options.samplerErrors.set(ex.message,true);
                if (options.verbose) {
                    console.error(ex);
                }
            }
            obj = JSON.parse(safejson(orig));
            try {
github Mermade / widdershins / lib / common.js View on Github external
function getSampleInner(orig,options,samplerOptions,api){
    if (!options.samplerErrors) options.samplerErrors = new Map();
    let obj = circularClone(orig);
    let defs = api; //Object.assign({},api,orig);
    if (options.sample && obj) {
        try {
            var sample = sampler.sample(obj,samplerOptions,defs); // was api
            if (sample && typeof sample.$ref !== 'undefined') {
                obj = JSON.parse(safejson(orig));
                sample = sampler.sample(obj,samplerOptions,defs);
            }
            if (typeof sample !== 'undefined') {
                if (sample !== null && Object.keys(sample).length) return sample
                else {
                    return sampler.sample({ type: 'object', properties: { anonymous: obj}},samplerOptions,defs).anonymous;
                }
            }
        }
        catch (ex) {
            if (options.samplerErrors.has(ex.message)) {
                process.stderr.write('.');
            }
            else {
                console.error('# sampler ' + ex.message);
                options.samplerErrors.set(ex.message,true);
                if (options.verbose) {
github Mermade / widdershins / lib / common.js View on Github external
function getSampleInner(orig,options,samplerOptions,api){
    if (!options.samplerErrors) options.samplerErrors = new Map();
    let obj = circularClone(orig);
    let defs = api; //Object.assign({},api,orig);
    if (options.sample && obj) {
        try {
            var sample = sampler.sample(obj,samplerOptions,defs); // was api
            if (sample && typeof sample.$ref !== 'undefined') {
                obj = JSON.parse(safejson(orig));
                sample = sampler.sample(obj,samplerOptions,defs);
            }
            if (typeof sample !== 'undefined') {
                if (sample !== null && Object.keys(sample).length) return sample
                else {
                    return sampler.sample({ type: 'object', properties: { anonymous: obj}},samplerOptions,defs).anonymous;
                }
            }
        }
        catch (ex) {
            if (options.samplerErrors.has(ex.message)) {
                process.stderr.write('.');
            }
            else {
github Mermade / widdershins / lib / common.js View on Github external
}
        }
        catch (ex) {
            if (options.samplerErrors.has(ex.message)) {
                process.stderr.write('.');
            }
            else {
                console.error('# sampler ' + ex.message);
                options.samplerErrors.set(ex.message,true);
                if (options.verbose) {
                    console.error(ex);
                }
            }
            obj = JSON.parse(safejson(orig));
            try {
                sample = sampler.sample(obj,samplerOptions,defs);
                if (typeof sample !== 'undefined') return sample;
            }
            catch (ex) {
                if (options.samplerErrors.has(ex.message)) {
                    process.stderr.write('.');
                }
                else {
                    console.warn('# sampler 2nd error ' + ex.message);
                    options.samplerErrors.set(ex.message,true);
                }
            }
        }
    }
    return obj;
}
github kyma-project / console / lambda / src / app / lambdas / lambda-details / lambda-details.component.ts View on Github external
private generateExample(schema: JSON) {
    try {
      return require('openapi-sampler').sample(schema);
    } catch (e) {
      return;
    }
  }
github asyncapi / generator / lib / beautifier2.js View on Github external
const generateExample = schema => {
  try {
    return OpenAPISampler.sample(schema);
  } catch (e) {
    return;
  }
};
github asyncapi / generator / lib / beautifier.js View on Github external
const generateExample = schema => {
  try {
    return OpenAPISampler.sample(schema);
  } catch (e) {
    return;
  }
};
github Redocly / redoc / src / services / models / MediaType.ts View on Github external
generateExample(parser: OpenAPIParser, info: OpenAPIMediaType) {
    const samplerOptions = {
      skipReadOnly: this.isRequestType,
      skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
      skipWriteOnly: !this.isRequestType,
    };
    if (this.schema && this.schema.oneOf) {
      this.examples = {};
      for (const subSchema of this.schema.oneOf) {
        const sample = Sampler.sample(subSchema.rawSchema, samplerOptions, parser.spec);

        if (this.schema.discriminatorProp && typeof sample === 'object' && sample) {
          sample[this.schema.discriminatorProp] = subSchema.title;
        }

        this.examples[subSchema.title] = new ExampleModel(
          parser,
          {
            value: sample,
          },
          this.name,
          info.encoding,
        );
      }
    } else if (this.schema) {
      this.examples = {

openapi-sampler

Tool for generation samples based on OpenAPI payload/response schema

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis

Popular openapi-sampler functions