fix: update discriminator.mapping values during multi-file $ref bundling#3400
fix: update discriminator.mapping values during multi-file $ref bundling#3400littlemyx wants to merge 2 commits intohey-api:mainfrom
Conversation
When @hey-api/json-schema-ref-parser bundles multi-file OpenAPI schemas, $ref objects get rewritten to internal paths (e.g. #/components/schemas/providers_Foo), but discriminator.mapping values (plain strings, not $ref objects) were left unchanged. This caused discriminatorValues() to fail matching and fall back to using the schema name instead of the mapping key, producing incorrect TypeScript discriminator types. Two fixes: - bundle.ts: add updateDiscriminatorMappings() post-processing step that walks the bundled schema and rewrites stale mapping values by matching against the already- corrected $ref values in sibling oneOf/anyOf arrays. Handles URL-encoded non-ASCII characters to avoid false positives on single-file schemas. - index.ts: in mergeMany()'s cloneAndRewrite(), also rewrite discriminator.mapping values using the same rewriteRef() logic as $ref keys. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
|
|
@littlemyx is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3400 +/- ##
==========================================
+ Coverage 39.50% 39.74% +0.24%
==========================================
Files 473 473
Lines 17119 17204 +85
Branches 5217 5251 +34
==========================================
+ Hits 6763 6838 +75
- Misses 8301 8314 +13
+ Partials 2055 2052 -3
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/types
@hey-api/vite-plugin
commit: |
- Multi-file test: verifies that discriminator.mapping values are updated to match rewritten $ref paths when bundling external schemas - Single-file test: verifies that mapping values are not modified when all refs are already internal and correct - Test spec files: two-file OpenAPI schema with oneOf + discriminator.mapping Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Fixes #3399
@hey-api/json-schema-ref-parserbundles multi-file OpenAPI schemas,$refobjects get rewritten to internal paths (e.g.#/components/schemas/providers_Foo), butdiscriminator.mappingvalues (plain strings, not$refobjects) were left unchangeddiscriminatorValues()to fail matching and fall back to using the schema name instead of the mapping key, producing incorrect TypeScript discriminator types (e.g.type: 'providers_JetBrainsProviderConfigResponse'instead oftype: 'jetbrains')@hey-api/json-schema-ref-parser:updateDiscriminatorMappings()that walks the bundled schema and rewrites stale mapping values by matching against the already-corrected$refvalues in siblingoneOf/anyOfarraysmergeMany()'scloneAndRewrite(), also rewritediscriminator.mappingvalues using the samerewriteRef()logic as$refkeysTest plan
oneOf+discriminator.mappingthat generatedtypes.gen.tscontains correct discriminator values from mapping keys🤖 Generated with Claude Code