Skip to content

fix(apigw-manager): parse v2 api responses - #300

Merged
wklken merged 1 commit into
TencentBlueKing:masterfrom
wklken:fix-apigw-manager-v2-response
Jul 6, 2026
Merged

fix(apigw-manager): parse v2 api responses#300
wklken merged 1 commit into
TencentBlueKing:masterfrom
wklken:fix-apigw-manager-v2-response

Conversation

@wklken

@wklken wklken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Release apigw-manager as 5.0.1 and add the corresponding changelog entry.
  • Add a v2 response parser for apigw-manager so successful 20x v2 responses return the data field directly, including {} and [] payloads.
  • Parse non-20x v2 API responses from the error body into ApiResultError, with a status/text fallback for non-JSON responses.
  • Switch core v2 sync/fetch/release/permission calls to the v2 parser and add regression coverage for success, error-body, non-JSON, and connection-error cases.
  • Update resource-version existence checks to use the v2 list response shape instead of the legacy count envelope.
  • Stop reading comment from v2 resource-version responses when releasing; created/latest resource-version payloads are treated as id/version-only and release comment defaults to an empty string unless passed explicitly.
  • Update stage MCP server sync output handling to consume the v2 data list directly instead of unwrapping a legacy data envelope again.
  • Add the required v2 applicant field when applying gateway permissions, while preserving explicit applicant values from definitions.
  • Remove v1-only private helpers and tests left unused after the v2 upgrade: _call, _call_with_cache, _parse_result, and itemgetter.

Verification

  • PYENV_VERSION=apigw-manager poetry check -> passed with existing metadata warnings
  • PYENV_VERSION=apigw-manager PYTHONPATH=src poetry run pytest -q --ds demo.settings tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py -q -> 29 passed
  • PYENV_VERSION=apigw-manager PYTHONPATH=src poetry run pytest -q --ds demo.settings tests/apigw_manager/apigw/management/commands/test_apply_apigw_permissions.py -q -> 1 passed
  • PYENV_VERSION=apigw-manager PYTHONPATH=src poetry run pytest -q --ds demo.settings tests/apigw_manager/apigw/management/commands/test_sync_apigw_stage_mcp_servers.py -q -> 2 passed
  • PYENV_VERSION=apigw-manager PYTHONPATH=src poetry run pytest -q --ds demo.settings tests/apigw_manager/apigw/management/commands -q -> 42 passed
  • PYENV_VERSION=apigw-manager PYTHONPATH=src poetry run pytest -q --ds demo.settings tests/apigw_manager/core -q -> 15 passed
  • PYENV_VERSION=apigw-manager make test -> 274 passed
  • PYENV_VERSION=apigw-manager poetry run mypy src/apigw_manager/apigw/management/commands/create_version_and_release_apigw.py tests/apigw_manager/apigw/management/commands/test_create_version_and_release_apigw.py -> no issues found in 2 source files
  • PYENV_VERSION=apigw-manager poetry run mypy src/apigw_manager/apigw/management/commands/apply_apigw_permissions.py tests/apigw_manager/apigw/management/commands/test_apply_apigw_permissions.py -> no issues found in 2 source files
  • PYENV_VERSION=apigw-manager poetry run mypy src/apigw_manager/apigw/management/commands/sync_apigw_stage_mcp_servers.py tests/apigw_manager/apigw/management/commands/test_sync_apigw_stage_mcp_servers.py -> no issues found in 2 source files
  • PYENV_VERSION=apigw-manager poetry run mypy src/apigw_manager/core tests/apigw_manager/core -> no issues found in 13 source files
  • git diff --check / git diff --cached --check -> passed
  • PYENV_VERSION=apigw-manager make lint -> failed: no lint target in sdks/apigw-manager/Makefile or included parent Makefile
  • PYENV_VERSION=apigw-manager poetry run mypy src -> failed on existing errors in untouched files: src/apigw_manager/drf/utils.py, src/apigw_manager/drf/management/commands/generate_resources_yaml.py, and src/apigw_manager/plugin/config.py

@wklken
wklken force-pushed the fix-apigw-manager-v2-response branch 3 times, most recently from 0b1bb80 to 4456599 Compare July 6, 2026 11:39
@wklken

wklken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

previous pr #279


Found multiple compatibility issues. The upgrade is not correct yet for several v2 input/output contracts.

Findings

  • Resource-version create/list flow is still using v1-shaped outputs.

create_version_and_release_apigw.py (line 89) expects list_resource_versions() to return {"count": ...}, but dashboard v2 returns data as a list of {version, comment} items from views.py (line 452) and serializers.py (line 687). After _parse_v2_result, SDK returns a list, so resource_versions["count"] will fail.

  • Resource-version creation returns no data, but the command needs version. 【fix in dashboard】

The SDK later uses resource_version["version"] at create_version_and_release_apigw.py (line 133). Dashboard v2 create returns OKJsonResponse(status=201) with no data at views.py (line 464), so _parse_v2_result() returns None.

  • MCP server sync is double-unwrapping data.

sync_stage_mcp_servers() now returns parsed data directly as a list, but the command still does result.get("data", []) at sync_apigw_stage_mcp_servers.py (line 36). Dashboard returns OKJsonResponse(data=output_slz.data) where output_slz.data is already the list at views.py (line 665).

  • apply_apigw_permissions does not send required v2 applicant.

The v2 open apply serializer requires applicant at serializers.py (line 106), but the command only defaults target_app_code and grant_dimension at apply_apigw_permissions.py (line 31). The docs example also omits applicant at sync_apigateway.md (line 264).

  • Stage creation response appears wrong on the dashboard side. 【fix in dashboard】

The dashboard saves stage, but serializes the pre-save instance at views.py (line 172). For a new stage, instance is None, while the SDK command expects result["id"] and result["name"] at sync_apigw_stage.py (line 35).

@wklken
wklken force-pushed the fix-apigw-manager-v2-response branch 2 times, most recently from 09a726c to fd61d1d Compare July 6, 2026 11:50
@wklken
wklken requested a review from cszmzh July 6, 2026 12:10
@wklken
wklken force-pushed the fix-apigw-manager-v2-response branch from fd61d1d to 90f277d Compare July 6, 2026 12:15
@wklken
wklken force-pushed the fix-apigw-manager-v2-response branch from 90f277d to f357164 Compare July 6, 2026 12:25
@wklken
wklken merged commit 6197621 into TencentBlueKing:master Jul 6, 2026
14 checks passed
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