Skip to content

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

Merged
Yuchao Yan (msyyc) merged 6 commits into
feature/lintdiff-migration-newfrom
feature/lintdiff-consistent-patch-properties-native
Sep 11, 2026
Merged

[Swagger Linter Migration] ConsistentPatchProperties (origin)#5453
Yuchao Yan (msyyc) merged 6 commits into
feature/lintdiff-migration-newfrom
feature/lintdiff-consistent-patch-properties-native

Conversation

@msyyc

@msyyc Yuchao Yan (msyyc) commented Sep 11, 2026

Copy link
Copy Markdown
Member

Original Swagger linter

linter code: ConsistentPatchProperties

linter doc: consistent-patch-properties.md

  • Select PATCH operations and the first body parameter schema.
  • Select PATCH 200, PATCH 201, same-path GET 200, then GET 201 as the resource comparison schema.
  • Skip comparison when either selected schema is absent.
  • Merge inherited allOf properties and compare property names at the same nesting level.
  • Recursively compare named object properties, reporting request properties missing from the response schema or placed at another level.
  • Report each missing path at the PATCH body parameter's schema location.

Why this follow-up repair is needed

PR #5439 removed the downstream emitter-context dependency and has merged. Its official ARM promotion exposed two native inheritance bugs, repaired in separate commits here; the unfinished promotion remains separate.

For Update extends Base { extra?: never; }, the previous walk skipped the derived never declaration and revived Base.extra, creating a false positive. The same override in the response incorrectly accepted PATCH extra. A redeclaration changing its encoded name could likewise leave the obsolete base name visible.

The resumed promotion then found that synthetic discriminator metadata on a derived model hid an effective inherited authored object encoded to the discriminator name. Moving an inline payload?: { extra?: string } encoded as kind into a base model incorrectly lost nested comparison. This missed request violations and caused false positives for inherited response objects.

How the Swagger linter works

The Spectral rule selects $.paths.*.patch. It compares the first body parameter schema with the first available response schema in the precedence above. Its recursive helper merges allOf properties and follows matching named properties; it reports a missing parent property at the operation-body schema path rather than using TypeSpec source-property locations. Arrays and scalars do not add named element/key comparisons.

The four new comparison fixtures expose native/emitted contract differences, not validator defects. AutoRest omits a derived never property but retains the base via allOf. For inherited encoded discriminator objects, its derived synthetic string overrides the base object during the validator's schema merge. Each pair produces one native-clean/validator-violation case and one native-violation/validator-clean case. The production lint honors effective TypeSpec authoring rather than simulating emission.

How the migrated TypeSpec linter works

Compiler getProperty(model, property.name) identifies the effective authored declaration before JSON encoded-name resolution and never filtering. A shadowed base declaration is skipped even if the derived property contributes no payload property.

The helper now collects the complete effective authored shape before adding missing synthetic discriminators. Authored properties, including inherited encoded objects, take precedence. Effective source-name lookup also prevents synthesizing an extra discriminator when an inherited authored discriminator name is encoded differently. Genuine synthetic discriminators remain supported, and never overrides do not resurrect shadowed nested shapes.

The rule still uses the native HTTP service graph, PATCH/GET response-body selection (including status-code ranges after exact matches), compiler model/nullable/discriminator metadata, and recursive same-level comparison. Diagnostics retain authored property/model targets and existing multiplicity; no new deduplication or version projection is introduced. The lintdiff-only provider isolation guard is unchanged.

Fourteen added native cases cover request/response never overrides, intermediate inheritance, encoded-name redeclarations, inherited/inline discriminator objects, differently encoded discriminator source names, and genuine synthetic metadata. Existing scope differences remain documented; no emitter, TCGC, or OpenAPI dependency was added to production logic.

Migration evidence

ConsistentPatchProperties migration evidence records both inheritance repairs, their native/emitted matrix, focused comparisons, the final full-corpus rerun, exact diagnostic-multiset comparison, one-sided project explanations, compile exclusions, and remaining Informatica/version-attribution uncertainty.

Swagger equivalence remains partial. Unchanged corpus findings do not replace the supported native-shape regressions that exposed these bugs.

Validation and scope

The source package build, changed-file oxlint/formatting, 23 native rule cases, and all 22 comparison cases passed. Snapshots were regenerated and checked without updates, including after formatting. The final full corpus completed on September 11 at 13:23 +08:00; its six compile exclusions remain explicitly recorded in the linked evidence.

Generated corpus data was retained outside the repository and restored before publication. This PR changes only the rule, directly related tests/fixtures, and rule-local migration evidence. Promotion may resume from the final reviewed source; neither the unfinished official copy nor unrelated rules were changed here.

Yuchao Yan (msyyc) and others added 5 commits September 9, 2026 17:42
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>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Respect effective source-name overrides before encoded-name and never filtering; retain native-versus-emitted inheritance evidence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix and supporting regression, comparison, and migration coverage are complete with no unresolved blocking issues.

Pull request overview

Repairs inherited never property handling in the native ConsistentPatchProperties linter.

Changes:

  • Resolves effective inherited declarations before filtering and encoded-name handling.
  • Adds inheritance and encoded-name regression coverage.
  • Adds comparison fixtures and updates migration evidence.
File summaries
File Reviewed change
packages/typespec-lintdiff/test/rules/consistent-patch-properties.test.ts Adds focused regression tests.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/rule.md Documents inheritance behavior and fixtures.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-resource-override/validator-diagnostics.json Records validator diagnostics.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-resource-override/tsp-diagnostics.json Records native diagnostics.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-resource-override/output.json Stores fixture output.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-resource-override/main.tsp Defines resource override scenario.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-resource-override/expect.json Defines expected results.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-patch-override/validator-diagnostics.json Records validator diagnostics.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-patch-override/tsp-diagnostics.json Records native diagnostics.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-patch-override/output.json Stores fixture output.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-patch-override/main.tsp Defines PATCH override scenario.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/never-patch-override/expect.json Defines expected results.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/migration.md Documents migration findings and validation.
packages/typespec-lintdiff/test/fixtures/ConsistentPatchProperties/corpus-evidence.json Records corpus evidence.
packages/typespec-lintdiff/src/rules/consistent-patch-properties.ts Fixes inherited declaration shadowing.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Collect effective authored properties before synthesized discriminator metadata and cover request/response inheritance with native and comparison regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review details
  • Files reviewed: 25/25 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@msyyc
Yuchao Yan (msyyc) merged commit 7a29831 into feature/lintdiff-migration-new Sep 11, 2026
3 checks passed
@msyyc
Yuchao Yan (msyyc) deleted the feature/lintdiff-consistent-patch-properties-native branch September 11, 2026 06:21
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