Skip to content

feat(v25): undefined input schema for factories and middlewares by default#2777

Merged
RobinTail merged 17 commits intomake-v25from
undefined-input-schema
Jun 30, 2025
Merged

feat(v25): undefined input schema for factories and middlewares by default#2777
RobinTail merged 17 commits intomake-v25from
undefined-input-schema

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Jun 29, 2025

Related to #2762

This should simplify intersections, remove redundant EmptySchema when it's not really needed, keeping it only for the final one.

I also realized that doing final intersection within ::build() makes it intersect middleware schemas for every endpoint built on the factory. It can be simpler now.

Summary by CodeRabbit

  • Refactor

    • Streamlined schema extension and middleware logic for improved consistency and maintainability.
    • Simplified schema handling by allowing undefined schemas instead of default empty schemas.
    • Unified and clarified type abstractions for schema extension and final input schema construction.
  • Tests

    • Updated test cases to reflect new schema handling and extension logic.
    • Improved coverage for schema merging scenarios and middleware behavior.

@RobinTail RobinTail added this to the v25 milestone Jun 29, 2025
@RobinTail RobinTail added enhancement New feature or request breaking Backward incompatible changes labels Jun 29, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change refactors schema extension and middleware logic in the EndpointsFactory and related modules. It introduces new abstractions for schema intersection, updates middleware input schema handling to allow undefined, and simplifies schema composition. Tests are updated to reflect the new approach, expecting undefined instead of empty schemas where appropriate.

Changes

File(s) Change Summary
express-zod-api/src/endpoints-factory.ts Refactored EndpointsFactory to use new schema extension methods, replaced #create with #extend, updated middleware addition methods, and changed handler/build logic to use new schema abstractions.
express-zod-api/src/io-schema.ts Removed Ramda, replaced ConditionalIntersection with Extension, added ensureExtension, FinalInputSchema, and makeFinalInputSchema for schema composition and intersection handling.
express-zod-api/src/middleware.ts Allowed middleware input schema to be undefined, updated constructor and execution logic, and changed default schema handling to use emptySchema only when necessary.
express-zod-api/tests/endpoints-factory.spec.ts Updated tests to expect undefined for schema when omitted, removed references to EmptySchema, and adjusted type assertions for factories and middleware.
express-zod-api/tests/io-schema.spec.ts Replaced tests for deprecated schema helpers with tests for makeFinalInputSchema and ensureExtension, covering new intersection and extension behaviors.
express-zod-api/tests/middleware.spec.ts Updated tests to expect undefined schema when not provided, removed unused imports, and adjusted assertions for middleware schema property.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EndpointsFactory
    participant Middleware

    User->>EndpointsFactory: addMiddleware(middleware)
    EndpointsFactory->>Middleware: access schema (may be undefined)
    EndpointsFactory->>EndpointsFactory: #extend(middleware)
    EndpointsFactory->>EndpointsFactory: ensureExtension(currentSchema, middleware.schema)
    EndpointsFactory-->>User: returns new EndpointsFactory with updated schema
Loading

Possibly related PRs

  • #2776: Also refactors the #create method in EndpointsFactory, but with different logic and purpose.
  • #2762: Modifies schema intersection types in EndpointsFactory, related to how input schemas are handled and intersected.

Suggested labels

refactoring, coverage

Poem

A rabbit hopped through fields of code,
Where schemas once would overload.
Now undefined, the fields are clear,
Extensions simple, logic near.
With tests refreshed and types anew,
This garden grows—thanks to the dev crew!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb62f90 and 1e71529.

