-
Notifications
You must be signed in to change notification settings - Fork 3k
[type:feature] Add Swagger Import Functionality to ShenYu Admin #6050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[type:feature] Add Swagger Import Functionality to ShenYu Admin #6050
Conversation
…wagger 2.0 and openapi 3.0. (cherry picked from commit 6cb0507)
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerVersion.java
Show resolved
Hide resolved
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SwaggerImportServiceTest.java
Outdated
Show resolved
Hide resolved
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SwaggerImportServiceTest.java
Outdated
Show resolved
Hide resolved
- Add SwaggerVersion enum import in SwaggerDocParser - Update test case descriptions in SwaggerImportServiceTest - Move SwaggerVersion enum from the admin module to the common module
- Refactor the property handling logic in SwaggerDocParser to improve code readability and efficiency - Optimize HTTP request handling in SwaggerImportServiceImpl to enhance code flexibility - Remove unnecessary static HttpUtils instances to reduce resource consumption - Adjust code formatting and indentation to improve code cleanliness
- Use Objects.isNull() instead of direct equality checks to enhance code readability and safety - Improve the toString method of the SwaggerImportRequest class - Remove unused imports and optimize parts of the code structure
- Extract base path method to support Swagger 2.0 and OpenAPI 3.0 - Optimize HTTP request handling, use Spring Bean to manage HttpUtils - Improve log output, add document MD5 information - Refactor code structure to enhance maintainability and testability
|
hi, good job. any front pages? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a Swagger import feature to ShenYu Admin, enabling users to import API definitions from Swagger 2.0 and OpenAPI 3.0 URLs.
- New REST endpoints to import documentation and test connectivity
- Service and parser support multi-version Swagger, URL validation, and error handling
- DTOs, enums, and configuration for seamless integration with existing DocManager
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| shenyu-common/src/main/java/org/apache/shenyu/common/enums/SwaggerVersion.java | New enum to detect Swagger/OpenAPI versions |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/SwaggerImportController.java | Adds /import and /test-connection endpoints |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SwaggerImportService.java | Declares import and connection test methods |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java | Implements URL validation, fetching, content validation, and import |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java | Enhances parsing for V2/V3 schemas, base path and signals |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/SwaggerImportRequest.java | DTO with JSR-303 validation for import parameters |
| shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SwaggerImportServiceTest.java | Unit tests for connection testing in the service layer |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/config/HttpUtilsConfiguration.java | Registers HttpUtils as a Spring bean |
Comments suppressed due to low confidence (2)
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SwaggerImportServiceTest.java:52
- Add a test case for a successful connection scenario (e.g., mock HttpUtils to return a Response with code 200) to ensure
testConnectionreturns true when expected.
assertFalse(service.testConnection("http://invalid.example.com/swagger.json"));
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/SwaggerDocParser.java:392
- [nitpick] Add JavaDoc for private helper methods like
extractBasePath,detectSwaggerVersion, andgetSchemaDefinitionsto clarify their behavior and inputs for future maintainers.
private String extractBasePath(final JsonObject docRoot, final SwaggerVersion version) {
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java
Outdated
Show resolved
Hide resolved
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java
Outdated
Show resolved
Hide resolved
- Added UrlSecurityUtils utility class for URL security validation - Integrated URL security checks into the Swagger import feature - Implemented comprehensive validation for URL format, protocol, host, IP address, and port - Effectively prevents SSRF (Server-Side Request Forgery) and other URL-based attacks
I will complete the front-end pages in the next few days. |
this pr is ok, fix ci, waiting front together, ok? |
- Update CSS file references in index.html - Update JavaScript file references in index.html
Updated the front-end page |
|
hi, add my wechat pls: aias00 |
|
@guanzhenxing hi, fix ci pls |
…ty utility class - Optimized the code structure of the SwaggerImportServiceImpl class to improve code readability - Refactored the UrlSecurityUtils class to enhance URL security check functionality - Adjusted the exception handling method to make error messages clearer - Removed unused import statements to streamline the code
…henxing/shenyu into feature/import-swagger-url * 'feature/import-swagger-url' of https://github.com/guanzhenxing/shenyu: [type:feat] mcp server plugin (apache#5999)
* master: Bump org.apache.commons:commons-lang3 from 3.12.0 to 3.18.0 (apache#6052)
Already fixed them . This is ok or not ? @Aias00 |
What this PR does / why we need it
This PR adds a new Swagger import functionality to shenyu-admin, allowing users to import API documentation from Swagger 2.0 and OpenAPI 3.0 format URLs. This feature enables developers to quickly integrate existing API documentation into ShenYu gateway without manual configuration.
Types of changes
Changes in this PR
New Files Added:
SwaggerImportController.java- REST API controller with endpoints for import and connection testingSwaggerImportService.java- Service interface for swagger import operationsSwaggerImportServiceImpl.java- Service implementation with URL validation and document parsingSwaggerImportRequest.java- DTO model for swagger import requestsSwaggerVersion.java- Enumeration for swagger version detectionSwaggerImportServiceTest.java- Unit tests for the service layerModified Files:
SwaggerDocParser.java- Enhanced to support both Swagger 2.0 and OpenAPI 3.0 formatsKey Features:
definitions) and OpenAPI 3.0 (components/schemas)API Endpoints:
POST /swagger/import- Import swagger documentation from URLPOST /swagger/test-connection- Test connection to swagger URLTesting
Manual Testing:
Unit Tests:
SwaggerImportServiceImplScreenshots/Examples
Request Example:
{ "swaggerUrl": "https://petstore.swagger.io/v2/swagger.json", "projectName": "petstore-api", "projectDescription": "Pet Store API Documentation" }Response Example:
{ "code": 200, "message": "success", "data": "Import successful, supports Swagger 2.0 and OpenAPI 3.0 formats" }Checklist
Additional Notes
This feature integrates seamlessly with the existing ShenYu admin architecture and follows the established patterns for service layer implementation. The swagger document parsing reuses the existing
DocManagerinfrastructure, ensuring consistency with the current documentation management system.The implementation is backward compatible and does not affect existing functionality. All new code follows ShenYu's coding standards and includes proper error handling and logging.