[PR #31789] refactor(api): replace reqparse with Pydantic models in trial.py #33408

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

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

State: closed
Merged: Yes


Summary

This PR replaces flask_restx.reqparse with Pydantic models in api/controllers/console/explore/trial.py as part of the ongoing effort to modernize request validation (see #27513).

Changes

  • Added Pydantic models: WorkflowRunRequest, ChatRequest, TextToSpeechRequest, CompletionRequest
  • Registered models with console_ns.schema_model() for Swagger documentation
  • Used @console_ns.expect() decorator for API documentation
  • Replaced parser.parse_args() with model_validate(console_ns.payload)
  • Removed unused reqparse import

Motivation

Following the pattern established in #28236, this change:

  • Provides better type safety through Pydantic validation
  • Results in cleaner, more readable code
  • Improves API documentation through schema registration

Fixes #27513

Checklist

**Original Pull Request:** https://github.com/langgenius/dify/pull/31789 **State:** closed **Merged:** Yes --- ## Summary This PR replaces `flask_restx.reqparse` with Pydantic models in `api/controllers/console/explore/trial.py` as part of the ongoing effort to modernize request validation (see #27513). ## Changes - Added Pydantic models: `WorkflowRunRequest`, `ChatRequest`, `TextToSpeechRequest`, `CompletionRequest` - Registered models with `console_ns.schema_model()` for Swagger documentation - Used `@console_ns.expect()` decorator for API documentation - Replaced `parser.parse_args()` with `model_validate(console_ns.payload)` - Removed unused `reqparse` import ## Motivation Following the pattern established in #28236, this change: - Provides better type safety through Pydantic validation - Results in cleaner, more readable code - Improves API documentation through schema registration Fixes #27513 ## Checklist - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542) - [x] I ran `ruff check` and `ruff format` to appease the lint gods
yindo added the pull-request label 2026-02-21 20:53:13 -05:00
yindo closed this issue 2026-02-21 20:53:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33408