本文整理汇总了TypeScript中joi.only函数的典型用法代码示例。如果您正苦于以下问题:TypeScript only函数的具体用法?TypeScript only怎么用?TypeScript only使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了only函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: next
const register: PluginRegister = (server, _, next) => {
server.route([
{
method: 'POST',
path: '/users',
handler: {
async: createUser,
},
config: {
auth: 'attendee',
validate: {
payload: Joi.object().keys({
data: Joi.object().keys({
id: Joi.string(),
type: Joi.only('users'),
attributes: Joi.object().keys({
name: Joi.string(),
}),
}),
}),
},
},
},
{
method: 'GET',
path: '/users',
handler: {
async: getUsers,
},
config: {
cors: true,
},
},
{
method: 'GET',
path: '/users/{userId}',
handler: {
async: getUser,
},
config: {
cors: true,
validate: {
params: {
userId: Joi.string(),
},
},
},
},
])
next()
}
示例2:
import * as Joi from 'joi'
import { PluginRegister } from '../../../hapi.types'
import addTeamEntries from './add-team-entries'
import deleteTeamEntries from './delete-team-entries'
import getTeamEntries from './get-team-entries'
const multipleEntriesSchema = Joi.object().keys({
data: Joi.array().items(
Joi.object().keys({
id: Joi.string(),
type: Joi.only('hacks'),
}),
),
})
const register: PluginRegister = (server, _, next) => {
server.route([
{
method: 'POST',
path: '/teams/{teamId}/entries',
handler: {
async: addTeamEntries,
},
config: {
auth: 'attendee',
validate: {
params: {
teamId: Joi.string(),
},
payload: multipleEntriesSchema,