Skip to content

feat: swagger editor - #70

Merged
AlyaEngineer merged 9 commits into
developfrom
feature/3-swagger-editor
Jul 9, 2026
Merged

feat: swagger editor#70
AlyaEngineer merged 9 commits into
developfrom
feature/3-swagger-editor

Conversation

@AlyaEngineer

@AlyaEngineer AlyaEngineer commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

This PR delivers the core Swagger Editor functionality - loading and editing OpenAPI/Swagger schemas in both JSON and YAML, with automatic format detection, format conversion, and validation. It also lays the groundwork for the Swagger Viewer and schema persistence, both still in progress.

Changes Made

  • implemented schema parsing with automatic JSON/YAML detection and format conversion (schema-format.ts)
  • implemented schema validation via SwaggerParser with error reporting
  • built the Monaco-based code editor (SwaggerMonacoEditor) with format-aware syntax highlighting and theme synced to the app's color scheme
  • built SwaggerControl with format toggle and save action (save currently blocked pending working authentication)
  • built the responsive split view (SwaggerEditor) that adapts editor/viewer layout based on screen orientation
  • added SwaggerViewer as a placeholder component, wired into SwaggerEditor with endpoints/isValid props already flowing correctly - full implementation is in progress in a follow-up story
  • added SchemaService for save/restore API calls, with timeout handling and payload validation
  • added tests

Related issue

Closes #40 #41 #42 #43 #46

Feature

Feature 3: Swagger Editor

Acceptance criteria

Feature 1: App Header
  • Non-auth users see Sign In / Sign Up in header (upper right) — 15
  • Auth users see History / Sign Out in header — 10
  • About link in header and footer — 10
  • Expired/invalid token → redirect from private routes to Main — 10
  • Sign In / Sign Up buttons redirect to respective form route — 15
Feature 2: Sign In / Sign Up
  • Sign In / Sign Up / Sign Out buttons present everywhere they should be — 10
  • Client-side validation (email, password: 8+ chars, letter+digit+special, Unicode) — 20
  • Successful login → redirect to Main — 10
  • Logged-in user on Sign In / Sign Up routes → redirect to Main — 10
Feature 3: Swagger Editor
  • Load/paste schema in JSON and YAML — 25
  • Auto-detect input format (JSON vs YAML) — 20
  • Format switch with JSON ↔ YAML conversion, no data loss — 20
  • Schema validation with error indication — 15
  • Auth users save schema; restored on next login — 10
  • Viewer auto-populates with endpoints on valid schema — 10
  • Responsive split view (horizontal/vertical by orientation) — 20
Feature 4: Swagger Viewer
  • Endpoint list organized by path/method — 20
  • Details: method, path, all param types (path/query/header/cookie) — 25
  • Request schema and example payloads displayed — 20
  • Response schema, examples, all status codes displayed — 25
  • Try-It-Out: fill params/headers/body, execute, show response — 20
  • Generate cURL + copy-to-clipboard — 10
Feature 5: History and Analytics
  • SSR-generated; empty state with links to editor/viewer — 15
  • Requests sorted by timestamp (most recent first) — 10
  • Server-side analytics: duration, status, timestamp, method, request size, response size, error details, endpoint/URL — 45
Feature 6: About Page
  • Public route, accessible to all — 5
  • Info about RS School course — 5
  • Team info (names, roles, GitHub links) — 10
  • Design consistent with the app — 5
Feature 7: General Requirements
  • i18n: 2+ languages with toggler in header — 30
  • Sticky header with animation on stick — 10
  • User-friendly error display — 10
  • Private routes protected (401 if not authenticated) — 5
Feature 8: YouTube Video
  • 5–7 min YouTube walkthrough linked, covers all criteria — 50

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would break existing functionality)
  • Documentation update

Checklist

  • Self-review done
  • No console errors / warnings / logs
  • No any / @ts-ignore
  • Tests added / updated and passing

Screenshots

Снимок экрана 2026-07-09 155348 Снимок экрана 2026-07-09 155357 Снимок экрана 2026-07-09 155410 Снимок экрана 2026-07-09 155449 Снимок экрана 2026-07-09 155424

Summary by CodeRabbit

  • New Features

    • Added a Swagger editor experience with schema validation, format switching, save actions, and an endpoint preview.
    • Added support for editing schemas in both YAML and JSON, including automatic format detection and conversion.
    • Introduced a starter OpenAPI schema and updated app copy for the new editor workflow.
  • Bug Fixes

    • Improved error handling for invalid schema input, save failures, and restore timeouts.
    • Added safeguards for schema parsing and endpoint extraction to better handle empty or malformed content.
  • Tests

    • Added coverage for the editor, viewer, control actions, schema parsing/conversion, validation, and restore behavior.

YuliaDemir and others added 5 commits July 1, 2026 17:49
* feat: install next+ts+linter+prettier+ husky+redux

* feat: configs + perfectionist + lint fix

* feat: install scss

* refactor: add some folders

* feat: install i18n + basic configs

* feat: add internatiolisation

* feat: language switcher

* feat: dependencies update

* feat: add sticky header

* feat: add mui Button-and-Link-like component

* fix: lint

* style: add style for header

* refactor:  remove css from language selector

* refactor: add const for flex styles in the header boxes

* refactor: history style as link

* fix: add some fixes
* chore: setup libraries

* feat: swagger-editor

* refactor: move title and description into a separated component

* refactor: moved controls into the swaggerControl component

* chore: update package-lock.json

* fix: fix import in swagger-view

* feat: add translations into SwaggerControl, SwaggerEditor, SwaggerViewer

* fix: fix title translation in main text

* fix: enforce unique keys when parsing YAML

* refactor: extract DEFAULT_SCHEMA into a constant

* feat: add tooltip explaining disabled format toggle

* test: add test coverage for schema editing flow

* fix: resolve component type errors in swagger viewer

* fix: add request timeout with AbortController

* fix: preserve Monaco editor undo history and cursor position on format switch

* fix: prevent restore fetch from overwriting user-edited schema

* fix: handle rejected promise in restoreSchema to prevent unhandled rejection

* fix: replace missing setEditorValue with handleEditorChange in SwaggerEditor

* fix: apply syntax highlighting immediately on editor mount

* fix: preserve original JSON parse error

* fix: disable external $ref resolution in schema validation to prevent SSRF

* refactor: split SwaggerControl into service, component, and helper

move save request to schema-service
extract FormatToggle component
extract getSignalWithTimeout helper
switch errors to toast notifications

* refactor: rename useSwaggerHook and drop unnecessary useMemo

* test: fix tests after refactor

* refactor: extract duplicated language-setting logic into helper in SwaggerMonacoEditor

* refactor: remove redundant SwaggerViewer title

* fix: use translated conversionError message instead of hardcoded string

* refactor: extract SchemaFormat and isRecord into shared schema-types module

* fix: reserve space for status alert to prevent layout shift on locale switch

* feat: sync Monaco editor theme with app color scheme

* style: add shadow, border-radius, deduplicate panel styles

* test: fix ReactElement import in swagger-control tests

* feat: extract schema fetch logic into SchemaService with restore and save methods

* fix: extract magic number into named constant

* refactor: extract isRecord type guard into its own module

* fix: validate restore payload and cancel restore request on unmount

* test: add tests for monaco theme

* feat: add SwaggerViewer placeholder component

* fix: route SwaggerControl toast messages through shared toaster namespace

---------

Co-authored-by: Yulia  Demir <Nightelfin91@gmail.com>
@AlyaEngineer AlyaEngineer added the feature-3-editor Feature 3: Swagger Editor label Jul 9, 2026
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
swagger-editor-app Ready Ready Preview, Comment Jul 9, 2026 2:30pm

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 740fac38-c874-488b-b8dc-b4839ee28f02

📥 Commits

Reviewing files that changed from the base of the PR and between 016c079 and ba627da.

📒 Files selected for processing (4)
  • src/i18n/messages/en.json
  • src/i18n/messages/ru.json
  • src/services/schema-service.ts
  • src/utils/hooks/use-swagger.ts
💤 Files with no reviewable changes (2)
  • src/i18n/messages/ru.json
  • src/i18n/messages/en.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/services/schema-service.ts
  • src/utils/hooks/use-swagger.ts

📝 Walkthrough

Walkthrough

Introduces a client-side Swagger/OpenAPI editor with schema parsing, conversion (JSON/YAML), and validation utilities, a useSwagger state hook, a SchemaService for save/restore via /api/schema, and UI components (SwaggerEditor, SwaggerControl, SwaggerMonacoEditor, SwaggerViewer, FormatToggle, MainText), wired into the locale page with new dependencies, i18n strings, and config updates.

Changes

Swagger Editor Feature

Layer / File(s) Summary
Schema types, parsing, conversion, validation utilities
src/utils/swagger-editor/*, package.json, tsconfig.json
Adds SchemaFormat/OpenApiDocument types, isRecord guard, parseSchema/convertSchema for JSON/YAML, validateSwaggerSchema via SwaggerParser, getSwaggerEndpoints, new dependencies (swagger-parser, monaco-editor/react, openapi-types, yaml), and a tsconfig include update, all with unit tests.
SchemaService, timeout helper, useSwagger hook
src/services/schema-service.ts, src/utils/network/get-signal-with-timeout.ts, src/constants/default-schema.ts, src/utils/hooks/use-swagger.ts, ...use-swagger.test.ts
Adds SchemaService.restore/save against /api/schema, an abortable timeout helper, a default OpenAPI schema constant, and useSwagger orchestrating debounced validation, restoration, and format toggling.
SwaggerMonacoEditor component
src/components/swagger-monaco-editor/*
Adds a dynamically-loaded Monaco editor wrapper that syncs language to schema format and theme to MUI color scheme, with tests.
SwaggerViewer component
src/components/swagger-viewer/swagger-viewer.tsx
Adds a placeholder viewer showing invalid/empty/success alerts based on validity and endpoint count.
FormatToggle and SwaggerControl
src/components/format-toggle/*, src/components/swagger-control/*
Adds a format switch component and a save/toggle control that calls SchemaService.save with toast feedback, with tests.
SwaggerEditor page composition and app wiring
src/components/swagger-editor/*, src/app/[locale]/page.tsx, src/components/index.ts, src/components/main-text/*, src/components/header/header.tsx, src/constants/index.ts, src/i18n/messages/*.json
Composes the full editor page, wires it into the locale route and barrel exports, adds MainText, updates Header's flex usage, and adds new i18n copy.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SwaggerEditor
  participant useSwagger
  participant SchemaService
  participant API

  SwaggerEditor->>useSwagger: mount
  useSwagger->>SchemaService: restore(signal)
  SchemaService->>API: GET /api/schema
  API-->>SchemaService: schema payload
  SchemaService-->>useSwagger: RestoredSchema or null
  useSwagger->>useSwagger: validateSwaggerSchema(editorValue)
  useSwagger-->>SwaggerEditor: editorValue, isValid, schema, error
Loading
sequenceDiagram
  participant SwaggerControl
  participant SchemaService
  participant API
  participant ToastProvider

  SwaggerControl->>SchemaService: save(content, format, signal)
  SchemaService->>API: POST /api/schema
  alt success
    API-->>SchemaService: 200 OK
    SchemaService-->>SwaggerControl: resolved
    SwaggerControl->>ToastProvider: show success toast
  else failure or timeout
    API-->>SchemaService: error / aborted
    SchemaService-->>SwaggerControl: throws Error
    SwaggerControl->>ToastProvider: show error toast
  end
Loading

Possibly related issues

  • Feature 3: Swagger Editor (120 points) #31: These changes implement the Swagger Editor feature itself, including schema editing, format switching, validation, endpoint viewing, and save/restore flow described in the retrieved issue.

Possibly related PRs

Suggested reviewers: YuliaDemir, Ivan-khodorov

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also adds validation, viewer, save/restore, i18n, and API service work that goes beyond schema import in #40. Split validation, viewer, save/restore, and related service/i18n changes into separate PRs or link the corresponding issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main addition: a Swagger editor.
Linked Issues check ✅ Passed The PR adds Monaco-based JSON/YAML import, debounced updates, tests, and editor input handling required by #40.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/3-swagger-editor

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (6)
src/utils/hooks/use-swagger.ts (1)

21-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hardcoded auth stub — tracked by TODO.

isAuthenticated is permanently true, so restore logic always runs regardless of actual auth state. This is flagged with a TODO, so likely tracked separately, but worth confirming it's on the backlog before merge to main.

Want me to open a follow-up issue to track wiring real authentication into this hook?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/hooks/use-swagger.ts` around lines 21 - 24, The useSwagger hook
currently hardcodes isAuthenticated to true, so the restore logic always runs
regardless of the real auth state. Replace this stub in use-swagger.ts with the
actual authentication check used by the app, keeping the logic inside useSwagger
tied to the real auth source instead of a temporary TODO. If the real auth
integration is not ready, remove the stubbed behavior and gate the restore path
behind the existing auth state mechanism or confirm the follow-up is tracked
separately.
src/components/swagger-control/swagger-control.tsx (2)

36-58: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No unmount guard around the async save flow.

If the user navigates away or the component unmounts while SchemaService.save is pending, the finally block still calls setIsSaving/cleanup, and a resolved/rejected promise still triggers showToast, against a component/context that may no longer be mounted. Consider aborting on unmount (e.g. call cleanup() from a useEffect cleanup) or guarding state updates with an isMounted ref.

♻️ Suggested fix
+  useEffect(() => {
+    return () => {
+      // abort any in-flight save on unmount
+    };
+  }, []);

Alternatively, track the AbortController/signal returned by getSignalWithTimeout in a ref and call its cleanup() from a useEffect unmount callback so the fetch is aborted rather than left to resolve into an unmounted tree.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/swagger-control/swagger-control.tsx` around lines 36 - 58, The
async save flow in handleSaveSchema lacks an unmount safeguard, so
SchemaService.save can still resolve/reject after the component is gone. Update
the SwaggerControl save path to abort or clean up on unmount by wiring
getSignalWithTimeout/SAVE_TIMEOUT_MS into a useEffect cleanup, or guard
showToast and setIsSaving with an isMounted ref so handleSaveSchema does not
touch unmounted state.

29-32: 📐 Maintainability & Code Quality | 🔵 Trivial

Placeholder auth bypass with TODO.

isAuthenticated is hardcoded to true, guarded only by a TODO. This effectively disables the save-authorization gate for now — please make sure a tracking issue exists before merge.

Want me to open a tracking issue for wiring up real authentication here?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/swagger-control/swagger-control.tsx` around lines 29 - 32, The
auth check in swagger-control is currently bypassed by hardcoding
isAuthenticated to true, so replace this placeholder in swagger-control with the
real authorization flow or remove the bypass if not needed; if the real auth
wiring stays deferred, make sure there is a tracking issue linked to the TODO
and referenced from the relevant component logic before merge.
src/components/swagger-control/swagger-control.test.tsx (1)

25-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shared vi.fn() mock isn't cleared between tests.

handleFormatToggle is a single vi.fn() defined once at module scope and reused by every test. vi.restoreAllMocks() only restores vi.spyOn originals — it does not reset call history for plain vi.fn() instances. This works today because only one test clicks the switch, but call counts will silently accumulate if another test later also triggers the toggle.

♻️ Suggested fix
-const baseProps = {
-  editorValue: 'openapi: 3.0.0',
-  format: 'yaml' as const,
-  handleFormatToggle: vi.fn(),
-};
+function createBaseProps() {
+  return {
+    editorValue: 'openapi: 3.0.0',
+    format: 'yaml' as const,
+    handleFormatToggle: vi.fn(),
+  };
+}

Then call createBaseProps() fresh in each it(...), or add vi.clearAllMocks()/reassign in beforeEach.

Also applies to: 54-60

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/swagger-control/swagger-control.test.tsx` around lines 25 -
29, The shared vi.fn() for handleFormatToggle in swagger-control.test.tsx is
defined once at module scope and its call history can leak across tests. Update
the test setup around baseProps/createBaseProps so each test gets a fresh mock
instance, or clear/reset the mock in beforeEach alongside the existing
vi.restoreAllMocks() handling. Keep the fix localized to the
swagger-control.test.tsx tests and ensure any test using the format toggle
starts from a clean mock state.
src/components/swagger-editor/swagger-editor.tsx (2)

5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Self-referential barrel import creates a circular dependency.

src/components/index.ts re-exports SwaggerEditor from this very file, so importing SwaggerMonacoEditor/SwaggerViewer from @components here forms a cycle: index.ts → swagger-editor.tsx → index.ts. It's also inconsistent with MainText/SwaggerControl, which are imported via relative paths right below. This is also why the test file has to mock the entire @components module instead of importing the concrete components directly.

♻️ Suggested fix
-import { SwaggerMonacoEditor, SwaggerViewer } from '`@components`';
 import { Alert, alpha, Box, Paper, Stack } from '`@mui/material`';
 import { useTranslations } from 'next-intl';

 import { useSwagger } from '`@/utils/hooks/use-swagger`';
 import { getSwaggerEndpoints } from '`@/utils/swagger-editor/get-swagger-endpoints`';

 import { MainText } from '../main-text/main-text';
 import { SwaggerControl } from '../swagger-control/swagger-control';
+import { SwaggerMonacoEditor } from '../swagger-monaco-editor/swagger-monaco-editor';
+import { SwaggerViewer } from '../swagger-viewer/swagger-viewer';

Also applies to: 12-13

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/swagger-editor/swagger-editor.tsx` at line 5, Avoid the
circular dependency caused by importing SwaggerMonacoEditor and SwaggerViewer
from the `@components` barrel inside SwaggerEditor. Update SwaggerEditor to import
those components directly via relative paths, consistent with MainText and
SwaggerControl, so src/components/index.ts no longer loops back through this
file. Keep the existing exports in the barrel unchanged; only change the import
sources in swagger-editor.tsx and adjust the related test setup if it can now
import the concrete components instead of mocking the whole `@components` module.

56-60: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Memoize getSwaggerEndpoints(schema).

This recomputes on every render of SwaggerEditor, including re-renders triggered by editorValue/format state changes unrelated to schema. For large specs — explicitly called out as a manual-check concern for this feature — recomputing the full endpoint walk on unrelated re-renders is wasteful and also produces a new array reference each time, causing SwaggerViewer to re-render needlessly.

⚡ Suggested fix
+import { useMemo } from 'react';
 ...
-  const endpoints = getSwaggerEndpoints(schema);
+  const endpoints = useMemo(() => getSwaggerEndpoints(schema), [schema]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/swagger-editor/swagger-editor.tsx` around lines 56 - 60,
Memoize the endpoint derivation in SwaggerEditor: the current
getSwaggerEndpoints(schema) call is recomputed on every render and returns a new
array reference, which needlessly re-renders SwaggerViewer. Update SwaggerEditor
to cache the result based only on schema (for example by deriving endpoints
inside a memoized value tied to schema) so editorValue/format changes do not
retrigger the full schema walk.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/index.ts`:
- Around line 4-9: The codebase currently has two SwaggerViewer implementations
with the same API, and the one in swagger-view appears stale because the app
uses the barrel-exported SwaggerViewer from the component index. Remove the
redundant swagger-view implementation and any unnecessary exports/tests tied
only to it, or consolidate it into the main SwaggerViewer component so there is
a single source of truth. Use the SwaggerViewer symbol and the component index
barrel exports to locate and clean up the duplicate.

In `@src/components/swagger-view/swagger-view.tsx`:
- Around line 1-66: There are two competing SwaggerViewer implementations with
the same SwaggerViewerProps and translations namespace, so consolidate to a
single source of truth. Check which component is actually used by
swagger-editor.tsx and the barrel export in src/components/index.ts, then either
remove the unused duplicate or merge the rendering logic into the intended
SwaggerViewer file. Make sure only one SwaggerViewer export remains to avoid
import ambiguity and dead code.

In `@src/i18n/messages/en.json`:
- Around line 28-33: The SwaggerControl translation key is mismatched with the
component usage, so the timeout toast text is not resolving from the expected
namespace. Reconcile the `swaggerControl.timeoutError` entry in the messages
file with `SwaggerControl` in `swagger-control.tsx` by either moving the
component to use the `swaggerControl` namespace/key or removing/renaming the
unused key, and make sure the toast lookups (`requestTimeoutError`,
`schemaSaveSuccess`, `schemaSaveError`) point to the same defined message names.

In `@src/services/schema-service.ts`:
- Around line 30-32: The JSON handling in schema-service’s response parsing is
assuming `response.json()` always returns an object, so `data.schema` can throw
on null or non-object payloads. Update the async fetch flow in the
schema-service function that reads `response.json()` to validate the parsed
value before accessing `schema`, and return `null` for invalid shapes just like
the `!response.ok` path. Use the existing `isRestoredSchema` check as the guard
point and make sure it safely handles non-object JSON results.

In `@src/utils/hooks/use-swagger.ts`:
- Around line 29-43: The debounce validation effect in useSwagger currently
awaits validateSwaggerSchema inside the setTimeout callback without any error
handling, which can cause unhandled promise rejections. Update the useEffect
logic to wrap the async validation path in try/catch (or equivalent promise
handling) and surface failures through the existing setError state, keeping
behavior consistent with the restore effect and preventing silent runtime
warnings.

---

Nitpick comments:
In `@src/components/swagger-control/swagger-control.test.tsx`:
- Around line 25-29: The shared vi.fn() for handleFormatToggle in
swagger-control.test.tsx is defined once at module scope and its call history
can leak across tests. Update the test setup around baseProps/createBaseProps so
each test gets a fresh mock instance, or clear/reset the mock in beforeEach
alongside the existing vi.restoreAllMocks() handling. Keep the fix localized to
the swagger-control.test.tsx tests and ensure any test using the format toggle
starts from a clean mock state.

In `@src/components/swagger-control/swagger-control.tsx`:
- Around line 36-58: The async save flow in handleSaveSchema lacks an unmount
safeguard, so SchemaService.save can still resolve/reject after the component is
gone. Update the SwaggerControl save path to abort or clean up on unmount by
wiring getSignalWithTimeout/SAVE_TIMEOUT_MS into a useEffect cleanup, or guard
showToast and setIsSaving with an isMounted ref so handleSaveSchema does not
touch unmounted state.
- Around line 29-32: The auth check in swagger-control is currently bypassed by
hardcoding isAuthenticated to true, so replace this placeholder in
swagger-control with the real authorization flow or remove the bypass if not
needed; if the real auth wiring stays deferred, make sure there is a tracking
issue linked to the TODO and referenced from the relevant component logic before
merge.

In `@src/components/swagger-editor/swagger-editor.tsx`:
- Line 5: Avoid the circular dependency caused by importing SwaggerMonacoEditor
and SwaggerViewer from the `@components` barrel inside SwaggerEditor. Update
SwaggerEditor to import those components directly via relative paths, consistent
with MainText and SwaggerControl, so src/components/index.ts no longer loops
back through this file. Keep the existing exports in the barrel unchanged; only
change the import sources in swagger-editor.tsx and adjust the related test
setup if it can now import the concrete components instead of mocking the whole
`@components` module.
- Around line 56-60: Memoize the endpoint derivation in SwaggerEditor: the
current getSwaggerEndpoints(schema) call is recomputed on every render and
returns a new array reference, which needlessly re-renders SwaggerViewer. Update
SwaggerEditor to cache the result based only on schema (for example by deriving
endpoints inside a memoized value tied to schema) so editorValue/format changes
do not retrigger the full schema walk.

In `@src/utils/hooks/use-swagger.ts`:
- Around line 21-24: The useSwagger hook currently hardcodes isAuthenticated to
true, so the restore logic always runs regardless of the real auth state.
Replace this stub in use-swagger.ts with the actual authentication check used by
the app, keeping the logic inside useSwagger tied to the real auth source
instead of a temporary TODO. If the real auth integration is not ready, remove
the stubbed behavior and gate the restore path behind the existing auth state
mechanism or confirm the follow-up is tracked separately.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 452ec2e5-f91c-4daa-81e4-b48bd5865b3b

📥 Commits

Reviewing files that changed from the base of the PR and between 55f86f4 and 016c079.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (35)
  • package.json
  • src/app/[locale]/page.tsx
  • src/app/globals.css
  • src/components/format-toggle/format-toggle.tsx
  • src/components/header/header.tsx
  • src/components/index.ts
  • src/components/main-text/main-text.test.tsx
  • src/components/main-text/main-text.tsx
  • src/components/swagger-control/swagger-control.test.tsx
  • src/components/swagger-control/swagger-control.tsx
  • src/components/swagger-editor/swagger-editor.test.tsx
  • src/components/swagger-editor/swagger-editor.tsx
  • src/components/swagger-monaco-editor/swagger-monaco-editor.test.tsx
  • src/components/swagger-monaco-editor/swagger-monaco-editor.tsx
  • src/components/swagger-view/swagger-view.test.tsx
  • src/components/swagger-view/swagger-view.tsx
  • src/components/swagger-viewer/swagger-viewer.tsx
  • src/constants/default-schema.ts
  • src/constants/index.ts
  • src/i18n/messages/en.json
  • src/i18n/messages/ru.json
  • src/services/schema-service.ts
  • src/types/index.ts
  • src/utils/hooks/use-swagger.test.ts
  • src/utils/hooks/use-swagger.ts
  • src/utils/network/get-signal-with-timeout.ts
  • src/utils/swagger-editor/get-swagger-endpoints.ts
  • src/utils/swagger-editor/is-record.ts
  • src/utils/swagger-editor/schema-format-convert.test.ts
  • src/utils/swagger-editor/schema-format-parse.test.ts
  • src/utils/swagger-editor/schema-format.ts
  • src/utils/swagger-editor/schema-types.ts
  • src/utils/swagger-editor/swagger-validation.test.ts
  • src/utils/swagger-editor/swagger-validation.ts
  • tsconfig.json
💤 Files with no reviewable changes (1)
  • src/app/globals.css

Comment thread src/components/index.ts
Comment thread src/components/swagger-view/swagger-view.tsx Outdated
Comment thread src/i18n/messages/en.json
Comment thread src/services/schema-service.ts
Comment thread src/utils/hooks/use-swagger.ts Outdated
@AlyaEngineer
AlyaEngineer merged commit 84dee66 into develop Jul 9, 2026
3 checks passed
@AlyaEngineer
AlyaEngineer deleted the feature/3-swagger-editor branch July 12, 2026 15:31
@coderabbitai coderabbitai Bot mentioned this pull request Jul 13, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-3-editor Feature 3: Swagger Editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responsive split-view Schema validation Format conversion Format detection Schema import

3 participants