验证joi

时间:2018-12-11 07:06:10

标签: swagger joi

我正在尝试根据此链接将招摇对象确认为有效载荷

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object

我在安全方面面临困难,根据上面的链接,我创建了这段代码,

const scopesObject=Joi.object().pattern(/^/,joi.string()).required();

const securitySchemeObject=Joi.object({
type: Joi.string().valid('basic','apikey','oauth2').required(),
description: Joi.string(),
name: Joi.string().when('type', { is: 'apikey', then: Joi.string().required()}),
in: Joi.string().when('type', { is: 'apikey', then: Joi.string().valid('query','header').required()}),
flow: Joi.string().when('type', { is: 'oauth2', then: Joi.string().valid("implicit", "password", "application","accessCode").required()}),
authorizationUrl: Joi.string().when('flow', { is: 'implicit', then: Joi.string().required()})
                .when('flow', { is: 'accessCode', then: Joi.string().required()}),
tokenUrl: Joi.string().when('flow', { is: 'password', then: Joi.string().required()})
                .when('flow', { is: 'application', then: Joi.string().required()})
                .when('flow', { is: 'accesscode', then: Joi.string().required()}),
scopes: Joi.object().when('type', { is: 'oauth2', then: scopesObject.required()})
});

const start=Joi.object().pattern(/^/,securitySchemeObject);
var securityRequirementObject=Joi.object().pattern(/^/,joi.array().items(scopesObject));
Joi.array()
  .items(
    securityRequirementObject,
  );

他们在链接中提到了一个带模式的字段{名称},其密钥应该已经存在于securityschemeobject中,并且其范围密钥应该相同。 我该如何实现?如果我忽略了某些东西,请纠正我。

0 个答案:

没有答案