Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const schema = clone(jsonSchema, value => {
if (isObject(value)) {
if (patch) {
// Remove all required keywords and formats from schema for patch
// validation.
delete value.required
if (value.format === 'required') {
delete value.format
}
}
// Convert async `validate()` keywords to `validateAsync()`:
if (isAsync(value.validate)) {
value.validateAsync = value.validate
delete value.validate
}
if (!async) {
// Remove all async keywords for synchronous validation.
for (const key in value) {
function getSettings(verb, handlers, settings) {
// Only use `settings[verb]` as the settings for this handler, if `settings`
// contains any of the verbs defined in handlers. If not, then `settings`
// is a shared object to be used for all verbs:
let obj = isObject(settings) &&
Object.keys(handlers).find(verb => settings[verb])
? settings[verb]
: settings || false
if (!isObject(obj) || !('access' in obj)) {
// TODO: Improve check by looking for any route settings properties in
// Object.keys(obj), and only wrap with `access: obj` if obj doesn't contain
// any of these keys.
obj = { access: obj }
}
return obj
}
export function expandSchemaShorthand(schema) {
// TODO: Consider removing all short-hand schema expansion.
if (isString(schema)) {
schema = {
type: schema
}
} else if (isArray(schema)) {
schema = {
type: 'array',
items: schema.length > 1 ? schema : schema[0],
// The array short-forms sets an empty array as the default.
default: []
}
} else if (
// Expand objects to `type: 'object'`...
isObject(schema) &&
!(
// ...but only if they don't define any of these properties:
isString(schema.type) ||
isString(schema.$ref) ||
isArray(schema.allOf) ||
isArray(schema.anyOf) ||
isArray(schema.oneOf) ||
isObject(schema.not)
)
) {
schema = {
type: 'object',
properties: {
...schema
},
additionalProperties: false
file: pinoLogger
}[log.requests || log.request]
// TODO: `log.request` is deprecated, remove later.
this.use(handleError())
if (app.responseTime !== false) {
this.use(responseTime())
}
if (logger) {
this.use(logger())
}
if (app.helmet !== false) {
this.use(helmet())
}
if (app.cors !== false) {
this.use(cors(isObject(app.cors) ? app.cors : {}))
}
if (app.compress !== false) {
this.use(compress(app.compress))
}
if (app.etag !== false) {
this.use(conditional())
this.use(etag())
}
}
setupComputed() {
for (const [key, value] of Object.entries(this.schema.computed || {})) {
const accessor = isFunction(value)
? { get: value }
: isObject(value) && isFunction(value.get)
? value
: null
if (accessor) {
Object.defineProperty(this, key, accessor)
} else {
console.error(
`Invalid computed property definition: ${key}: ${value}`
)
}
}
},
clipboardConfig() {
return isObject(this.clipboard) ? this.clipboard : {}
},
function getType(schemaOrType) {
return isObject(schemaOrType) ? schemaOrType.type : schemaOrType
}
getOptionKey(key) {
const [option] = this.options
return isObject(option) && key in option ? key : null
},
? toObject(descriptions, value => (
isObject(value) ? value : {
name: camelize(value, false)
}
))
: isObject(descriptions) && Object.keys(descriptions).length
function hasDefaults(obj) {
if (isArray(obj)) {
for (const val of obj) {
if (val && hasDefaults(val)) {
return true
}
}
} else if (isObject(obj)) {
for (const [key, val] of Object.entries(obj)) {
if (key === 'default' || val && hasDefaults(val)) {
return true
}
}
}
return false
}