Skip to content

Comments

feat: add bulk callback and async support for patch.schemas#3415

Merged
mrlubos merged 6 commits intomainfrom
copilot/support-bulk-callback-schemas
Feb 18, 2026
Merged

feat: add bulk callback and async support for patch.schemas#3415
mrlubos merged 6 commits intomainfrom
copilot/support-bulk-callback-schemas

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Large OpenAPI specs (e.g., DMTF Redfish with 1600+ schemas) require name-based transformations across all schemas. Current API forces explicit enumeration, which is impractical at scale.

Changes

  • Type system: Extended patch.schemas to accept either Record<string, fn> (existing) or (name, schema) => void | Promise<void> (new bulk callback)
  • Implementation: Added function type discrimination and iteration for both OpenAPI v2 (definitions) and v3 (components.schemas). All callbacks now properly awaited.
  • Tests: Added coverage for bulk callbacks, async operations, version extraction pattern, and invalid schema handling for both spec versions.

Usage

// Before: enumerate every schema (impractical for 1600+ schemas)
patch: {
  schemas: {
    'ServiceRoot_v1_20_0': (schema) => { /* ... */ },
    // ... 1600+ more
  }
}

// After: single callback handles all, with async support
patch: {
  schemas: async (name, schema) => {
    const metadata = await fetchSchemaMetadata(name);
    const match = name.match(/_v(\d+)_(\d+)_(\d+)_/);
    if (match) {
      schema.description = `${schema.description}\n@version ${match[1]}.${match[2]}.${match[3]}`;
    }
  }
}

Backward compatible with existing Record-based usage.

Original prompt

This section details on the original issue you should resolve

<issue_title>patch.schemas — support bulk callback for all schemas</issue_title>
<issue_description>### Description

Use Case

When working with large specs like DMTF Redfish (~1600+ schemas), we need to apply transformations to every schema based on its name — not just to specific named schemas. For example, extracting version info from schema names and annotating descriptions:

// Current: must enumerate every schema by name (impractical for 1600+ schemas)
patch: {
  schemas: {
    'ServiceRoot_v1_20_0_ServiceRoot': (schema) => {
      schema.description += '\n@version 1.20.0';
    },
    // ... 1600+ more entries
  },
}

The only alternative today is patch.input, which works but is a much heavier tool for what is conceptually a per-schema operation.

Proposal

Allow patch.schemas to accept a function in addition to the existing Record<string, fn>. When a function is provided, it is called for every schema with (name, schema):

// Proposed: bulk callback receives (name, schema) for every schema
patch: {
  schemas: (name, schema) => {
    const match = name.match(/_v(\d+)_(\d+)_(\d+)_/);
    if (match) {
      schema.description = (schema.description || '') +
        `\n@version ${match[1]}.${match[2]}.${match[3]}`;
    }
  },
}

Suggested Implementation

In packages/shared/src/openApi/shared/utils/patch.ts, the existing schemas loop (line ~82) would add a function branch:

if (patchOptions.schemas && spec.components?.schemas) {
  if (typeof patchOptions.schemas === 'function') {
    for (const [key, schema] of Object.entries(spec.components.schemas)) {
      if (schema && typeof schema === 'object') {
        patchOptions.schemas(key, schema);
      }
    }
  } else {
    for (const key in patchOptions.schemas) {
      const schema = spec.components.schemas[key];
      if (!schema || typeof schema !== 'object') continue;
      patchOptions.schemas[key]!(schema);
    }
  }
}

The type in packages/shared/src/config/parser/patch.ts would become:

schemas?: Record<string, (schema: SchemaObject) => void>
  | ((name: string, schema: SchemaObject) => void);

Other Use Cases

This pattern is useful for any bulk per-schema transformation:

  • Stripping vendor extensions (x-*) from all schemas
  • Adding @deprecated based on naming conventions
  • Injecting additionalProperties: false on all object schemas
  • Normalizing description formatting

Applying the same pattern to patch.operations, patch.parameters, etc. would also be valuable.</issue_description>

<agent_instructions>Do as the man says</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@bolt-new-by-stackblitz
Copy link

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

@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: e494f4d

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

This PR includes changesets to release 3 packages
Name Type
@hey-api/shared Patch
@hey-api/openapi-ts Patch
@hey-api/openapi-python 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

vercel bot commented Feb 18, 2026

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

Project Deployment Actions Updated (UTC)
hey-api-docs Ready Ready Preview, Comment Feb 18, 2026 10:38pm

Request Review

- Updated type definition to allow function signature in addition to Record
- Implemented bulk callback for OpenAPI v3 schemas
- Implemented bulk callback for OpenAPI v2 (swagger) definitions
- Added comprehensive tests for both v2 and v3 specs
- Tests cover basic callbacks, mutations, version extraction, and invalid schema handling

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for bulk callback for all schemas feat: support bulk callback for patch.schemas Feb 18, 2026
Copilot AI requested a review from mrlubos February 18, 2026 21:55
- Updated type definition to allow Promise<void> return type for both Record and bulk callback
- Updated implementation to await all schema callback invocations (v2 and v3)
- Added comprehensive tests for async bulk callbacks and async Record-based callbacks
- Verified with manual CLI test that async operations work correctly

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title feat: support bulk callback for patch.schemas feat: add bulk callback and async support for patch.schemas Feb 18, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 18, 2026
@mrlubos mrlubos marked this pull request as ready for review February 18, 2026 22:42
@pullfrog
Copy link

pullfrog bot commented Feb 18, 2026

Leaping into action...

Pullfrog  | View workflow run | Using OpenCode | Triggered by Pullfrogpullfrog.com𝕏

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. feature 🚀 Feature request. labels Feb 18, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@3415

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

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

@hey-api/nuxt

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

@hey-api/openapi-ts

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

@hey-api/shared

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

@hey-api/types

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

@hey-api/vite-plugin

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@3415

commit: e494f4d

@mrlubos mrlubos merged commit 714413e into main Feb 18, 2026
10 checks passed
@mrlubos mrlubos deleted the copilot/support-bulk-callback-schemas branch February 18, 2026 22:44
@hey-api hey-api bot mentioned this pull request Feb 17, 2026
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.96%. Comparing base (ab6942f) to head (e494f4d).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3415      +/-   ##
==========================================
+ Coverage   38.93%   38.96%   +0.03%     
==========================================
  Files         473      473              
  Lines       17292    17302      +10     
  Branches     5218     5218              
==========================================
+ Hits         6732     6742      +10     
  Misses       8480     8480              
  Partials     2080     2080              
Flag Coverage Δ
unittests 38.96% <100.00%> (+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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 🚀 Feature request. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patch.schemas — support bulk callback for all schemas

2 participants