UNPKG

@har-sdk/openapi-sampler

Version:

[![Maintainability](https://api.codeclimate.com/v1/badges/4acaec95c82465cb2c3d/maintainability)](https://codeclimate.com/github/NeuraLegion/har-sdk/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/4acaec95c82465cb2c3d/test_coverage

43 lines 1.48 kB
import { VendorExampleExtractor } from './VendorExampleExtractor'; import { firstArrayElement, hasDefault, hasExample } from '../utils'; export class SchemaExampleExtractor { constructor(vendorExampleExtractor = new VendorExampleExtractor()) { this.vendorExampleExtractor = vendorExampleExtractor; } extractFromExamples(schema, options) { let value = this.extractFromSchemaExamples(schema); value = value === undefined ? this.extractFromVendorExamples(schema, options) : value; return value; } extractFromProperties(schema) { let value; if (hasDefault(schema)) { value = schema.default; } else if (schema.const !== undefined) { value = schema.const; } else if (schema.enum && schema.enum.length) { value = firstArrayElement(schema.enum); } return value; } extractFromSchemaExamples(schema) { if (hasExample(schema)) { return schema.example; } else if (schema.examples !== undefined && schema.examples.length > 0) { return firstArrayElement(schema.examples); } } extractFromVendorExamples(schema, { includeVendorExamples }) { return includeVendorExamples ? this.vendorExampleExtractor.extract(schema) : undefined; } } //# sourceMappingURL=SchemaExampleExtractor.js.map