fix(api): show structured add example in /docs for /product/add#2112
Conversation
Swagger UI rendered APIADDRequest.messages as "string" because it picks the leading `str` branch of the `str | MessageList | RawMessageList` union when generating the example. Add a model-level json_schema_extra example so /docs shows a copy-paste-ready payload with a structured messages list. Schema-only change: field types, validation and runtime behaviour are unchanged, so the core add pipeline is unaffected. Closes MemTensor#1505 Co-authored-by: Cursor <cursoragent@cursor.com>
🤖 Open Code ReviewTarget: PR #2112 🔍 OpenCodeReview found 2 issue(s) in this PR. 1.
|
Description
The interactive API docs (
/docs) forPOST /product/addshow"messages": "string"in the request example, which conflicts with the official docs (a structured message list) and misleads users into sending plain text.Root cause:
APIADDRequest.messagesis typedstr | MessageList | RawMessageList. Pydantic v2 renders this as ananyOf, and Swagger UI builds the "Example Value" from the first branch (str), so it displays"string". Fields likechat_history(a plain list) render correctly, which confirms the cause.Fix: add a model-level
json_schema_extraexample toAPIADDRequestso/docsshows a copy-paste-ready payload with a structuredmessageslist plus the common fields. This is a schema-only change — field types, validation, the deprecated-field validator and runtime behaviour are all unchanged, so the core add pipeline is unaffected.Related Issue (Required): Fixes #1505
Type of change
How Has This Been Tested?
Added
tests/api/test_product_models.py, which asserts the generated OpenAPI schema exposes a model-levelexamplewhosemessagesis a non-empty structured list (not a bare string) and covers the core add fields.Also ran
ruff format --checkandruff checkon the changed files — all passed.Checklist
messagesaslist/str; no docs change neededReviewer Checklist
Made with Cursor