Repository navigation
Fix patternProperties parent name inference - #841
terminalchai wants to merge 3 commits into
Conversation
|
Nice catch and clean fix for issue #161! Fixing the JSDoc parent name inference removes the buggy undefined references in generated TypeScript definitions. LGTM! |
There was a problem hiding this comment.
Thank you @terminalchai — this fixes a wart that has been in the output since 2018 (#161 is the maintainer's own "why is this undefined?"), and the approach is the one I'd have taken: use the name the reader will actually see, fall back to the property key, and drop the clause rather than print something untrue.
Why CI is red, and the one-line fix. Your head (4cd539a) builds and passes on its own base. CI runs on the merge with master, and #837 landed 11 minutes before this PR was opened; it removed the definitionKeyOf helper from src/parser.ts (a definition's key is now stamped on the schema by the normalizer). So every job stops at Build with:
src/parser.ts(705,79): error TS2552: Cannot find name 'definitionKeyOf'. Did you mean 'DefinitionKey'?
Rebase (or merge master) and change that one call in parseRequired:
- const parentSchemaName = schemaNameForComment(standaloneName, nameOf(owner, definitionKeyOf(owner), options))
+ const parentSchemaName = schemaNameForComment(standaloneName, nameOf(owner, owner[DefinitionKey], options))DefinitionKey is already imported there on master. Nothing else conflicts.
Verified locally (bun 1.4.0, your branch + current master 7369533 + that line): bun install --frozen-lockfile && bun run build && CI=true bun run test → 606 pass / 0 fail, lint clean.
- The #161 case itself (Boris's
Procfile/process_typesschema from the original report): master printsreferenced by `undefined`'s, this branch printsreferenced by `process_types`'s.intersection.2likewise goes fromundefinedtoIntersection. - Occurrences of
referenced by `undefined`in the e2e snapshot: master 36 → this branch 0. - Existing snapshot entries whose output changes:
realWorld.openapi,realWorld.schemaStore.1,intersection.2,intersection.3,enum.2,minProperties,required.undeclaredKeys,options.strictIndexSignatures.singlePatternProperty. I diffed all of them against master line by line: 75 changed lines, every one a docblock line — no emitted type changes anywhere. New wordings: the enclosing declaration's name where the object is the body of a named intersection (Parameter,MediaType,Header,HTTPSecurityScheme,Intersection), the property key for inline objects (schemas,responses, … in OpenAPI'sComponents;pattern,definitions,patternPropertiesAllowedin the smaller fixtures), and the neutral "referenced via thepatternProperty…" for the three nameless spots inpackage.json'sexports/typesVersions.
Two small things, neither blocking:
- There's no dedicated fixture for the inline-object case; the coverage is the existing snapshots moving, plus the comment added to
intersection.2.ts. If you're rebasing anyway, a tinytest/e2e/patternProperties.unnamedParent.tswith theProcfileschema from #161 (object propertyprocess_typeswith onepatternPropertiesentry,additionalProperties: false) would pin the exact case the issue describes. Happy to add it in a follow-up otherwise. newInterfacereads the intersection's name back out of theprocessedcache (processed.get(schema[Intersection])?.get('ALL_OF')?.standaloneName). That works for every fixture here and degrades to the key / neutral wording if the entry isn't populated yet, so it can't produce a wrong name — but it does lean on parse order, so a one-line comment saying so would help the next reader.
Recommendation for the maintainer: merge once rebased with the one-line port above. Output change is comments only (listed above), it closes #161, and it supersedes the fix we had queued for the same issue.
Generated by Claude Code
|
Quick follow-up, @terminalchai — two things changed since the review above, both small, plus an offer. 1. The rebase now has one textual conflict (not your doing). #844 landed after my review and threads a new const intersectionName = schema[Intersection]
? processed.get(schema[Intersection])?.get('ALL_OF')?.standaloneName
: undefined
const params = parseSchema(
schema,
scope,
options,
processed,
usedNames,
schemaNameForComment(name ?? intersectionName, keyName),
)plus the 2. One more fallback worth catching. I ran the merged build over 46 real-world schemas (Kubernetes, Stripe, GitHub's REST API, a set from SchemaStore): Minimal input: function schemaNameForComment(standaloneName: string | undefined, keyName: string | undefined): string | undefined {
return (
standaloneName ??
(keyName && keyName !== '[k: string]' && !keyName.includes('{keyNameFromDefinition}') ? keyName : undefined)
)
}A one-schema fixture for that (array items + How you'd like to land it is your call. If you have time to rebase with the above, I'll re-check it the same day. If you'd rather not chase Generated by Claude Code |
4cd539a to
e78021f
Compare
|
Updated the branch with the requested follow-ups:
Verification:
The unnamed array-items fixture now emits the neutral |
|
Thanks @terminalchai — re-checked e78021f cold from a fresh checkout and everything from both reviews is in:
Nothing left to do on your side; this is ready for the maintainer's review. Generated by Claude Code |
e78021f to
d8eed8c
Compare
|
Re-checked d8eed8c cold from a fresh checkout. The rebase onto 5caacfc keeps everything from both earlier reviews in place (
Nothing further from my side — the merge is the maintainer's call. Generated by Claude Code |
Summary
patternPropertiesdocumentation owners from the final intersection name or containing property keyFixes #161
Testing
bun run test(600 tests passed)