APIOps Toolkit artifacts only partly compatible

未關閉
#304 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript

研究方向

Start with RESOURCE_TYPE_METADATA in src/models/resource-types.ts and trace artifact discovery for apiops publish and apiops extract. Compare those paths with the Toolkit layouts and docs/guides/migration-from-v1.md, including named values, policy fragments, version sets, and policy.xml handling. Done means Toolkit artifacts are handled deliberately, skipped paths are reported, and the migration guidance matches the supported behavior.

由索引模型根據 Issue 內容生成。

描述

stale type:bug
Command that triggered the bug

apiops publish (also affects apiops extract)

Expected behavior

The migration guide (docs/guides/migration-from-v1.md) says existing APIOps Toolkit artifacts "should work as-is with apiops-cli" and that "the artifact format is backward compatible". We therefore expected apiops publish, run against a repository extracted by the Toolkit, to publish every resource in it, including named values, policy fragments and version sets. If some artifacts couldn't be read, we'd at least expect a warning or error, so that a partial publish can't go unnoticed.

Any of these would help:

  1. Accept the Toolkit names on publish: "named values", "policy fragments", "version sets", apiVersionSetInformation.json, and a policy fragment's policy.xml when properties.value is absent.
  2. Warn about artifact paths that aren't recognised, especially unknown top-level folders.
  3. Update the migration guide to list these differences, and provide an in-place conversion step for existing repositories (for example an apiops migrate command; related to #133 and #146), so teams aren't pushed towards re-extracting.
  4. Store policy fragment bodies as policy.xml, as the CLI already does for API, product and operation policies, and fall back to properties.value when there is no policy.xml. This keeps fragment changes reviewable and removes one of the incompatibilities with the Toolkit.
Actual behavior

APIs, backends, products and their policies are published, but named values, policy fragments and version sets in the Toolkit layout are silently skipped, with no warning or error. The dry run that the migration guide recommends also passes, because the skipped resources simply don't appear in the plan. You'd only notice by counting them.

The differences below still exist in the latest Toolkit release (v7.0.4) and in apiops-cli main.

Differences between the Toolkit and apiops-cli layouts

  1. Named values folder

    • Toolkit v7.0.4: "named values//namedValueInformation.json"
    • apiops-cli: "namedValues//namedValueInformation.json"
  2. Policy fragments folder

    • Toolkit v7.0.4: "policy fragments//..."
    • apiops-cli: "policyFragments//..."
  3. Policy fragment body

    • Toolkit v7.0.4: a separate policy.xml next to policyFragmentInformation.json. v7 deliberately removes properties.value and properties.format from the JSON (FormatInformationFileDto in src/common/PolicyFragment.cs).
    • apiops-cli: read only from properties.value (format: rawxml) in policyFragmentInformation.json. A separate policy.xml in the fragment folder is ignored.
  4. Version sets folder

    • Toolkit v7.0.4: "version sets//..."
    • apiops-cli: "versionSets//..."
  5. Version set information file (v5 only)

    • Toolkit v5.0.1: apiVersionSetInformation.json
    • Toolkit v7.0.4 and apiops-cli: versionSetInformation.json

Sources:

  • Azure/apiops v7.0.4: src/common/NamedValue.cs, src/common/PolicyFragment.cs, src/common/VersionSet.cs
  • Azure/apiops v5.0.1: tools/code/common/NamedValue.cs, tools/code/common/PolicyFragment.cs, tools/code/common/ApiVersionSet.cs
  • apiops-cli main: RESOURCE_TYPE_METADATA in src/models/resource-types.ts

What we observed

On our repository, mostly extracted with Toolkit v7.0.4 (809 artifact files), running apiops-cli 1.0.4 with no changes:

  • 217 files under "named values/", "policy fragments/" and "version sets/" were not recognised, with no warning or error.
  • The CLI's artifact discovery found 507 resources, compared with 701 after converting the layout.
  • After converting, all 23 policy fragment bodies were read back exactly as they appear in the Toolkit output.

Extract has the same problem in reverse

apiops extract always writes namedValues/, policyFragments/ and versionSets/. Run against an existing Toolkit repository, it creates these alongside the existing "named values/", "policy fragments/" and "version sets/" folders instead of replacing them. The old folders stay behind and still look authoritative, but publish ignores them. So a team can't start using apiops extract until the repository has been migrated, which means publish and extract have to switch over at the same time.

Policy fragment bodies become hard to review

The Toolkit stores each fragment's XML in its own policy.xml. apiops-cli stores it as a string in policyFragmentInformation.json (properties.value). A JSON string can't contain real line breaks, so the whole policy ends up on one escaped line. Every fragment change then shows up as that one line changing, which is hard to review and conflicts on any concurrent edit. This is also inconsistent with the rest of the CLI layout, where API, product and operation policies are stored as policy.xml files.

Why not just re-extract?

The obvious workaround is to re-extract from an APIM instance with apiops extract, so the artifacts come out in the CLI layout. That doesn't really work for us:

  • Our git repository is the source of truth, not any single APIM instance. Artifacts are reviewed and merged in git, then published out to environments. Re-extracting would mean treating one instance as authoritative and hoping it exactly matches the repository.
  • There are always several feature branches with work in progress on the artifacts. Git's rename detection deals with most of a folder rename. However, new files added under the old folder names on those branches are reported as conflicts, and any fragment policy edited on a branch conflicts with policy.xml being folded into the JSON file. Each of those has to be fixed by hand, branch by branch.
  • A re-extract would also change every API's specification from specification.json to specification.yaml (see #257). Every spec would then show up as a new file, which hides the real changes in review.

What we need is a migration path where the CLI can publish our existing repository as-is while we move over. We can then switch the layout once, deliberately, when no branches are in flight.

Workaround

For now, before each publish we convert a copy of the Toolkit artifacts into the CLI layout. We rename the three folders, rename the v5 version set file, and inline each fragment's policy.xml into properties.value with format rawxml. The source is never modified, so the repository and the open branches stay unchanged. Happy to share the script.

apiops CLI version

1.0.4 (layout also checked against main)

Environment details
  • Node.js 24.x
  • Windows, self-hosted Azure DevOps agent; the pipeline steps run in Windows PowerShell 5.1
  • Artifacts extracted with APIOps Toolkit (Azure/apiops) v5.0.1; layout also checked against v7.0.4
CI/CD environment

None

Is this bug blocking you?

Yes - too hard to switch to apiops-cli without backwards compatibility or a clear migration path

主要語言
TypeScript
星號
44
分支
14
PR 合併指標
30 天內沒有已合併 PR

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Azure/apiops-cli 的其他 Issue

查看 Azure/apiops-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。