Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// validate and dereference the specification
specification = await swagger.validate(specification) as OpenAPIV2.Document
specification['x-amazon-apigateway-request-validators'] = {
validateBodyAndParameters: {
validateRequestBody: true,
validateRequestParameters: true
}
}
specification['x-amazon-apigateway-request-validator'] = 'validateBodyAndParameters'
for (let pathKey of Object.keys(specification.paths)) {
for (let operationKey of Object.keys(specification.paths[pathKey])) {
let responses = specification.paths[pathKey][operationKey].responses
let status = Object.keys(responses)[0]
let schema = responses[status].schema
let mockData: any
if (schema) mockData = await jsf.resolve(schema)
specification.paths[pathKey][operationKey]['x-amazon-apigateway-integration'] = {
type: 'mock',
requestTemplates: {
'application/json': '{\"statusCode\": 200}'
},
responses: {
default: (operationKey === 'options') ? {
statusCode: '200',
responseParameters: {
'method.response.header.Access-Control-Allow-Headers': "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
'method.response.header.Access-Control-Allow-Methods': "'*'",
'method.response.header.Access-Control-Allow-Origin': "'*'"
},
responseTemplates: {
'application/json': '{}'
}
function generateFakeData(file, typeName) {
var json = require(file.path);
jsf.option({failOnInvalidTypes: true, fileOnInvalidFormat: true, fillProperties:true});
jsf.resolve(json, file.base).then(sample => {
sample['$schema'] = slash(path.relative(path.join(source, 'samples'), file.path));
var data = JSON.stringify(sample, undefined, 2);
str(data).pipe(vinylSource('generated-'+typeName+'.json')).pipe(gulp.dest('samples', {cwd: source}));
}, err => console.error(err));
};
.then(refs => jsf.resolve(content, refs, this.params.directory))
.then(sample => {
export const getMock = (schema: any) => jsf.resolve(schema);
export const fakerGenerate = (schema: Definition) => jsf.generate(schema, []);
export const generate = (schemaPath: string | {}): Promise => {
const schema = getSchema(schemaPath);
return jsf.resolve(schema);
};
return Promise.map(definitionEntries, ([key, schema]) => {
const s = Object.assign({}, schema, { definitions });
return jsf.resolve(s).then(sample => ({ [key]: sample }));
})
.then(samples => samples.reduce((total, el) => Object.assign(total, el), {}))
return () => jsf.resolve(dump);
}
new Promise(resolve => {
jsf.resolve(JSON.parse(code)).then(_json => {
resolve(
transform(_json, {
lang: "rust-serde",
rustCase
})
);
});
})
);
async [mockName](req, res) {
if (data.validateRequest && !data.validateRequest(req.body)) {
return res.json({
error: {
message: "Request failed to validate",
meta: data.validateRequest.errors
}
})
}
if (responseSchema == null) {
return res.json({})
}
const fakedResponse = await jsf.resolve(responseSchema)
return res.json(fakedResponse)
}
}