[Swagger Linter Migration] NonApplicationJsonType - #5302
Open
Yuchao Yan (msyyc) wants to merge 4 commits into
Open
[Swagger Linter Migration] NonApplicationJsonType#5302Yuchao Yan (msyyc) wants to merge 4 commits into
Yuchao Yan (msyyc) wants to merge 4 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
All changed packages have been documented.
Show changes
|
Contributor
📦 Package size report1 package changed size, +4.94 KB (+0.0%) packed overall.
12 package(s) with no notable change
Packed = gzipped |
commit: |
Contributor
|
You can try these changes here
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Yuchao Yan (msyyc)
marked this pull request as ready for review
August 26, 2026 05:21
Yuchao Yan (msyyc)
requested review from
Mark Cowlishaw (markcowl),
Timothee Guerin (timotheeguerin) and
Jeff Fisher (xirzec)
as code owners
August 26, 2026 05:21
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cf125def-85b2-462d-8902-7ac7beb588a3
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.
Original Swagger linter
The original rule is an ARM warning that requires Swagger request and response content types to contain
application/json.The original rule performs these checks:
producesentry.consumesentry.producesentry underpaths.consumesentry underpaths.x-ms-paths.application/jsonpattern.How the Swagger linter works
The Spectral rule traverses
$[produces,consumes].*and$[paths,'x-ms-paths'].*.*[produces,consumes].*with resolved references enabled. It appliesSpectral's
patternfunction to each individual array entry and reports at that Swagger JSON pathwhen the string does not contain
application/json.The validator's pattern is a substring match rather than exact media-type equality. The migrated
rule preserves that behavior. Root-level Swagger arrays are emitter-controlled and cannot be
authored independently in current TypeSpec OpenAPI2 output, so the TypeSpec rule checks the
authorable semantic source: resolved request and response bodies. Validator diagnostics are tied to
emitted array occurrences; the promoted rule instead targets authored TypeSpec declarations.
Source TypeSpec lintdiff rule
NonApplicationJsonTypenon-application-json-typenon-application-json-typefeature/lintdiff-non-application-json-type5d6bc319579aeec5fde116dbd2018a5f2f58ac43C:\dev\worktrees\lintdiff-non-application-json-typepackages/typespec-lintdiff/src/rules/non-application-json-type.tsThe source branch was merged by PR #5286. The user-marked done source rule was treated as immutable
and was not modified during promotion.
Destination analysis
The rule belongs in
@azure-tools/typespec-azure-resource-manager:applicability: ARMandsources: ["arm"];isArmProviderNamespace;Azure Core was considered but rejected because removing ARM provider scoping would broaden the rule
to data-plane APIs and materially change its semantics. The public TypeSpec rule name is shortened
from the validator-derived
non-application-json-typeto the convention-aligneduse-application-json-content-type.How the promoted TypeSpec linter works
The promoted rule visits operations in ARM provider namespaces and resolves each operation with
getHttpOperation. It checks the resolved request body and every resolved response body, reportingonce for each content type that does not contain
application/json.Diagnostics target an authored content-type property when available, then an authored body
property. For library-instantiated bodies such as
ArmResponse<string>, the rule falls back to theauthored operation so the compiler surfaces the project lint diagnostic. This preserves the source
rule's fix for scalar ARM responses. There is no version-specific projection in the rule itself;
ordinary TypeSpec linting evaluates the program presented by the compiler. The migration evidence
separately attributes corpus results to selected Swagger versions.
The promotion adapts package imports, rule variable and public rule names, documentation metadata,
native tests, linter registration, and ARM ruleset registration. It does not change source
semantics.
Fixture-to-native test mapping
json-only-content-type/main.tspit("accepts ARM operations with only application/json content types")non-json-content-type/main.tspit("reports an explicit non-JSON response content type")application/octet-streamresponse.scalar-response-content-type/main.tspit("reports an implicit scalar response content type")non-json-request-content-type/main.tspit("reports an explicit non-JSON request content type")text/plainrequest.patch-merge-patch-content-type/main.tspit("reports application/merge-patch+json request content type")application/merge-patch+jsonPATCH request.These are direct native TypeSpec assertions; validator and OpenAPI snapshots were not copied.
Migration evidence
The checked-in
migration.mdrecords the focused fixtures, real-service comparison, latest full-corpus counts, selected-version
attribution, compile failures, diagnostic-target regression, and remaining uncertainty.
Validation
git diff --checkpnpm formatandpnpm lintValidation blocker
pnpm validate:prpassed its branch-up-to-date check in 3.7 seconds, then produced no additionalprogress for more than five minutes. It was stopped after approximately 5 minutes 10 seconds under
the bounded-validation policy. The targeted and broad validations listed above completed
successfully.
Promotion sync policy
If review discovers a semantic gap in the completed lintdiff rule, this promotion must pause until
the user explicitly reopens lintdiff repair. Source-rule changes are not part of this promotion PR.