mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 05:24:20 +08:00
fix(http): expose structured vars in HTTP body selector (#34185)
Co-authored-by: Jordan <175169034+owldev127@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { VarType } from '@/app/components/workflow/types'
|
||||
import {
|
||||
HTTP_BODY_VARIABLE_TYPES,
|
||||
isSupportedHttpBodyVariable,
|
||||
} from './supported-body-vars'
|
||||
|
||||
describe('HTTP body variable support', () => {
|
||||
it('should include structured variables in the selector', () => {
|
||||
expect(HTTP_BODY_VARIABLE_TYPES).toEqual([
|
||||
VarType.string,
|
||||
VarType.number,
|
||||
VarType.secret,
|
||||
VarType.object,
|
||||
VarType.arrayNumber,
|
||||
VarType.arrayString,
|
||||
VarType.arrayObject,
|
||||
])
|
||||
})
|
||||
|
||||
it('should accept object and array object variables', () => {
|
||||
expect(isSupportedHttpBodyVariable(VarType.object)).toBe(true)
|
||||
expect(isSupportedHttpBodyVariable(VarType.arrayObject)).toBe(true)
|
||||
})
|
||||
|
||||
it('should keep unsupported file variables excluded', () => {
|
||||
expect(isSupportedHttpBodyVariable(VarType.file)).toBe(false)
|
||||
expect(isSupportedHttpBodyVariable(VarType.arrayFile)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -13,6 +13,7 @@ import VarReferencePicker from '../../../_base/components/variable/var-reference
|
||||
import useAvailableVarList from '../../../_base/hooks/use-available-var-list'
|
||||
import { BodyPayloadValueType, BodyType } from '../../types'
|
||||
import KeyValue from '../key-value'
|
||||
import { isSupportedHttpBodyVariable } from './supported-body-vars'
|
||||
|
||||
const UNIQUE_ID_PREFIX = 'key-value-'
|
||||
|
||||
@@ -58,7 +59,7 @@ const EditBody: FC<Props> = ({
|
||||
const { availableVars, availableNodes } = useAvailableVarList(nodeId, {
|
||||
onlyLeafNodeVar: false,
|
||||
filterVar: (varPayload: Var) => {
|
||||
return [VarType.string, VarType.number, VarType.secret, VarType.arrayNumber, VarType.arrayString].includes(varPayload.type)
|
||||
return isSupportedHttpBodyVariable(varPayload.type)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { VarType } from '@/app/components/workflow/types'
|
||||
|
||||
export const HTTP_BODY_VARIABLE_TYPES: VarType[] = [
|
||||
VarType.string,
|
||||
VarType.number,
|
||||
VarType.secret,
|
||||
VarType.object,
|
||||
VarType.arrayNumber,
|
||||
VarType.arrayString,
|
||||
VarType.arrayObject,
|
||||
]
|
||||
|
||||
export const isSupportedHttpBodyVariable = (type: VarType) => {
|
||||
return HTTP_BODY_VARIABLE_TYPES.includes(type)
|
||||
}
|
||||
Reference in New Issue
Block a user