Skip to content

[Swagger Linter Migration] ConsistentPatchProperties (origin) - #5439

Draft
Yuchao Yan (msyyc) wants to merge 1 commit into
feature/lintdiff-migration-newfrom
feature/lintdiff-consistent-patch-properties-native
Draft

[Swagger Linter Migration] ConsistentPatchProperties (origin)#5439
Yuchao Yan (msyyc) wants to merge 1 commit into
feature/lintdiff-migration-newfrom
feature/lintdiff-consistent-patch-properties-native

Conversation

@msyyc

Copy link
Copy Markdown
Member

Summary

Follow-up source repair to #5399. Promotion exposed that preserving AutoRest-specific @scope behavior would make the ARM library depend on client-generator-core, which already references ARM in its build graph. This repair adopts the native TypeSpec contract instead of introducing a downstream dependency or a private-state adapter.

The rule no longer constructs a TCGC context or filters operations/properties with isInScope. It uses compiler Program and HTTP semantic APIs. Swagger equivalence is explicitly partial, not inferred from project overlap.

Original Swagger linter

linter code: ConsistentPatchProperties

linter doc: consistent-patch-properties.md

  • Select resolved ARM Swagger PATCH operations.
  • Locate the first body parameter schema.
  • Prefer PATCH 200, then 201, then same-path GET 200/201 response schemas.
  • Skip comparison when the request or comparison schema is absent.
  • Recursively compare named properties, including inherited schema properties, at the same nesting level.
  • Report missing/misplaced properties at the PATCH body parameter schema path.

How the Swagger linter works

The Spectral selector is $.paths.*.patch, with references resolved. consistentPatchProperties selects the request and response schemas, delegates their recursive comparison to diffSchema, and emits one body-schema diagnostic per reported property path. It does not evaluate TypeSpec decorators. AutoRest has already omitted operations and properties outside its scope before validation.

Consequently, a C#-scoped PATCH, request property, or GET fallback can produce no Swagger finding even though it exists in the native HTTP contract. Conversely, a C#-scoped response property can disappear from Swagger and cause a validator finding despite a matching native PATCH subset. Neither side is a bug for these differing contracts.

The earlier migration also recorded status-range differences, an Informatica validator miss, API-version population differences, and emitted-occurrence versus authored-target multiplicity. Those distinctions remain evidence rather than reasons to recreate emitter internals inside a lint.

How the migrated TypeSpec linter works

getAllHttpServices supplies native HTTP operations. The rule compares PATCH bodies with PATCH response bodies or a same-path GET fallback, preserving exact-code precedence over containing status-code ranges. Recursive model traversal retains inheritance, nullable object handling, JSON encoded names, compiler discriminator metadata, cycle guards, and existing authored diagnostic targets.

The only production behavior change is that client/emitter scope no longer removes native operations or properties from this comparison. The existing provider check remains lintdiff's ARM isolation in its mixed ruleset; promotion must assess official-library applicability separately. Other rules still use TCGC, so this PR does not remove package-wide dependencies.

Focused evidence

Direct native regressions compile without AutoRest, including tests that do not load client-generator-core at all. Additional tests load only TCGC's decorator library to prove that its scope metadata does not change native lint outcomes.

Comparison fixture Swagger validator Native TypeSpec lint
scoped-property No finding: PATCH property omitted Reports properties.clientOnly
scoped-get-fallback No finding: GET fallback omitted Reports wrongly nested displayName
scoped-patch-operation No finding: PATCH operation omitted Reports extra
scoped-response-property Reports description absent from emitted response Accepts matching native property

Snapshots preserve the comparison differences instead of disguising them as equivalence. coverageKind is changed to partial. No emitter implementation, harness behavior, official package, or generated corpus data is changed.

Migration evidence

See migration.md for the latest full-run counts, project overlap, API-version attribution, compile failures, source revisions, code-backed examples, and evidence limitations. The detailed corpus tables are intentionally not duplicated here.

Promotion status

Promotion remains paused. This source repair changes the previously done rule's contract; the repaired rule must be accepted as done before a new promotion attempt. No ARM-to-TCGC dependency or official-library enablement is introduced by this PR.

Remove the TCGC/AutoRest scope dependency while retaining native HTTP and model comparison. Add scope-boundary regressions and record partial Swagger equivalence with refreshed corpus evidence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

1 participant