chore: add children and overrides to symbols#3945
Conversation
|
|
🦋 Changeset detectedLatest commit: 13c3d7d The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ed323fc to
13c3d7d
Compare
There was a problem hiding this comment.
Important
The Pydantic alias regression should be fixed before merging because it changes generated model wire names for fields that collide with inherited BaseModel members.
Reviewed changes — This PR adds symbol-level child and override metadata so inherited member names can participate in planner conflict resolution, then uses that machinery for Python/Pydantic naming.
- Extend
Symbolmetadata —Symbolnow carrieschildrenandoverridestate, and the public package exports the related symbol and resolver types. - Teach the planner about inherited child names —
AnalysisContext.injectChildrenregisters base-class child names in class scopes, andPlanner.nameIsAvailabletreats them as soft conflicts unless a symbol opts intooverride. - Use Python-specific conflict suffixes —
pythonNameConflictResolveremits the first conflict asname_, and Python is wired to use it by default. - Move Pydantic reserved members into symbols —
PYDANTIC.BaseModelnow declares inherited child names, whilePydanticFieldDsldrops its directBASE_MODEL_RESERVEDalias handling. - Refresh generated Python snapshots — OpenCode snapshots now reflect the new first-conflict Python suffixing for models and SDK classes.
GPT | 𝕏
| const snake = toCase(name, 'snake_case'); | ||
| const safe = safeRuntimeName(snake); | ||
| const runtimeName = BASE_MODEL_RESERVED.has(safe) ? `${safe}_` : safe; | ||
| const runtimeName = safe; |
There was a problem hiding this comment.
BaseModel child. For a schema property named model_dump, runtimeName is still model_dump here and needsAlias stays false, but the planner can later emit the symbol as model_dump_, so the generated Pydantic model uses model_dump_ as the wire name instead of the OpenAPI property model_dump.
Technical details
# Pydantic alias is decided before planner conflict resolution
## Affected sites
- `packages/openapi-python/src/plugins/pydantic/dsl/decl/field.ts:74` — `runtimeName` no longer includes the reserved-member suffix before `needsAlias` is computed.
- `packages/codegen-core/src/planner/analyzer.ts:82` — injected `BaseModel` child names now defer the suffix decision to planner conflict resolution.
- `packages/codegen-core/src/planner/planner.ts:421` — the eventual `finalName` is selected after `PydanticFieldDsl._build()` has already decided whether to emit `Field(..., alias=...)`.
## Required outcome
- When a Pydantic field's emitted Python identifier differs from its OpenAPI property name because of either sanitization or symbol conflict resolution, the generated field preserves the original property name via `Field(..., alias=...)`.
- Fields colliding with inherited `BaseModel` members such as `model_dump`, `model_validate`, `schema`, or `dict` should still deserialize and serialize using the original OpenAPI property name.
## Suggested approach
Either keep the Pydantic reserved-member suffixing in `PydanticFieldDsl` so alias decisions remain local and deterministic, or move alias emission to a point where the planned symbol `finalName` is available and can be compared with the original property name.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3945 +/- ##
==========================================
- Coverage 37.37% 37.34% -0.03%
==========================================
Files 654 653 -1
Lines 22397 22429 +32
Branches 6501 6510 +9
==========================================
+ Hits 8370 8377 +7
- Misses 11373 11394 +21
- Partials 2654 2658 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |

No description provided.