wso2 / api-manager

All issues, tasks, improvements and new features of WSO2 API Manager
Apache License 2.0
34 stars 8 forks source link

Swagger update causing problems while deploying a revision #2940

Closed niranRameshPeiris closed 1 month ago

niranRameshPeiris commented 3 months ago

Description

Hi team,

We have observed the below error while deploying a new revision after updating the swagger definition.

TID: [-1234] [api/am/publisher] [2024-06-03 08:14:37,182] ERROR {org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO} - Failed to add API Revision entry of API UUID c6cbf692-9f2a-4299-9a5b-f46988bd00d0 java.sql.BatchUpdateException: Batch entry 0 INSERT INTO AM_API_OPERATION_POLICY_MAPPING  (URL_MAPPING_ID, POLICY_UUID, DIRECTION, PARAMETERS, POLICY_ORDER)  VALUES (0,'12345-5555-5555-55555-dg5t5654','request','{}',1) was aborted: ERROR: insert or update on table "am_api_operation_policy_mapping" violates foreign key constraint "am_api_operation_policy_mapping_url_mapping_id_fkey"
  Detail: Key (url_mapping_id)=(0) is not present in table "am_api_url_mapping".  Call getNextException to see other errors in the batch.

If we check the "API Definition" we will be able to see that after importing the updated swagger, even though we removed the "security" section it will be automatically appended to each resource by WSO2.

image

However, WSO2 didn't add the "x-auth-type" parameter. This is the reason for the behavior we are observing.

Thanks & Regards, Niran Peiris

Steps to Reproduce

  1. Set up a Postgres database. (We haven't tried the behavior in any other database type. The behavior should be the same)
  2. Deploy and Publish the "pizzashack" API.
  3. Add a simple mediation policy to all the resources.
  4. Save and deploy a new revision.
  5. Download the swagger from the "API Definition" section.
  6. Remove the below section from all the resources in the downloaded swagger.
    security:
        - default: []
      x-throttling-tier: Unlimited
      x-wso2-application-security:
        security-types:
          - oauth2
        optional: false
  7. Save the changes.
  8. Import the updated swagger.
  9. Deply a new revision.

Affected Component

APIM

Version

4.2.0

Environment Details (with versions)

No response

Relevant Log Output

No response

Related Issues

No response

Suggested Labels

No response

Tharanidk commented 2 months ago

Hi @shnrndk ,

Please share the public fix and close this issue.

Regards, Tharani.