Skip to content

chore: add children and overrides to symbols#3945

Merged
mrlubos merged 1 commit into
mainfrom
chore/core-symbol-children
May 27, 2026
Merged

chore: add children and overrides to symbols#3945
mrlubos merged 1 commit into
mainfrom
chore/core-symbol-children

Conversation

@mrlubos
Copy link
Copy Markdown
Member

@mrlubos mrlubos commented May 27, 2026

No description provided.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

🦋 Changeset detected

Latest commit: 13c3d7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hey-api/codegen-core Patch
@hey-api/openapi-ts Patch
@hey-api/openapi-python Patch
@hey-api/shared Patch

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment May 27, 2026 7:30pm

Request Review

@mrlubos mrlubos marked this pull request as ready for review May 27, 2026 19:24
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. internal ⚙️ Internal development work. labels May 27, 2026
Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Symbol metadataSymbol now carries children and override state, and the public package exports the related symbol and resolver types.
  • Teach the planner about inherited child namesAnalysisContext.injectChildren registers base-class child names in class scopes, and Planner.nameIsAvailable treats them as soft conflicts unless a symbol opts into override.
  • Use Python-specific conflict suffixespythonNameConflictResolver emits the first conflict as name_, and Python is wired to use it by default.
  • Move Pydantic reserved members into symbolsPYDANTIC.BaseModel now declares inherited child names, while PydanticFieldDsl drops its direct BASE_MODEL_RESERVED alias handling.
  • Refresh generated Python snapshots — OpenCode snapshots now reflect the new first-conflict Python suffixing for models and SDK classes.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using GPT𝕏

const snake = toCase(name, 'snake_case');
const safe = safeRuntimeName(snake);
const runtimeName = BASE_MODEL_RESERVED.has(safe) ? `${safe}_` : safe;
const runtimeName = safe;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This loses the JSON alias when the planner renames a field only because it conflicts with an injected 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
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 44.23077% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.34%. Comparing base (8fbcd3e) to head (13c3d7d).

Files with missing lines Patch % Lines
packages/codegen-core/src/symbols/symbol.ts 33.33% 8 Missing ⚠️
packages/codegen-core/src/planner/analyzer.ts 0.00% 3 Missing and 4 partials ⚠️
packages/codegen-core/src/planner/scope.ts 69.23% 3 Missing and 1 partial ⚠️
packages/codegen-core/src/planner/resolvers.ts 25.00% 2 Missing and 1 partial ⚠️
packages/codegen-core/src/planner/planner.ts 81.81% 2 Missing ⚠️
packages/openapi-python/src/py-dsl/decl/class.ts 0.00% 2 Missing ⚠️
packages/openapi-ts/src/ts-dsl/decl/class.ts 0.00% 1 Missing and 1 partial ⚠️
...napi-python/src/plugins/pydantic/dsl/decl/field.ts 0.00% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 37.34% <44.23%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 27, 2026

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@3945

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@3945

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@3945

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@3945

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@3945

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@3945

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@3945

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@3945

commit: 13c3d7d

@mrlubos mrlubos merged commit 294ea6e into main May 27, 2026
12 checks passed
@mrlubos mrlubos deleted the chore/core-symbol-children branch May 27, 2026 19:32
@hey-api hey-api Bot mentioned this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal ⚙️ Internal development work. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant