[Swagger Linter Migration] LatestVersionOfCommonTypesMustBeUsed (origin) - #5203
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
There was a problem hiding this comment.
Pull request overview
Extends the migrated lint rule to detect legacy ARM common-type references even when v6 is selected.
Changes:
- Traverses HTTP operation payloads and parameters for outdated references.
- Adds two regression fixtures and corpus migration evidence.
- Adds a reusable LintDiff rule-development skill.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.github/skills/develop-lintdiff-rule/SKILL.md |
Documents the rule workflow. |
packages/typespec-lintdiff/src/rules/latest-version-of-common-types-must-be-used.ts |
Implements reference-level validation. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/rule.md |
Documents updated behavior and fixtures. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/migration.md |
Records corpus parity evidence. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-managed-identity/main.tsp |
Defines the managed-identity regression. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-managed-identity/expect.json |
Marks the fixture as violating. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-managed-identity/output.json |
Snapshots emitted Swagger. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-managed-identity/tsp-diagnostics.json |
Snapshots TypeSpec diagnostics. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-managed-identity/validator-diagnostics.json |
Snapshots validator diagnostics. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-location-parameter/main.tsp |
Defines the location-parameter regression. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-location-parameter/expect.json |
Marks the fixture as violating. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-location-parameter/output.json |
Snapshots emitted Swagger. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-location-parameter/tsp-diagnostics.json |
Snapshots TypeSpec diagnostics. |
packages/typespec-lintdiff/test/fixtures/LatestVersionOfCommonTypesMustBeUsed/legacy-location-parameter/validator-diagnostics.json |
Snapshots validator diagnostics. |
Suppressed comments (1)
packages/typespec-lintdiff/src/rules/latest-version-of-common-types-must-be-used.ts:92
- The unversioned path has the same undefined-selection problem: when no
@armCommonTypesVersionis present,reportIfOutdatedreturns false and this scan resolves the default v3 references while claiming the service already selected latest v6. Gate reference diagnostics oncurrentVersion === latestVersion, and decide separately whether an omitted selection needs a selection-level warning.
reportOutdatedUsages(
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 17d130f6-25f1-4e3a-89bb-ec9ceeaae4ed
|
Thanks for the detailed PR description, it's really helpful! I'm reviewing the PR, but I was thinking we should include some additional data in the PRs to review so that we can have increased certainty that the rule is providing the coverage we need. For each of the typespec lint PRs that are migrating a lintdiff rule, could we include the following:
Let me know what you think! We can discuss in the sync later |
A couple of questions about this comment, does it meant that these swaggers dont have a tsp equivalent? Likewise, how are we getting around the v5 reference as latest even though the swaggers have newer versions? Maybe we should also warn in this case that the author should update to the lastest version? If the original lintdiff rule didnt do this, then we should open tracking issues to improve the rules in cases like this. |
Discussed in today's meeting:
|
Yes just one thing to add to 1 is to include a checklist of the specific checks the original lintdiff rule performed to make sure we're covering all our bases in the migrated tsp rule. |
|
…atest-version-common-types
1a222cf
into
feature/lintdiff-migration-new
|
related with #5271 |
Original Swagger linter
LatestVersionOfCommonTypesMustBeUsedis the original ARM Swagger/Spectral rule being migrated.The original Swagger linter performs these checks:
$refvalue in ARM OpenAPI 2.0 specs (given: "$..['$ref']",resolved: false).nullreferences and references that do not match/common-types/resource-management/v\d+/\w+.json#.$refpath.LATEST_VERSION_BY_COMMON_TYPES_FILENAME.$refpath when the referenced version does not equal the mapped latest version.types.json,managedidentity.json, andprivatelinks.jsonmap tov6;customermanagedkeys.json,managedidentitywithdelegation.json,networksecurityperimeter.json, andmobo.jsonmap tov5.How the original Swagger linter works
The Swagger linter is a string-level emitted-Swagger check. Spectral visits each unresolved
$ref, the function filters to ARM common-types references under/common-types/resource-management/v*/, then it splits the reference into{version}/{fileName}.json. If the extracted version is not equal to the hard-coded latest version for that filename, the linter reports:It does not inspect TypeSpec source, service namespaces, version enum members, payload visibility, or the authoring symbol that produced the emitted reference. This also means validator map entries are part of the observed behavior. In the current published validator,
managedidentitywithdelegation.jsonandnetworksecurityperimeter.jsonare still mapped tov5, even though validv6copies exist in common-types. This PR deliberately does not copy those stale-map false positives.How the migrated TypeSpec linter works
The migrated TypeSpec rule keeps the existing effective
@armCommonTypesVersionselection check on ARM service namespaces and version enum members. When an API version already selects the latest common-types version, it additionally analyzes the TypeSpec symbols that would emit common-types$refs for that projected API.For each service/API version, the rule applies the emitter's versioning mutator and analyzes the projected service graph. It then:
resolveRequestVisibilityfor requests andVisibility.Readfor responses.createMetadataInfo().isPayloadPropertyand schema-sharing behavior used by AutoRest.Visibility.Itemonly to array elements; recordadditionalPropertieskeep their original payload context.getArmCommonTypeOpenAPIRef.The reference diagnostic distinguishes the correct latest-version selection from the specific legacy symbol:
Migration evidence
Full focused-test evidence, real-service project comparison, latest full-corpus counts, one-sided project explanations, compile failures, review findings, and remaining uncertainty are documented in migration.md.