Skip to content

RI-7682 Strengthen API public swagger docs and setup a postinstall script to autogenerate types for clients#5863

Merged
KrumTy merged 27 commits into
mainfrom
feature/RI-7682/openapi-codegen-scaffolding
May 8, 2026
Merged

RI-7682 Strengthen API public swagger docs and setup a postinstall script to autogenerate types for clients#5863
KrumTy merged 27 commits into
mainfrom
feature/RI-7682/openapi-codegen-scaffolding

Conversation

@KrumTy
Copy link
Copy Markdown
Contributor

@KrumTy KrumTy commented May 7, 2026

What

Phase 1 of decoupling the UI from the API codebase (RI-7682).

  • Scaffolds an OpenAPI / typescript-axios client generation pipeline (yarn generate:api-client), regenerated on postinstall and gitignored.
  • Decorates all backend modules currently consumed by the UI with @nestjs/swagger so the generated client emits real types instead of any/void. Strict spec validation is enabled.
  • Generated client lives at redisinsight/api-client/ and is exposed to UI / Storybook / Jest via the apiClient path alias.
  • Adds a warn-only ESLint rule discouraging new apiSrc/* imports from the UI, pointing devs at apiClient/* (RI-7682).

No UI imports are migrated in this PR — that follows per-domain in Phase 2.

Testing

  • yarn install (or yarn generate:api-client) produces redisinsight/api-client/ with no validation errors.

Note

Medium Risk
Adds a new OpenAPI spec dump + client generation step that runs on API postinstall, which can affect install/build workflows and CI caching. Broad Swagger annotation changes across many endpoints may subtly alter the published API schema and generated client types.

Overview
Adds a generated OpenAPI TypeScript client pipeline: the API now dumps openapi.json via a lightweight Nest bootstrap (dump-openapi.ts) and runs @hey-api/openapi-ts to output redisinsight/api-client/ (gitignored), exposed via the new apiClient/* alias in TS, Vite/Storybook, and Jest.

Strengthens Swagger/OpenAPI typing across multiple API modules by standardizing Redis string schemas (ApiRedisString), fixing/adding response metadata (@ApiOkResponse, correct isArray/type), and improving union/discriminator schemas (e.g., REJSON, RDI statistics). Also adds a warn-only ESLint no-restricted-imports rule to discourage new UI imports from apiSrc/* in favor of apiClient/*, and updates test Docker installs to skip client generation when needed (SKIP_API_CLIENT_GEN=1).

Reviewed by Cursor Bugbot for commit 2f08733. Bugbot is set up for automated code reviews on this repo. Configure here.

KrumTy added 23 commits May 5, 2026 16:29
Add tooling to auto-generate a typescript-axios client from the
NestJS Swagger spec on yarn install. The spec and the generated
client are treated as ephemeral build artifacts (gitignored), so
the BE Swagger decorators remain the single source of truth.

- Pin openapi-generator-cli to 7.14.0 via openapitools.json
- Add dump-openapi.ts to extract the spec without an HTTP listener
- Wire postinstall hook to regenerate the client on every install
- Port ApiRedisString decorator for Buffer/RedisString wire format
- Lint guard against new apiSrc/* and src/* imports from the UI

References: #RI-7682
Fix 7 schema/path issues so the generator runs without
--skip-validate-spec:

- rdi-statistics: register union members (Table/Blocks/Info sections)
  as top-level schemas via @ApiExtraModels + getSchemaPath
- vector-set DTOs: drop redundant isArray on number[] fields that
  produced nested arrays in the spec
- bulk-actions and database-analysis controllers: declare the
  {dbInstance} path parameter via @ApiRedisParams

Refs RI-7682
Add @ApiProperty/@ApiPropertyOptional to all fields on the
Notification class so the generated client surfaces a real
Notification interface and types NotificationsDto.notifications
as Array<Notification> (was Array<object>).

Refs RI-7682
Two response-type bugs caused the generated client to expose the
wrong shapes for two database endpoints:

- bulkDeleteDatabaseInstance declared DeleteDatabasesDto (the
  request body shape) but actually returns DeleteDatabasesResponse.
- exportConnections returns ExportDatabase[] but the swagger
  metadata was missing isArray: true, so it appeared as a single
  object in the spec.

Fix the @apiendpoint responses metadata to match the actual return
types. The generated client now exposes
AxiosPromise<DeleteDatabasesResponse> and
AxiosPromise<Array<ExportDatabase>>.

Refs RI-7682
Adopt @ApiRedisString for RedisString/Buffer fields and add response-type
decorators on keys.controller endpoints so the generated TS client emits
proper interfaces and array-typed responses.

Refs RI-7682
Apply targeted improvements from PR #4725:
- list endpoint: correct description and array response type
- update endpoint: correct description (analysis vs instance)
- get/update endpoints: declare :id path param
- models: mark NspSummary arrays with isArray, switch Key.name and
  NspSummary.nsp to ApiRedisString to model the wire format

dbInstance path param remains declared via the class-level
ApiRedisParams() introduced in the strict-validation commit.

Refs RI-7682
- drop unused ApiPropertyOptional/ApiProperty imports left over after
  switching to ApiRedisString
- prettier formatting in cloud-auth-request-info, cloud-auth-response,
  and rdi-statistics

Refs RI-7682
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Code Coverage - Frontend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 82.63% 24202/29288
🟡 Branches 67.84% 10189/15020
🟡 Functions 77.74% 6529/8398
🟢 Lines 83.11% 23656/28465

Test suite run success

6775 tests passing in 786 suites.

Report generated by 🧪jest coverage report action from 2f08733

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Code Coverage - Backend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 92.57% 15404/16641
🟡 Branches 74.48% 4813/6462
🟢 Functions 86.54% 2391/2763
🟢 Lines 92.39% 14720/15933

Test suite run success

3357 tests passing in 305 suites.

Report generated by 🧪jest coverage report action from 2f08733

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Code Coverage - Integration Tests

Status Category Percentage Covered / Total
🟡 Statements 79.81% 17433/21843
🟡 Branches 62.26% 7970/12801
🟡 Functions 68.55% 2418/3527
🟡 Lines 79.37% 16390/20649

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

valkirilov
valkirilov previously approved these changes May 7, 2026
@@ -0,0 +1,27 @@
#!/usr/bin/env node
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I see the dump scripts live inside the API, but this API client, which should be used by the UI, is placed here on the root level. Is this intentional, or can we move it one level deeper, inside redisinisght/ui?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The auto generated client is intentionally outside ui and api. We will have better control over it if it's not tied to the ui. E.g. in future we might use it in VSCode as well or publish it as a package even

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So basically, it will be a "shared package" after all - just not manually created (as @ArtemHoruzhenko asked), but automatically generated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"shared" as in all API consumers can reuse it, yes
and autogenerated based on API swagger docs, yes

Comment thread .eslintrc.js
// RI-7682: discourage new BE -> FE coupling. Existing imports are still allowed
// (warn-only) until per-domain migration replaces them with `apiClient/*`.
// Flips to 'error' once Phase 2 is complete.
'no-restricted-imports': [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good idea 👍

Comment thread redisinsight/api/test/test-runs/test.Dockerfile Outdated
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@KrumTy KrumTy changed the title RI-7682 Decouple FE and BE — scaffold OpenAPI client pipeline RI-7682 Strengthen API public swagger docs and setup a postinstall script to autogenerate types for clients May 7, 2026
@KrumTy KrumTy marked this pull request as ready for review May 7, 2026 13:54
@KrumTy KrumTy requested a review from a team as a code owner May 7, 2026 13:54
Comment thread redisinsight/api/src/modules/cloud/auth/cloud-auth.controller.ts Outdated
Comment thread redisinsight/api/src/modules/cloud/auth/cloud-auth.service.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c6c8af9. Configure here.

Comment thread redisinsight/api/openapitools.json Outdated
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 7, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 8, 2026

❌ Jit Scanner failed - Our team is investigating

Jit Scanner failed - Our team has been notified and is working to resolve the issue. Please contact support if you have any questions.


💡 Need to bypass this check? Comment @sera bypass to override.

@KrumTy KrumTy requested a review from valkirilov May 8, 2026 09:24
@KrumTy
Copy link
Copy Markdown
Contributor Author

KrumTy commented May 8, 2026

@sera bypass

@KrumTy KrumTy merged commit 7bb7270 into main May 8, 2026
29 checks passed
@KrumTy KrumTy deleted the feature/RI-7682/openapi-codegen-scaffolding branch May 8, 2026 13:27
@mrlubos
Copy link
Copy Markdown

mrlubos commented May 8, 2026

@KrumTy @valkirilov feedback on @hey-api would be welcome as you use it more!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants