Skip to content

feat(http): add no-content-type-optionality-mismatch linting rule - #11416

Draft
markcowl with Copilot wants to merge 2 commits into
mainfrom
copilot/no-content-type-optionality-mismatch
Draft

feat(http): add no-content-type-optionality-mismatch linting rule#11416
markcowl with Copilot wants to merge 2 commits into
mainfrom
copilot/no-content-type-optionality-mismatch

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

When a Content-Type header is required but the @body/@bodyRoot is 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 a Content-Type header property diverges from its associated request body.

Example

// ❌ content-type required, body optional
op foo(
  @header("content-type") contentType: "application/json",
  @body body?: Bar,
): void;

// ✅ optionality matches
op foo(
  @header("content-type") contentType?: "application/json",
  @body body?: Bar,
): void;

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 optionality
  • packages/http/src/rules/no-content-type-optionality-mismatch.md — Extended rule documentation with incorrect/correct examples
  • packages/http/src/linter.ts — Register the new rule
  • packages/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

@azure-pipelines

Copy link
Copy Markdown
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 no-content-type-optionality-mismatch linting rule Jul 27, 2026
Copilot AI requested a review from markcowl July 27, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:http meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate content-type set as constant/required while @body or @bodyRoot value is optional?

2 participants