Skip to content

Openapi import advanced option tenant and prefix - #176

Merged
iFurySt merged 1 commit into
AmoyLab:mainfrom
boston008:Openapi-import-advance-option
Jul 2, 2025
Merged

iFurySt merged 1 commit into
AmoyLab:mainfrom
boston008:Openapi-import-advance-option

Conversation

@boston008

@boston008 boston008 commented Jun 30, 2025 •

Copy link
Copy Markdown
Contributor

Openapi import advanced option tenant and prefix
Fix slect file button

Summary by Sourcery

Add advanced tenant and prefix options to the OpenAPI import flow, extend client and server to handle these options during conversion, fetch tenants dynamically, and fix the file selection button behavior.

New Features:

  • Expose advanced import options for selecting a tenant and entering a prefix in the OpenAPI import UI
  • Support tenant and prefix parameters in the importOpenAPI API call
  • Introduce ConvertWithOptions in the server converter to apply tenant and prefix to the generated configuration

Bug Fixes:

  • Fix the “Select a file” button to correctly open the file dialog without interfering with the dropzone

Enhancements:

  • Lazy-load tenant list when advanced options are shown
  • Always include tenantId and prefix fields in the form data for import requests

Openapi import advanced option tenant and prefix
@sourcery-ai

sourcery-ai Bot commented Jun 30, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR extends the OpenAPI import flow with optional tenant and prefix parameters by adding an “Advanced Options” UI in the frontend, updating the import service to send those values, and enhancing the backend converter and handler to apply them during conversion.

Sequence diagram for OpenAPI import with tenant and prefix

sequenceDiagram
    actor User
    participant UI as Frontend UI
    participant API as Backend API
    participant Converter as OpenAPI Converter
    User->>UI: Select file, (optionally) set tenant and prefix
    UI->>API: POST /openapi/import (file, tenantId, prefix)
    API->>Converter: ConvertWithOptions(file, tenantId, prefix)
    Converter-->>API: MCPConfig
    API-->>UI: Success/Error response
    UI-->>User: Show notification
Loading

Class diagram for OpenAPI import backend changes

classDiagram
    class OpenAPI {
      +HandleImport(c *gin.Context)
    }
    class Converter {
      +Convert(specData []byte) *MCPConfig
      +ConvertWithOptions(specData []byte, tenant, prefix string) *MCPConfig
    }
    OpenAPI --> Converter : uses
    Converter --> MCPConfig : returns
    class MCPConfig {
      +Tenant string
      +Routers []Router
    }
    class Router {
      +Prefix string
    }
    MCPConfig --> Router : has many
Loading

File-Level Changes

Change Details Files
Add advanced tenant and prefix options to the import UI
  • Introduce state hooks for showing advanced options, loading tenants, selected tenant, and prefix
  • Fetch tenant list on-demand when advanced options are toggled
  • Render a toggle button that reveals a tenant dropdown and prefix input
  • Modify the “Select a file” button to programmatically trigger the hidden file input
web/src/pages/gateway/components/OpenAPIImport.tsx
Extend importOpenAPI service to include tenant and prefix fields
  • Add optional tenantId and prefix parameters to the importOpenAPI signature
  • Always append tenantId and prefix (even if empty) to the multipart form data
  • Import and use getTenants for frontend tenant fetching
web/src/services/api.ts
Implement backend conversion logic for tenant and prefix
  • Add Converter.ConvertWithOptions to apply tenant and prefix into MCPConfig
  • Branch in handler to choose between Convert and ConvertWithOptions based on form input
  • Read tenantId and prefix from the request form data in the import handler
pkg/openapi/converter.go
internal/apiserver/handler/openapi.go

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @boston008 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `web/src/pages/gateway/components/OpenAPIImport.tsx:76` </location>
<code_context>
           }`}
         >
-          <input {...getInputProps()} />
+          <input {...getInputProps()} style={{ display: 'none' }} />
           <LocalIcon icon="lucide:upload" className="text-4xl mb-4 text-primary" />
           {isDragActive ? (
</code_context>

<issue_to_address>
Hiding the file input with inline style may impact accessibility.

Consider alternatives like a 'visually-hidden' class or appropriate ARIA attributes to ensure the input remains accessible to screen readers.

Suggested implementation:

```typescript
          <input {...getInputProps()} className="visually-hidden" />

```

If the `visually-hidden` class does not already exist in your global CSS (e.g., `index.css` or `globals.css`), add the following CSS:

```css
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}`}
>
<input {...getInputProps()} />
<input {...getInputProps()} style={{ display: 'none' }} />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Hiding the file input with inline style may impact accessibility.

Consider alternatives like a 'visually-hidden' class or appropriate ARIA attributes to ensure the input remains accessible to screen readers.

Suggested implementation:

          <input {...getInputProps()} className="visually-hidden" />

If the visually-hidden class does not already exist in your global CSS (e.g., index.css or globals.css), add the following CSS:

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@iFurySt

iFurySt commented Jul 2, 2025

Copy link
Copy Markdown
Member

LGTM! Thanks!

@iFurySt
iFurySt merged commit 8380ecf into AmoyLab:main Jul 2, 2025
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.

2 participants