本文整理匯總了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,