Skip to content

refactor: generate orpc contract from openapi#31490

Draft
hyoban wants to merge 40 commits intomainfrom
1-24-kubb-generate
Draft

refactor: generate orpc contract from openapi#31490
hyoban wants to merge 40 commits intomainfrom
1-24-kubb-generate

Conversation

@hyoban
Copy link
Member

@hyoban hyoban commented Jan 24, 2026

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

close #31448

While most interfaces remain in Swagger v2, the OpenAPI v3 migration has already begun.
However, it is in its early stages, and many have not yet been migrated.

Category Status Details
Console API Not work Unable to render schema
Service API Not work Missing $ref pointer "#/components/schemas/DocumentMetadataOperation". Token "DocumentMetadataOperation" does not exist. Missing $ref pointer "#/components/schemas/SegmentUpdateArgs". Token "SegmentUpdateArgs" does not exist. Missing $ref pointer "#/components/schemas/RetrievalMethod". Token "RetrievalMethod" does not exist.
Web API Partial It can generate them, but many of the types are unknown.

related pull request

Flask-RESTX Swagger UI (Legacy)

Each Blueprint using ExternalApi has its own Swagger UI at {url_prefix}/swagger-ui.html:

API Name Swagger UI Path OpenAPI JSON Path
Console API /console/api/swagger-ui.html /console/api/swagger.json
Service API /v1/swagger-ui.html /v1/swagger.json
Web API /api/swagger-ui.html /api/swagger.json
Files API /files/swagger-ui.html /files/swagger.json
Inner API /inner/api/swagger-ui.html /inner/api/swagger.json

FastOpenAPI Documentation (New)

Configured in extensions/ext_fastopenapi.py:

Doc Type Path
Swagger UI /fastopenapi/docs
ReDoc /fastopenapi/redoc
OpenAPI JSON /fastopenapi/openapi.json

FastOpenAPI is currently a PoC and only covers a subset of /console/api endpoints.

Configuration

Controlled via environment variables:

  • SWAGGER_UI_ENABLED: Enable/disable docs (default true)
  • SWAGGER_UI_PATH: Custom path (default /swagger-ui.html)

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@github-actions github-actions bot added the web This relates to changes on the web. label Jan 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hyoban, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the API contract generation process for the web frontend by integrating the Kubb code generation tool. This change automates the creation of ORPC contracts and Zod schemas directly from OpenAPI specifications, aiming to streamline development, reduce manual errors, and ensure strong type consistency between the frontend and backend API definitions.

Highlights

  • New Code Generation Pipeline: Introduced Kubb, a code generation tool, to automate the creation of API contracts from OpenAPI specifications, enhancing type safety and development efficiency.
  • Kubb Configuration Added: A new configuration file, web/kubb.config.ts, has been added to define the Kubb setup, specifying OpenAPI input, output directory, and enabling OAS, Zod, and ORPC plugins.
  • New generate:contract Script: A new npm script, generate:contract, has been added to web/package.json to easily trigger the Kubb code generation process.
  • Dependency Updates: Numerous @kubb packages and @scalar/openapi-parser have been added to web/package.json and web/pnpm-lock.yaml, reflecting the integration of the new code generation tooling.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a code generation setup using Kubb to generate ORPC contracts from an OpenAPI specification. This is a good step towards automating contract generation and ensuring consistency.

However, I've found a few issues:

  • Critical: The package.json file uses local pnpm link for @kubb/plugin-orpc and @kubb/plugin-zod. This will prevent other developers from installing dependencies and building the project. These should be replaced with packages from a public or private registry.
  • Medium: The dependencies @kubb/plugin-react-query and @kubb/plugin-ts are installed but not used in kubb.config.ts. They should be removed if they are not needed.
  • The refactoring appears to be incomplete. The new contracts are generated into the ./gen directory, but the old manually created contract files in web/contract/ are not removed, and their usages are not updated to point to the new generated files. This leaves dead code and an incomplete feature.

Please address these points to ensure the project remains maintainable and buildable for the whole team.

@hyoban hyoban added the status: blocked Waiting for something else to be resolved label Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: blocked Waiting for something else to be resolved web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] OpenAPI specification -> oRPC contract

2 participants