Skip to content

Commit

Permalink
fix(api): invalid schema (#7184)
Browse files Browse the repository at this point in the history
  • Loading branch information
djabarovgeorge authored Dec 2, 2024
1 parent 77c25e5 commit cf3b1cd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/api/src/app/workflows-v2/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,24 @@ export function flattenObjectValues(obj: Record<string, unknown>): string[] {
export function createMockPayloadFromSchema(
schema: JSONSchemaDto,
path = 'payload',
depth = 0
depth = 0,
safe = true
): Record<string, unknown> {
const MAX_DEPTH = 10;
if (depth >= MAX_DEPTH) {
if (safe) {
return {};
}
throw new BadRequestException({
message: 'Schema has surpassed the maximum allowed depth. Please specify a more shallow payload schema.',
maxDepth: MAX_DEPTH,
});
}

if (schema.type !== 'object' || !schema.properties) {
if (schema?.type !== 'object' || !schema?.properties) {
if (safe) {
return {};
}
throw new BadRequestException({
message: 'Schema must define an object with properties.',
});
Expand Down

0 comments on commit cf3b1cd

Please sign in to comment.