⛔ Files ignored due to path filters (2)
  • express-zod-api/tests/__snapshots__/index.spec.ts.snap is excluded by !**/*.snap
  • express-zod-api/tests/__snapshots__/io-schema.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • express-zod-api/src/endpoints-factory.ts (5 hunks)
  • express-zod-api/src/io-schema.ts (1 hunks)
  • express-zod-api/src/middleware.ts (6 hunks)
  • express-zod-api/tests/endpoints-factory.spec.ts (4 hunks)
  • express-zod-api/tests/io-schema.spec.ts (3 hunks)
  • express-zod-api/tests/middleware.spec.ts (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RobinTail RobinTail added the miracle Mysterious events are happening here label Jun 29, 2025
RobinTail added a commit that referenced this pull request Jun 29, 2025
I think it's a legacy that it used to be static.
It could be simplified now.

I'd like to reuse it for #2777 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

* **Refactor**
* Improved internal logic for endpoint factory creation to enhance
maintainability. No changes to user-facing features or behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@RobinTail RobinTail force-pushed the undefined-input-schema branch from fb14e2a to 63d390e Compare June 29, 2025 18:27
@RobinTail RobinTail force-pushed the undefined-input-schema branch from ac7b829 to 1fe4fe1 Compare June 29, 2025 20:31
@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented Jun 30, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 1e71529 on undefined-input-schema
into fb62f90 on make-v25.

@RobinTail
Copy link
Copy Markdown
Owner Author

Experiment is the success!

@RobinTail RobinTail changed the title Exp: undefined input schema feat(v25): undefined input schema Jun 30, 2025
@RobinTail RobinTail marked this pull request as ready for review June 30, 2025 08:56
@RobinTail RobinTail changed the title feat(v25): undefined input schema feat(v25): undefined input schema for factories and middlewares by default Jun 30, 2025
@RobinTail
Copy link
Copy Markdown
Owner Author

RobinTail commented Jun 30, 2025

— what exactly is breaking here?
Middleware::handler::input can be unknown if the input schema is not set.

Comment thread express-zod-api/src/io-schema.ts Outdated
Comment thread express-zod-api/src/middleware.ts
Comment thread express-zod-api/src/middleware.ts Outdated
@RobinTail RobinTail merged commit 8ccf714 into make-v25 Jun 30, 2025
13 checks passed
@RobinTail RobinTail deleted the undefined-input-schema branch June 30, 2025 16:14
@RobinTail
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 30, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

RobinTail added a commit that referenced this pull request Aug 2, 2025
### Dedication


![image](https://github.com/user-attachments/assets/47dc18f9-70fa-4276-9c79-2a84ef360642)

**Sara Millerey González** was a 32 years young trans woman from Bello,
Antioquia, Colombia.
She was killed in April 2025. Millerey was raped, tortured, and thrown
into a ravine by a group of men. Denounced as a hate crime by press and
Antioquia's mayor, the Colombian National Working Group on Violence
Based on Victims' Sexual Orientation or Gender Identity is collaborating
with the Attorney's General's Office on identifying remaining suspects.

Transgender women suffer too frequently from transphobic violence and
cruelty, being the less protected social group. I'd like to raise an
awareness of this problem. Humans should be creators — not killers. But
most importantly, I want every transgender girl to have an opportunity
to create applications quickly and, in general, learn to write code
easily in order to receive job offers and leave dangerously transphobic
territories for more favorable and civilized ones, and live happily
there. Protect transgender women.

### Breaking

- `zod` version is `^4.0.0`;
  - Compatibility with `zod@^3` is dropped;
  - You SHOULD now `import { z } from "zod"` without the `/v4` suffix;
- Node.js version is `^20.19.0 || ^22.12.0 || ^24.0.0`;
  - The framework distribution is now ESM-only (finally);
  - All the Node.js versions listed above support `require(ESM)` syntax;
- Changes to the `Middleware` class:
- When the `input` schema is not defined, the `input` argument of the
`handler` method is now `unknown`;
- Plugin changes to metadata:
  - `example` removed;
  - object-based `examples` removed (only array remains);
- use either `.example()` or `.meta({})` with `examples` being an array.
- Public `getExamples()` helper removed:
  - use `.meta()?.examples` or `globalRegistry.get()?.examples` instead.

### Content

- #2622 
- #2711 
- #2740 
- #2742 
- #2777 
- #2809 
- #2814 
- #2815 
- #2842 
- #2843 
- #2844 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

* **New Features**
* Dropped support for Zod v3; now requires Zod v4 and updates all
imports to use `"zod"` directly.
* Framework is now distributed as ESM-only and supports Node.js
^20.19.0, ^22.12.0, or ^24.0.0.
  * Introduced a unified empty schema utility for input/output defaults.
* Added Vitest configuration with experimental eventsource flag for
testing.

* **Breaking Changes**
* Removed the public `getExamples()` helper; access examples via
`.meta()?.examples` or the global registry.
* Middleware and factory input schemas now default to `undefined` when
omitted, not an empty object schema.
* Dropped support for object-based `examples` in schema metadata; use
`.example()` or array-based `examples` instead.
* Removed deprecated enum and literal depicters from documentation
helpers.
* Updated import paths from `"zod/v4"` to `"zod"` throughout codebase
and examples.
* Adjusted migration rules to reflect import and metadata changes only.

* **Bug Fixes**
* Improved handling of empty schemas and type inference for middleware
and endpoint factories.

* **Chores**
* Updated documentation and changelogs for new Zod import paths and
version requirements.
* Updated build, test, and lint configurations for ESM-only output and
new dependency versions.
* Adjusted GitHub workflows to monitor new branches and updated Node.js
versions.
* Removed legacy migration rules and simplified migration logic focusing
on import and metadata changes.
* Removed legacy dependencies like `undici` and adjusted package
metadata.
  * Simplified ESLint and tsup configurations for ESM-only builds.
  * Updated startup logo dedication message.

* **Tests**
* Refactored and updated tests to align with new schema defaults and Zod
v4 usage.
* Simplified migration tests and rules to focus on import path changes.
  * Added tests for new empty schema utilities.

* **Style**
  * Updated dedication message in the startup logo.

* **Revert**
* Removed legacy and deprecated migration logic and configuration
overrides.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Backward incompatible changes enhancement New feature or request miracle Mysterious events are happening here

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant