Bugfix/JSON5 Parsing (#5201)

use json5 for parsing input data
This commit is contained in:
Henry Heng
2025-09-12 17:27:03 +01:00
committed by GitHub
parent e002e617df
commit 4af067a444
12 changed files with 32 additions and 43 deletions
@@ -1,6 +1,7 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, stripHTMLFromToolInput } from '../../../src/utils'
import { RequestParameters, desc, RequestsPutTool } from './core'
import JSON5 from 'json5'
const codeExample = `{
"name": {
@@ -140,11 +141,11 @@ class RequestsPut_Tools implements INode {
if (bodySchema) obj.bodySchema = stripHTMLFromToolInput(bodySchema)
if (maxOutputLength) obj.maxOutputLength = parseInt(maxOutputLength, 10)
if (headers) {
const parsedHeaders = typeof headers === 'object' ? headers : JSON.parse(stripHTMLFromToolInput(headers))
const parsedHeaders = typeof headers === 'object' ? headers : JSON5.parse(stripHTMLFromToolInput(headers))
obj.headers = parsedHeaders
}
if (body) {
const parsedBody = typeof body === 'object' ? body : JSON.parse(body)
const parsedBody = typeof body === 'object' ? body : JSON5.parse(body)
obj.body = parsedBody
}
@@ -1,6 +1,7 @@
import { z } from 'zod'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
import { secureFetch } from '../../../src/httpSecurity'
import JSON5 from 'json5'
export const desc = `Use this when you want to execute a PUT request to update or replace a resource.`
@@ -27,7 +28,7 @@ const createRequestsPutSchema = (bodySchema?: string) => {
// If bodySchema is provided, parse it and add dynamic body params
if (bodySchema) {
try {
const parsedSchema = JSON.parse(bodySchema)
const parsedSchema = JSON5.parse(bodySchema)
const bodyParamsObject: Record<string, z.ZodTypeAny> = {}
Object.entries(parsedSchema).forEach(([key, config]: [string, any]) => {