Repository navigation
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 17 files
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
067fd08 to
f3586d1
Compare
a47683e to
189b725
Compare
Generator Snapshot Testing
Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/133#issuecomment-6377439379 Snapshot results are summarized above. Additional run context is linked for maintainers with access. |
189b725 to
56a8cb5
Compare
f3586d1 to
cf1a6c5
Compare
56a8cb5 to
876df5f
Compare
cf1a6c5 to
f19c32e
Compare
Add python.modelSerializationMethods (default false). When enabled, generated models gain to_dict() and to_json(), which dump with API field names and exclude unset fields by default, and expose Pydantic's exclude_defaults, exclude_none and warnings options plus use_api_names. - model serializers emit Python field names when use_api_names=False, and the helpers leave filtered fields out even with exclude_none - consts are marked as set so exclude_unset keeps them, in models and error data models - the unknown variant of an open union dumps as its raw payload in to_dict() and to_json(); use_api_names and the exclude options do not apply inside the raw payload, which has no schema - model fields named to_dict or to_json gain a trailing underscore; SDK group accessors, global and server-variable constructor arguments and method parameters keep their names - method parameter docs and docstrings use the same sanitizer as the method signature - usage snippets name global parameters like the SDK constructor does The tertiary variant covers the option alone and the quaternary variant covers it together with preserveUnknownFields.
f19c32e to
96a37ed
Compare
There was a problem hiding this comment.
No issues found across 24 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Adds optional modelSerializationMethods (to_dict/to_json) with serializer and naming/test changes. Dismissed default-model_dump-alias finding unresolved: serializer keys off by_alias; claim that default model_dump keeps API names needs human verification.
View guided diff | Turn on auto-fix | Re-trigger cubic
TristanSpeakEasy
left a comment
There was a problem hiding this comment.
Looks good, nice to have the helpers preserve the raw payload for unknown union variants without changing request serialization.
Why
Python SDK models have no short way to turn a model into a dict or JSON string with the field names the API uses. Users have to call
model_dump(by_alias=True, exclude_unset=True, ...)themselves.What changed
Add
python.modelSerializationMethods(defaultfalse). When enabled, every generated model gains:to_dict(*, mode="python", use_api_names=True, exclude_unset=True, exclude_defaults=False, exclude_none=False, warnings=True)to_json(*, indent=2, use_api_names=True, exclude_unset=True, exclude_defaults=False, exclude_none=False, warnings=True)Supporting changes:
use_api_names=False. With the option on,model_dump(by_alias=False)also emits Python field names; the defaultmodel_dump()keeps emitting API names.to_dictandto_jsonleave filtered fields out even withexclude_none=True. Other dumps keep theexclude_noneexception from fix(python): honour include/exclude filters in model dumps #149, which request bodies rely on.model_post_init, soexclude_unsetkeeps them. Error-data models (<Name>Data) get the samemodel_post_init.to_dictandto_json, so the helpers return the data the server sent instead of the SDK's fallback object. Parsing that output gives the same unknown variant only when unknown union variants are allowed, as for responses; a plainmodel_validaterejects the unrecognized discriminator value.use_api_namesand theexclude_*options do not apply inside the raw payload, which has no schema.model_dumpand request bodies are unchanged.to_dictorto_jsongets a trailing underscore. SDK group accessors, global-parameter and server-variable constructor arguments, and flattened method parameters keep their names, because only models reserve these methods. Security constructor arguments follow the security model's field names, so they get the underscore too.toJsonparameter was documented asto_json_while the method acceptsto_json. This also applies with the option disabled, for parameter names that are reserved differently for parameters and model fields: the review SDK's flattenedtypeparameter was documented astypewhile the method acceptstype_, and is now documented astype_.preserveUnknownFieldsalso enabled, both helpers keep unknown fields, subject to the limitations listed in feat(python): add preserveUnknownFields option #146.Test coverage
unknown-fieldsfragment gains a group namedtoJsonwith atoJsonquery parameter, an object withtoDict/toJsonproperties, a const object with a defaulted field, and a required const in the error body. Its discriminatedChoiceunion becomes a component, used bychoiceand by a newchoicesarray.model_dump()of nested models and model lists, and unknown open-union variants at the top level, nested in a model and inside a list.preserveUnknownFields, flattened parameters): helper round trips that keep unknown fields, unknown open-union variants nested in a model and inside a list alongside unknown fields, a flattenedto_jsonparameter whose signature, docstring and Markdown table agree, plus checks that unrecognized enums serialize without warnings.Stack
preserveUnknownFieldsmodelSerializationMethodsTesting
TARGET=primary make test-pythonv2(option disabled): 724 passed.TARGET=secondary make test-pythonv2(option disabled): 333 passed, 1 skipped.TARGET=tertiary make test-pythonv2: 257 passed, 1 skipped. The nestedmodel_dump()test fails without the serializer fix, and the error-data const test fails withoutmodel_post_initon error data.TARGET=quaternary make test-pythonv2: 296 passed, 1 skipped.TARGET=review make test-pythonv2: 36 passed, 6 skipped.TARGET=primary make test-typescriptv2(fragment change): 802 passed.make check-template-pythonv2and prettier pass.TARGET=review make build-pythonv2: integrity validation passes; the review SDK gainsmodelSerializationMethods: falseingen.yaml, and the flattenedtypeparameter of two methods is now documented astype_in their docstrings and Markdown tables, matching the signature.git diff --checkpasses.Public-safety check
.claude/skills/public-repo-communication/SKILL.md).git diff --check.