[PR #27159] fix: fix OpenAPI Schema Import Pydantic Validation Errors for Complex Default Values #31699

Closed
opened 2026-02-21 20:49:58 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/27159

State: closed
Merged: Yes


Problem
This PR fixes Pydantic validation errors that occur when importing OpenAPI schemas containing complex default values (arrays and objects). Resolves #27095 where users encountered validation errors when importing OpenAPI schemas with array or object default values.

Root Cause

  1. PluginParameter.default field type annotation didn't include bool type
  2. Complex types like arrays ([]) and objects ({}) are not supported by the current type system
  3. The issue affected both URL parameters and request body parameters

Solution

  1. Enhanced Type Support: Extended PluginParameter.default to include bool type
  2. Complex Default Handling: Set complex types (arrays, objects) to None to avoid validation errors
  3. Improved Array Detection: Enhanced array type detection in parser

Key Changes

  • api/core/plugin/entities/parameters.py: Added bool to default field type annotation
  • api/core/tools/utils/parser.py: Added unified complex default value handling
  • api/tests/unit_tests/core/tools/utils/test_parser.py: Added comprehensive test coverage

Before: OpenAPI schemas with complex defaults failed to import
After: All OpenAPI schemas import successfully

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/27159 **State:** closed **Merged:** Yes --- **Problem** This PR fixes Pydantic validation errors that occur when importing OpenAPI schemas containing complex default values (arrays and objects). Resolves #27095 where users encountered validation errors when importing OpenAPI schemas with array or object default values. **Root Cause** 1. `PluginParameter.default` field type annotation didn't include `bool` type 2. Complex types like arrays (`[]`) and objects (`{}`) are not supported by the current type system 3. The issue affected both URL parameters and request body parameters **Solution** 1. **Enhanced Type Support**: Extended `PluginParameter.default` to include `bool` type 2. **Complex Default Handling**: Set complex types (arrays, objects) to `None` to avoid validation errors 3. **Improved Array Detection**: Enhanced array type detection in parser **Key Changes** - `api/core/plugin/entities/parameters.py`: Added `bool` to default field type annotation - `api/core/tools/utils/parser.py`: Added unified complex default value handling - `api/tests/unit_tests/core/tools/utils/test_parser.py`: Added comprehensive test coverage **Before**: OpenAPI schemas with complex defaults failed to import **After**: All OpenAPI schemas import successfully ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:58 -05:00
yindo closed this issue 2026-02-21 20:49:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31699