refactor(api): migrate console site responses to BaseModel#35217
refactor(api): migrate console site responses to BaseModel#35217ai-hpc wants to merge 4 commits intolanggenius:mainfrom
Conversation
Pyrefly DiffNo changes detected. |
Pyrefly DiffNo changes detected. |
There was a problem hiding this comment.
Pull request overview
Migrates the console app import endpoints in api/controllers/console/app/app_import.py from Flask-RESTX response models to Pydantic BaseModel/ResponseModel schemas registered via register_schema_models(), aligning response documentation and serialization with the newer schema approach used elsewhere in the console API.
Changes:
- Added Pydantic response schemas (
AppImportResponse,AppImportCheckDependenciesResponse,LeakedDependencyResponse) and registered them withconsole_ns. - Updated RESTX
@responsedecorators to reference the new schema models. - Updated endpoint return paths to validate into response models before
model_dump(mode="json").
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class LeakedDependencyResponse(ResponseModel): | ||
| type: str | ||
| value: Any | ||
| current_identifier: str | None = None |
There was a problem hiding this comment.
LeakedDependencyResponse.value is annotated as Any, but when validating from CheckDependenciesResult it will receive PluginDependency.value objects (nested Pydantic models). To avoid accidentally returning a non-JSON-serializable object (depending on how Any is serialized), consider normalizing value to a plain dict (e.g., type it as dict[str, Any] and/or add a validator that converts BaseModel values via model_dump(mode="json")).
| result = import_service.check_dependencies(app_model=app_model) | ||
|
|
||
| return result.model_dump(mode="json"), 200 | ||
| return AppImportCheckDependenciesResponse.model_validate(result).model_dump(mode="json"), 200 |
There was a problem hiding this comment.
AppImportCheckDependenciesResponse.model_validate(result) relies on attribute access; if check_dependencies() ever returns a dict/model_dump()-style object (as some tests/mocks do), this will fail. A more robust approach is to validate from result.model_dump(mode="json") (or from the dict directly) before dumping the response.
| return AppImportCheckDependenciesResponse.model_validate(result).model_dump(mode="json"), 200 | |
| result_data = result if isinstance(result, dict) else result.model_dump(mode="json") | |
| return AppImportCheckDependenciesResponse.model_validate(result_data).model_dump(mode="json"), 200 |
Part of #28015
Summary
Migrate response marshalling in
api/controllers/console/app/app_import.pyfrom Flask-RESTX response models to PydanticBaseModel/ResponseModelschemas registered withregister_schema_models().Checklist
make lintandmake type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods