6.2 KiB
6.2 KiB
Implementation Plan: Replace Swagger with Scalar, Add HttpRequest Component, Create PlaygroundPage
Overview
This plan outlines the steps to accomplish three main tasks:
- Replace the current OpenAPI UI (Swagger) with Scalar API reference UI in the backend.
- Add a new HttpRequest component (similar to Calculator) for making HTTP requests.
- Create a PlaygroundPage.vue for dynamic s8n components manipulation.
Task 1: Replace Swagger with Scalar
Current State
- Backend uses
Microsoft.AspNetCore.OpenApipackage (built-in OpenAPI). - OpenAPI endpoint is mapped via
app.MapOpenApi()in development environment. - No Swashbuckle/Swagger UI currently installed.
Requirements
- Integrate Scalar as middleware to serve a modern API reference UI.
- Maintain OpenAPI specification generation (already provided by
AddOpenApi). - Scalar UI should be accessible at a dedicated route (e.g.,
/scalar).
Implementation Steps
1.1 Add Scalar.AspNetCore NuGet Package
Add package reference to MyCompany.MyProject.BackendApi.csproj:
<PackageReference Include="Scalar.AspNetCore" Version="2.0.0" />
1.2 Configure Scalar Middleware
Modify Program.cs:
- Keep
builder.Services.AddOpenApi()for OpenAPI spec generation. - Replace
app.MapOpenApi()with Scalar middleware in development environment. - Configure Scalar to use the generated OpenAPI spec.
Example code:
if (app.Environment.IsDevelopment())
{
app.MapScalarApiReference();
// Optional: keep MapOpenApi if needed for raw spec
app.MapOpenApi();
}
1.3 Customize Scalar Settings (Optional)
Configure Scalar options (title, theme, etc.) via AddScalar.
Expected Outcome
- Visiting
/scalarin browser displays Scalar API reference UI. - OpenAPI spec remains available at
/openapi/v1.json.
Task 2: Add HttpRequest Component
Component Structure
2.1 C# Backend Component
- Location:
S8n.Components.Packages/Basics/HttpRequest.cs - Namespace:
S8n.Components.Basics - Class:
HttpRequest - Method:
Execute(orRequest) - Inputs:
method(string): HTTP method (GET, POST, PUT, DELETE, etc.)url(string): Target URLheaders(Dictionary<string, string>): Optional request headersbody(object): Optional request body (serialized as JSON)
- Outputs:
statusCode(int): HTTP status coderesponse(string): Response body as stringheaders(Dictionary<string, string>): Response headersduration(long): Request duration in milliseconds
Implementation will use HttpClient to make the request.
2.2 Vue Frontend Component
- Location:
QuasarFrontend/src/components_s8n/ComponentHttpRequest.vue - Pattern: Follow
ComponentCalculator.vuestructure. - UI Elements:
- Dropdown for HTTP method (GET, POST, PUT, DELETE, etc.)
- Text input for URL
- Dynamic key-value pair inputs for headers (add/remove)
- JSON editor for request body (textarea with JSON validation)
- Execute button with loading state
- Display response status, headers, body, and duration
2.3 Component Definition Markdown
- Location:
components/basics/httprequest.md - Format: Similar to
calculator.mdwith appropriate inputs/outputs.
Implementation Steps
2.4 Create C# Class
- Create
HttpRequest.csfile. - Implement method with error handling (timeout, invalid URL, etc.).
- Ensure JSON serialization/deserialization.
2.5 Create Vue Component
- Create
ComponentHttpRequest.vue. - Use
runtime.createExecutorwith appropriate types. - Design UI using Quasar components.
2.6 Create Markdown Definition
- Create
httprequest.mdwith YAML definition.
2.7 Register Component (if needed)
- The runtime automatically discovers classes via reflection; no explicit registration required.
Task 3: Create PlaygroundPage.vue
Requirements
- A dedicated page for interacting with s8n components.
- Dynamic component selection and rendering.
- Support for multiple components (Calculator, HttpRequest, future components).
Implementation Steps
3.1 Add Route
Modify QuasarFrontend/src/router/routes.ts:
{
path: '/playground',
component: () => import('layouts/MainLayout.vue'),
children: [{ path: '', component: () => import('pages/PlaygroundPage.vue') }],
}
3.2 Create PlaygroundPage.vue
- Location:
QuasarFrontend/src/pages/PlaygroundPage.vue - Structure:
- Left sidebar: List of available components (hardcoded for now).
- Main content: Dynamic component render area.
- Output display area (could be integrated into each component).
3.3 Component Registry
Create a component registry file (src/components_s8n/registry.ts) that exports:
- Component definitions (name, description, Vue component import).
- Dynamic import of components.
3.4 Dynamic Component Loading
Use Vue's <component :is="selectedComponent"> to render selected component.
3.5 UI Enhancements
- Use Quasar's
q-selectfor component selection. - Provide a clean layout with card containers.
Dependencies and Considerations
Backend Dependencies
Scalar.AspNetCore(new)Microsoft.AspNetCore.OpenApi(already present)System.Net.Http(for HttpRequest component)
Frontend Dependencies
- None new; use existing Quasar and Vue.
Testing
- Test Scalar UI loads correctly.
- Test HttpRequest component with mock HTTP server.
- Test PlaygroundPage navigation and component switching.
Timeline and Priority
- Priority 1: HttpRequest component (core functionality).
- Priority 2: PlaygroundPage (user interface).
- Priority 3: Scalar integration (documentation).
Success Criteria
- Scalar UI accessible at
/scalar(development only). - HttpRequest component works for basic GET/POST requests.
- PlaygroundPage renders Calculator and HttpRequest components.
- No regression in existing Calculator component.
Notes
- Scalar integration may require configuration for production; currently planned for development only.
- HttpRequest component should handle CORS limitations (backend acts as proxy).
- PlaygroundPage can be extended later with component discovery from backend API.
Next Steps
- Review this plan with stakeholders.
- Proceed to implementation in Code mode.