feat: enable update for existing v4 apis via import process#15814
feat: enable update for existing v4 apis via import process#15814vikrantgravitee wants to merge 3 commits intomasterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement by allowing existing V4 APIs to be updated through the import mechanism. This feature provides a streamlined way to modify API configurations, whether from a Gravitee definition or an OpenAPI specification, directly within the console. The changes span both the frontend, with a dedicated user experience for V4 API updates, and the backend, with new endpoints and core logic to process these updates securely and efficiently. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the capability to update existing V4 APIs by importing new definitions, either from a Gravitee definition or an OpenAPI (Swagger) descriptor. The changes include a new Angular dialog component (ApiImportV4Component) for the update process, new API service methods (importUpdate, importSwaggerApiUpdate) in the frontend, and corresponding new PUT endpoints (/apis/{apiId}/_import/definition, /apis/{apiId}/_import/swagger) in the backend. A new UpdateApiDefinitionUseCase handles the core logic for updating API definitions, ensuring only V4 APIs are supported. The review comment highlights a code duplication issue in the newly added backend API resource, suggesting extracting a common response-building logic into a helper method for better maintainability.
...-v2-rest/src/main/java/io/gravitee/rest/api/management/v2/rest/resource/api/ApiResource.java
Show resolved
Hide resolved
d0a3628 to
8a75805
Compare
APIM UI Tests
|
||||||||||||||||||||||||||||
| Project |
APIM UI Tests
|
| Branch Review |
APIM-12010-enable-update-for-existing-v4-apis
|
| Run status |
|
| Run duration | 07m 27s |
| Commit |
|
| Committer | vikrant |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
8
|
|
|
0
|
|
|
82
|
| View all changes introduced in this branch ↗︎ | |
782bc14 to
0b90c19
Compare
0b90c19 to
323779b
Compare
323779b to
5e5deeb
Compare
5e5deeb to
e989a01
Compare
e989a01 to
115f894
Compare
115f894 to
e42ed7d
Compare
|



Issue
https://gravitee.atlassian.net/browse/APIM-12010
Description
Prior to this change, the import mechanism in Gravitee APIM only supported creating new V4 APIs from a Gravitee definition or an OpenAPI/Swagger descriptor. Updating an existing V4 API through the import flow was explicitly blocked — the import button was disabled for V4 APIs in the console.
This PR removes that restriction and introduces full update-via-import support for V4 APIs (HTTP Proxy, Message, and Native types), both from the console UI and the management REST API.
What Was Achieved
How the System Works Now
Frontend (Console):
The "Import" button on
api-general-info.component.htmlwas previously disabled for V4 APIs (api.definitionVersion === 'V4'). That condition has been removed so V4 APIs can now trigger the import modal.ApiImportV4Component(api-import-v4/) handles the V4 update flow. It accepts anApiImportV4DialogDatainput containing theapiId, which signals that this is an update operation rather than a create.ApiV2Service.importUpdate(apiId, payload)(for Gravitee definitions) orApiV2Service.importSwaggerApiUpdate(apiId, descriptor)(for OpenAPI specs), which both issuePUTrequests to the backend.Backend (Management API v2):
Two new
PUTendpoints have been added toApiResource.java:PUT /apis/{apiId}/_import/definition— updates a V4 API from a Gravitee export definition.PUT /apis/{apiId}/_import/swagger— updates a V4 API from an OpenAPI/Swagger descriptor (the descriptor is first converted to an import definition via the existingOAIToImportApiUseCase).UpdateApiDefinitionUseCase, which:ApiDefinitionVersionNotSupportedExceptionotherwise).ApiNotFoundExceptionif not found).ImportDefinitionUpdateDomainService.ImportDefinitionUpdateDomainServiceorchestrates the full update:ApiIdsCalculatorDomainService.UpdateApiDomainService.updateV4()for HTTP Proxy/Message APIs or a native-specific update path for Native APIs.openapi-apis.yaml) has been updated to document the two new PUT endpoints.Commits
feat(console): update V4 APIs from import modalc6e1ff4ApiImportV4Componentdialog and wires it into the General Info page. Removes the V4 disable condition from the import button and adds two new service methods (importUpdate,importSwaggerApiUpdate) that call the new PUT endpoints.feat(mAPI): add PUT calls to update V4 APIs7797fcdPUTREST endpoints inApiResource.java, theUpdateApiDefinitionUseCase, theImportDefinitionUpdateDomainService, updates the OpenAPI spec, and adds full test coverage.Files Changed & Why
Frontend
api-general-info.component.html— Removedapi.definitionVersion === 'V4'from the import button's[disabled]condition so V4 APIs can use the import/update flow.api-general-info.component.ts— Wires up the newApiImportV4Componentdialog and passes theapiIdso the component knows it is in update mode.api-import-v4/api-import-v4.component.ts— New component that handles the V4 import/update dialog, detects update mode from the injectedapiId, and calls the appropriate service method.api-import-v4/api-import-v4.component.html— Template for the V4 import dialog (file picker + format selection).api-import-v4/api-import-v4.component.scss— Styles for the dialog.api-import-v4/api-import-v4.component.spec.ts— Unit tests for the component.api-import-v4/api-import-v4.harness.ts— Angular CDK test harness for the component.application-general.module.ts— RegistersApiImportV4Componentin the module.api-v2.service.ts— AddsimportUpdate(apiId, payload)andimportSwaggerApiUpdate(apiId, descriptor)methods, both issuingPUTto/apis/{apiId}/_import/definitionand/apis/{apiId}/_import/swaggerrespectively.Backend
ApiResource.java— AddsupdateApiWithDefinition()andupdateApiFromSwagger()methods withPUTmappings. Both are guarded byapi-definition[C]permission and delegate toUpdateApiDefinitionUseCase.openapi-apis.yaml— Documents the two newPUTendpoints in the OpenAPI spec so they appear correctly in API docs and client generators.UpdateApiDefinitionUseCase.java(new) — Use-case encapsulating the update logic: validates V4, fetches existing API, delegates toImportDefinitionUpdateDomainService, returns the updated API with flows.ImportDefinitionUpdateDomainService.java(new) — Domain service that orchestrates the full update: recalculates IDs, dispatches to the correct update service based on API type (PROXY/MESSAGE vs NATIVE), updates images, and upserts all sub-entities (metadata, pages, plans).ImportDefinitionPageDomainService.java— Modified to support the upsert-pages flow needed during import updates.ApiResource_UpdateApiWithDefinitionTest.java(new) — Integration tests covering the new PUT endpoint for definition-based updates.ApiResourceTest.java— Updated to include new test cases for the update paths.AbstractResourceTest.java— Base test setup updated to support the new use-case injection.ResourceContextConfiguration.java— Spring context updated to wireUpdateApiDefinitionUseCaseinto the test context.ImportDefinitionPageDomainServiceTest.java— Tests for the page upsert logic.UpdateApiDefinitionUseCaseTest.java(new) — Unit tests for the use-case (V4 validation, not-found handling, happy path).ProcessPromotionUseCaseTest.java—Updated to remain consistent with changes in
ImportDefinitionUpdateDomainService.APIM_12010_new.mov
PolicyShuffle.mov
export-import-same-no-change.mov