Handle required-only allOf constraints - #2850
Conversation
Translate exact required-only allOf members through the existing required-property flow while preserving unsafe, annotated, polymorphic, and transformed schemas. Fixes openapi-ts#1474 Related to openapi-ts#1520 and openapi-ts#2570
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 89e7c70 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Follow-upAfter opening the PR, I tested the package with a generator that always supplies a custom Commit This keeps transformed output concise: WithRequiredObject<CompanyResource, "organization" | "addresses" | "processingTypes">The implementation deliberately keeps The first transform-aware version was much larger than necessary. Commit
That reduced the PR from 2,890 additions to 1,436 additions without dropping supported behavior. The final suite passes with 306 tests. TypeScript checks, generated examples, build and package exports, the DigitalOcean fixture, live schema generation, and a freshly packed consumer all pass. The live callback-enabled schema produces three concise helper references, no NotesThe follow-up commit has been done entirely by GPT-5.6 Sol. |
Apply typed required-only constraints to the completed transformed intersection while preserving callback replacements and legacy WithRequired behavior.
Consolidate helper generation and reduce duplicated tests while preserving transform support and collision-safe output.
6c81ae2 to
89e7c70
Compare
Summary
Handle
allOfmembers that only make existing object properties required.Fixes #1474
Related to #1520 and #2570
Problem
Given a schema such as:
openapi-typescriptgeneratedBase & Record<string, never>. The second member is a presence constraint, but it was transformed as an empty object, making the resulting type effectively unusable.Solution
Exact
{ required: [...] }and{ type: object, required: [...] }members are translated through the existing parentrequiredflow. For referenced schemas this producesWithRequired<Base, "name">instead of an empty-object intersection.The implementation is intentionally conservative:
allOfreferences are followed with cycle protection.The main logic is in
transform/schema-object.ts. The composition tests include generated TypeScript compilation checks, and the DigitalOcean fixture was regenerated because it contains several real examples of this schema pattern.Validation
Notes
While the original implementation has been written by me, after several rounds of validation by GPT-5.6 Sol it found so many corner cases that it basically rewrote it from scratch.