Draft
feat(http): add no-content-type-optionality-mismatch linting rule#11416
no-content-type-optionality-mismatch linting rule#11416Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Adds a linting rule that validates the optionality of a Content-Type header matches the optionality of the associated request body. Closes #11413 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add linting rule for content-type optionality mismatch
feat(http): add Jul 27, 2026
no-content-type-optionality-mismatch linting rule
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.
When a
Content-Typeheader is required but the@body/@bodyRootis optional (or vice versa), the mismatch can cause runtime issues—there's no content to describe when the body is omitted.Adds linting rule
@typespec/http/no-content-type-optionality-mismatch(warning) that checks operation parameters and reports when the optionality of aContent-Typeheader property diverges from its associated request body.Example
Changes
packages/http/src/rules/no-content-type-optionality-mismatch.ts— Rule implementation; resolves HTTP properties from operation parameters, finds content-type and body/bodyRoot properties, compares optionalitypackages/http/src/rules/no-content-type-optionality-mismatch.md— Extended rule documentation with incorrect/correct examplespackages/http/src/linter.ts— Register the new rulepackages/http/test/rules/no-content-type-optionality-mismatch.test.ts— 14 tests (5 diagnostic-emitting, 9 valid cases)packages/http/README.md,website/.../linter.md— Regenerated docs