Skip to content

Conversation

@bnusunny
Copy link
Contributor

migrate to Pydantic v2

  • Update pydantic dependency from v1 to v2
  • Remove v1/v2 compatibility shim in samtranslator/compat.py
  • Migrate deprecated APIs:
    • parse_obj() -> model_validate()
    • schema() -> model_json_schema()
    • dict() -> model_dump()
    • root -> RootModel with .root accessor
    • class Config -> model_config = ConfigDict()
  • Update Field() to use json_schema_extra for custom schema properties
  • Add explicit default values for all Optional fields
  • Add type aliases to avoid field name shadowing in Pydantic v2
  • Update JSON schema generation to normalize $defs -> definitions
  • Upgrade schema version from draft-04 to draft-07
  • Update validation error handling for v2 error format
  • Update mypy to >=1.5.0 for Pydantic v2 plugin compatibility
  • Add hypothesis test dependency

Checklist

Examples?

Please reach out in the comments if you want to add an example. Examples will be
added to sam init through aws/aws-sam-cli-app-templates.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@bnusunny bnusunny requested a review from a team as a code owner December 16, 2025 07:53
BREAKING CHANGE: Requires pydantic>=2.0

- Update pydantic dependency from v1 to v2
- Remove v1/v2 compatibility shim in samtranslator/compat.py
- Migrate deprecated APIs:
  - parse_obj() -> model_validate()
  - schema() -> model_json_schema()
  - dict() -> model_dump()
  - __root__ -> RootModel with .root accessor
  - class Config -> model_config = ConfigDict()
- Update Field() to use json_schema_extra for custom schema properties
- Add explicit default values for all Optional fields
- Add type aliases to avoid field name shadowing in Pydantic v2
- Update JSON schema generation to normalize $defs -> definitions
- Upgrade schema version from draft-04 to draft-07
- Update validation error handling for v2 error format
- Update mypy to >=1.5.0 for Pydantic v2 plugin compatibility
- Add hypothesis test dependency
@bnusunny bnusunny force-pushed the pydantic_v2_upgrade branch from ca14894 to 761f208 Compare December 16, 2025 17:13
@bnusunny bnusunny enabled auto-merge (squash) December 16, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant