Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(requestSchema.properties).forEach(prop => {
const ref = resolveReference(
document,
(requestSchema as any).properties[prop],
);
const ex = this.generateExampleValue(ref);
reqBody[prop] = ex ? ex : undefined;
});
debug(`Generated Body: ${JSON.stringify(reqBody, null, 2)}`);
path: string,
opConfig: OperationConfig,
document: OpenApiDocument,
): Object {
const reqBody = {};
if (opConfig.config.requestBody) {
debug(
`Attempting to generate requestBody for: ${opConfig.operation.toUpperCase()} ${path}...`,
);
let requestSchema: SchemaObject | ReferenceObject | undefined =
opConfig.config.requestBody.content['application/json'].schema;
if (requestSchema) {
requestSchema = resolveReference(document, requestSchema);
if (requestSchema.properties) {
Object.keys(requestSchema.properties).forEach(prop => {
const ref = resolveReference(
document,
(requestSchema as any).properties[prop],
);
const ex = this.generateExampleValue(ref);
reqBody[prop] = ex ? ex : undefined;
});
debug(`Generated Body: ${JSON.stringify(reqBody, null, 2)}`);
}
}
}
return reqBody;