Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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) {
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 {
}
}
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;
}
private generateExample(schema: JSON) {
try {
return require('openapi-sampler').sample(schema);
} catch (e) {
return;
}
}
const generateExample = schema => {
try {
return OpenAPISampler.sample(schema);
} catch (e) {
return;
}
};
const generateExample = schema => {
try {
return OpenAPISampler.sample(schema);
} catch (e) {
return;
}
};
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 = {