[Swagger Linter Migration] PatchBodyParametersSchema (origin) - #5209
Draft
Yuchao Yan (msyyc) wants to merge 6 commits into
Draft
[Swagger Linter Migration] PatchBodyParametersSchema (origin)#5209Yuchao Yan (msyyc) wants to merge 6 commits into
Yuchao Yan (msyyc) wants to merge 6 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7054e94e-5ed2-43ae-9bca-490a4203c0a7
Yuchao Yan (msyyc)
requested review from
Mark Cowlishaw (markcowl),
Timothee Guerin (timotheeguerin) and
Jeff Fisher (xirzec)
as code owners
August 12, 2026 04:49
Contributor
There was a problem hiding this comment.
Pull request overview
Improves PatchBodyParametersSchema parity with the Swagger validator.
Changes:
- Detects create-only PATCH properties.
- Broadens the top-level identity exemption.
- Adds fixtures, snapshots, and migration evidence.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/typespec-lintdiff/src/rules/patch-body-parameters-schema.ts |
Implements create-only detection and identity skipping. |
packages/typespec-lintdiff/test/fixtures/PatchBodyParametersSchema/rule.md |
Documents covered behavior and fixtures. |
packages/typespec-lintdiff/test/fixtures/PatchBodyParametersSchema/migration.md |
Records corpus and migration evidence. |
.../default-patch-property/main.tsp |
Defines the default-value fixture. |
.../default-patch-property/expect.json |
Marks the fixture as violating. |
.../default-patch-property/output.json |
Captures emitted Swagger. |
.../default-patch-property/tsp-diagnostics.json |
Captures TypeSpec diagnostics. |
.../default-patch-property/validator-diagnostics.json |
Captures validator diagnostics. |
.../create-only-patch-property/main.tsp |
Defines the create-only fixture. |
.../create-only-patch-property/expect.json |
Marks the fixture as violating. |
.../create-only-patch-property/output.json |
Captures emitted Swagger. |
.../create-only-patch-property/tsp-diagnostics.json |
Captures TypeSpec diagnostics. |
.../create-only-patch-property/validator-diagnostics.json |
Captures validator diagnostics. |
.../top-level-identity-compliant/main.tsp |
Defines the identity exemption fixture. |
.../top-level-identity-compliant/expect.json |
Records compliant expectations and noise. |
.../top-level-identity-compliant/output.json |
Captures emitted Swagger. |
.../top-level-identity-compliant/tsp-diagnostics.json |
Captures ambient TypeSpec diagnostics. |
.../top-level-identity-compliant/validator-diagnostics.json |
Confirms no validator diagnostic. |
Suppressed comments (1)
packages/typespec-lintdiff/src/rules/patch-body-parameters-schema.ts:80
- This exception checks the TypeSpec source name, but the Swagger rule checks the emitted JSON property name. Because AutoRest emits model keys via
resolveEncodedName(..., "application/json"), a top-levelcustomIdentityencoded asidentitywill still be reported here even though Swagger skips it, while a sourceidentityencoded to another name is incorrectly skipped. Base this check on the resolved JSON name (and add a focused encoded-name fixture) to preserve parity.
if (isTopLevelIdentityProperty(propertyPath)) {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Yuchao Yan (msyyc)
marked this pull request as draft
August 12, 2026 06:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7054e94e-5ed2-43ae-9bca-490a4203c0a7
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7054e94e-5ed2-43ae-9bca-490a4203c0a7
…atch-body-parameters-schema
…atch-body-parameters-schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR closes two known semantic gaps in the native TypeSpec migration of
PatchBodyParametersSchema: it detects create-only PATCH properties and mirrors the Swagger validator's top-levelidentityexemption. The rule remains classified as partial because corpus-level one-sided projects still require project-specific explanation; raw diagnostic counts are not expected to match because Swagger reports emitted OpenAPI occurrences while TypeSpec reports semantic source properties.Original Swagger linter
Rule:
PatchBodyParametersSchema(source, RPC-Patch-V1-10)For every property reachable from a Swagger 2.0 PATCH body schema, the original rule checks that:
requiredarray;x-ms-mutabilityis not exactly["create"].It deliberately skips a case-insensitive top-level property named
identity, including that property's descendants.How the Swagger linter works
The Spectral ruleset selects resolved body parameters under
$.paths.*.patch.parameters. Its custom function obtains the body schema's properties and required-property list, checks each property, and recursively enters nested object schemas. For nested findings, it advances the JSON path throughschema.properties.<property>; diagnostics target the containing schema rather than the individual property node.The implementation has two important comparison caveats:
properties[prop].defaultby truthiness, so emitted defaults such asfalse,0, and""are not reported even though the guideline forbids defaults.Those behaviors explain count differences and are not copied merely to force numerical parity.
How the migrated TypeSpec linter works
The TypeSpec rule visits operations in ARM provider namespaces, resolves each HTTP operation with
getHttpOperation, and processes only PATCH operations with model request bodies. It recursively walks authored and inheritedModelPropertyvalues, preserves derived overrides, and tracks visited models to avoid cycles.For each property it reports:
ModelProperty.optionalis false;defaultValueis present, including falsy defaults;getVisibilityForClassagainstgetLifecycleVisibilityEnumcontains exactlyLifecycle.Create.The rule skips top-level
identitybefore checking or recursing, matching the Swagger exception. Diagnostics target the authoredModelPropertyand include its full nested property path, giving users a stable source location instead of an emitted schema location.This PR adds focused fixtures for default-valued and create-only properties, retains the required-property fixture, and adds a compliant top-level
identityregression. For example,@visibility(Lifecycle.Create) createOnly?: stringnow matches Swagger's emittedx-ms-mutability: ["create"], while required descendants beneath top-levelidentityremain clean on both sides.Migration evidence
See
PatchBodyParametersSchemamigration evidence for focused fixture results, the pinned full-corpus run, project overlap and complete one-sided project lists, compile failures, selected-version/source-to-emission analysis, review decisions, and remaining uncertainty.The latest full run covered 462 successfully compiled projects: the validator fired in 93 projects, TypeSpec in 123, with 89 overlapping, four validator-only, and 34 TypeSpec-only projects. The identity exemption removed prior TypeSpec-only
identity.typecases including DataFactory, ElasticSan, HealthcareApis, Monitor ScheduledQueryRuleApi, and SAP Virtual Instance. The rule remains partial until the residual project-level gaps are fully reconciled.