Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (wrapArrays) {
return childrenString.slice(1, -1);
}
return childrenString;
}
const hasKey = /{{!?label}}/.test(format);
const skipKey = format.length > 2 && format[0] === '!' && format[1] === '!';
if (skipKey) {
format = format.slice(2);
}
if (!hasKey && !skipKey) {
const localizedKey = Hoek.reach(localized, 'key');
if (typeof localizedKey === 'string') {
format = localizedKey + format;
}
else {
format = Hoek.reach(Language.errors, 'key') + format;
}
}
const message = format.replace(/{{(!?)([^}]+)}}/g, ($0, isSecure, name) => {
const value = Hoek.reach(this.context, name);
const normalized = internals.stringify(value, wrapArrays);
return (isSecure && this.options.escapeHtml ? Hoek.escapeHtml(normalized) : normalized);
});
this.toString = () => message; // Persist result of last toString call, it won't change
private createRoute(spec: Route) {
const { basePath } = this.config.base
const route = this.koaRouter
// const customMiddleware = this.customMiddleware()
const customMiddleware = this.middleware
const path = spec.path
const method = spec.method
const validate = Hoek.reach(spec, "config.validate")
const id = Hoek.reach(spec, "config.id")
const handler = Hoek.reach(spec, "config.handler")
const validatorMiddleware = this.validator(validate)
should.exist(path, `'path' should be defined on route ${path}`)
const middleware = [
validatorMiddleware,
...customMiddleware,
handler,
]
const fullPath = `${basePath || ""}${path}`
this.logger.info(`Mount Route ${fullPath}`)
debug(fullPath)
route[method](fullPath, ...middleware)
}
routes.forEach((route) => {
// let routeOptions = Hoek.reach(route, 'settings.plugins.hapi-swagger') || {};
let routeData = {
path: route.path,
method: route.method.toUpperCase(),
description: route.description,
summary: route.summary,
tags: Hoek.reach(route, 'tags'),
queryParams: Hoek.reach(route, 'validate.query'),
pathParams: Hoek.reach(route, 'validate.params'),
payloadParams: Hoek.reach(route, 'validate.payload'),
responseSchema: Hoek.reach(route, 'response.schema'),
responseStatus: Hoek.reach(route, 'response.status'),
headerParams: Hoek.reach(route, 'validate.headers'),
consumes: Hoek.reach(route, 'options.consumes') || null,
produces: Hoek.reach(route, 'options.produces') || null,
responses: Hoek.reach(route, 'options.responses') || null,
payloadType: Hoek.reach(route, 'options.payloadType') || null,
security: Hoek.reach(route, 'options.security') || null,
order: Hoek.reach(route, 'options.order') || null,
deprecated: Hoek.reach(route, 'options.deprecated') || null,
id: Hoek.reach(route, 'options.id') || null,
groups: route.group,
'x-meta': Hoek.reach(route, 'options.x-meta') || null
description: route.description,
summary: route.summary,
tags: Hoek.reach(route, 'tags'),
queryParams: Hoek.reach(route, 'validate.query'),
pathParams: Hoek.reach(route, 'validate.params'),
payloadParams: Hoek.reach(route, 'validate.payload'),
responseSchema: Hoek.reach(route, 'response.schema'),
responseStatus: Hoek.reach(route, 'response.status'),
headerParams: Hoek.reach(route, 'validate.headers'),
consumes: Hoek.reach(route, 'options.consumes') || null,
produces: Hoek.reach(route, 'options.produces') || null,
responses: Hoek.reach(route, 'options.responses') || null,
payloadType: Hoek.reach(route, 'options.payloadType') || null,
security: Hoek.reach(route, 'options.security') || null,
order: Hoek.reach(route, 'options.order') || null,
deprecated: Hoek.reach(route, 'options.deprecated') || null,
id: Hoek.reach(route, 'options.id') || null,
groups: route.group,
'x-meta': Hoek.reach(route, 'options.x-meta') || null
};
routeData.path = Utilities.replaceInPath(routeData.path, ['endpoints'], this.settings.pathReplacements);
// TODO: hapi-swagger的routeOptions处理,此处可做优化,理论上swagi并不需要这一步
// user configured interface through route plugin options
if (Hoek.reach(route, 'validate.query')) {
routeData.queryParams = Utilities.toJoiObject(Hoek.reach(route, 'validate.query'));
}
if (Hoek.reach(route, 'validate.params')) {
routeData.pathParams = Utilities.toJoiObject(Hoek.reach(route, 'validate.params'));
property.description = Hoek.reach(joiObj, '_description')
property.summary = Hoek.reach(joiObj, '_summary')
property.tags = Hoek.reach(joiObj, '_tags')
// add extended properties not part of openAPI spec
if (this.settings.xProperties === true) {
internals.convertRules(property, describe.rules, [
'unit'
], 'x-format')
property.example = Hoek.reach(joiObj, '_examples.0')
property['x-meta'] = Hoek.reach(joiObj, '_meta.0')
}
// add required/optional state only if present
if (parent && name) {
if (Hoek.reach(joiObj, '_flags.presence')) {
if (parent.required === undefined) {
parent.required = []
}
if (parent.optional === undefined) {
parent.optional = []
}
if (Hoek.reach(joiObj, '_flags.presence') === 'required') {
parent.required.push(name)
}
if (Hoek.reach(joiObj, '_flags.presence') === 'optional') {
parent.optional.push(name)
}
}
}
property.default = Hoek.reach(joiObj, '_flags.default')
function pushEvent(request, reply) {
const pipelineFactory = request.server.app.pipelineFactory;
const jobFactory = request.server.app.jobFactory;
const buildFactory = request.server.app.buildFactory;
const userFactory = request.server.app.userFactory;
const eventId = request.headers['x-github-delivery'];
const payload = request.payload;
const repository = hoek.reach(payload, 'repository.ssh_url');
const branch = hoek.reach(payload, 'ref').replace(/^refs\/heads\//, '');
const sha = hoek.reach(payload, 'after');
const username = hoek.reach(payload, 'sender.login');
const checkoutUrl = `${repository}#${branch}`;
request.log(['webhook-github', eventId], `Push for ${checkoutUrl}`);
// Fetch the pipeline associated with this hook
return userFactory.get({ username })
.then(user => user.unsealToken())
.then(token => pipelineFactory.scm.parseUrl({ checkoutUrl, token }))
.then(scmUri => pipelineFactory.get({ scmUri }))
.then((pipeline) => {
if (!pipeline) {
request.log(['webhook-github', eventId],
`Skipping since Pipeline ${checkoutUrl} does not exist`);
return reply().code(204);
if (schema._flags.presence) {
return { type: new TypeDictionary.required(TypeDictionary[schema._tests[0].name]) };
}
return { type: TypeDictionary[schema._tests[0].name] };
}
if (schema._flags.presence === 'required') {
return { type: new TypeDictionary.required(TypeDictionary[schema._type]) };
}
if (schema._flags.allowOnly) { // GraphQLEnumType
const name = Hoek.reach(schema, '_meta.0.name') || 'Anon';
const config = {
name,
values: internals.buildEnumFields(schema._valids._set)
};
return { type: new TypeDictionary.enum(config) };
}
return { type: TypeDictionary[schema._type] };
};
let format;
if (this.template) {
format = this.template;
}
const localized = this.options.language;
format = format || Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type);
if (format === undefined) {
return `Error code "${this.type}" is not defined, your custom type is missing the correct language definition`;
}
let wrapArrays = Hoek.reach(localized, 'messages.wrapArrays');
if (typeof wrapArrays !== 'boolean') {
wrapArrays = Language.errors.messages.wrapArrays;
}
if (format === null) {
const childrenString = internals.stringify(this.context.reason, wrapArrays);
if (wrapArrays) {
return childrenString.slice(1, -1);
}
return childrenString;
}
const hasKey = /\{\{\!?label\}\}/.test(format);
const skipKey = format.length > 2 && format[0] === '!' && format[1] === '!';
this.context.key = localized.label;
}
else if (this.context.key === '' || this.context.key === null) {
this.context.key = localized.root || Language.errors.root;
}
var format = Hoek.reach(localized, this.type) || Hoek.reach(Language.errors, this.type);
var hasKey = /\{\{\!?key\}\}/.test(format);
var skipKey = format.length > 2 && format[0] === '!' && format[1] === '!';
if (skipKey) {
format = format.slice(2);
}
if (!hasKey && !skipKey) {
format = (Hoek.reach(localized, 'key') || Hoek.reach(Language.errors, 'key')) + format;
}
var wrapArrays = Hoek.reach(localized, 'messages.wrapArrays');
if (typeof wrapArrays !== 'boolean') {
wrapArrays = Language.errors.messages.wrapArrays;
}
var message = format.replace(/\{\{(\!?)([^}]+)\}\}/g, function ($0, isSecure, name) {
var value = Hoek.reach(self.context, name);
var normalized = internals.stringify(value, wrapArrays);
return (isSecure ? Hoek.escapeHtml(normalized) : normalized);
});
return message;
};
utils.generateNameFromSchema = function (schema) {
const isArray = schema && schema._type === 'array'
const isPrimitive = schema && utils.isPrimitiveSwaggerType(schema._type)
let keys = []
if (isPrimitive) {
return utils.firstCharToUpperCase(utils.getPrimitiveType(schema))
} else if (isArray) {
return 'Array'
} else {
const children = Hoek.reach(schema, '_inner.children')
keys = _.map(_.map(children, 'key'), utils.firstCharToUpperCase)
}
if (_.isEmpty(keys)) {
return 'EmptyModel'
} else {
keys.push('Model')
return keys.join('')
}
}