fix(@typespec/http): @head response with body wrongly flags content type#9869
Draft
fix(@typespec/http): @head response with body wrongly flags content type#9869
@head response with body wrongly flags content type#9869Conversation
…erb-body warning Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
…est.ts, improve changeset Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix content type flagging for HEAD requests
fix(@typespec/http): Mar 2, 2026
@head response with body uses wrong content-type and missing warning
…treatContentTypeAsHeader, revert tsp-for-openapi3.ts Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot
AI
changed the title
fix(@typespec/http):
fix(@typespec/http): Mar 3, 2026
@head response with body uses wrong content-type and missing warning@head response with body wrongly flags content type
commit: |
markcowl
reviewed
Mar 4, 2026
| default: "`Content-Type` header ignored because there is no body.", | ||
| }, | ||
| }, | ||
| "head-no-body": { |
Contributor
There was a problem hiding this comment.
Suggested change
| "head-no-body": { | |
| "head-operation-no-body": { |
A little morbid otherwise.
| if (verb === "head" && resolvedBody !== undefined) { | ||
| diagnostics.add( | ||
| createDiagnostic({ | ||
| code: "head-no-body", |
Contributor
There was a problem hiding this comment.
Suggested change
| code: "head-no-body", | |
| code: "head-operation-no-body", |
|
|
||
| expectDiagnostics(diagnostics, [ | ||
| { | ||
| code: "@typespec/http/head-no-body", |
Contributor
There was a problem hiding this comment.
Suggested change
| code: "@typespec/http/head-no-body", | |
| code: "@typespec/http/head-operation-no-body", |
| // Should get warning about body in HEAD response | ||
| expectDiagnostics(diagnostics, [ | ||
| { | ||
| code: "@typespec/http/head-no-body", |
Contributor
There was a problem hiding this comment.
Suggested change
| code: "@typespec/http/head-no-body", | |
| code: "@typespec/http/head-operation-no-body", |
| expect(routes[0].verb).toBe("head"); | ||
| }); | ||
|
|
||
| it("@head with body emits head-no-body warning", async () => { |
Contributor
There was a problem hiding this comment.
Suggested change
| it("@head with body emits head-no-body warning", async () => { | |
| it("@head with body emits head-operation-no-body warning", async () => { |
|
|
||
| it("@head with body emits head-no-body warning", async () => { | ||
| const diagnostics = await diagnoseOperations(`@head op test(): string;`); | ||
| expectDiagnostics(diagnostics, [{ code: "@typespec/http/head-no-body", severity: "warning" }]); |
Contributor
There was a problem hiding this comment.
Suggested change
| expectDiagnostics(diagnostics, [{ code: "@typespec/http/head-no-body", severity: "warning" }]); | |
| expectDiagnostics(diagnostics, [{ code: "@typespec/http/head-operation-no-body", severity: "warning" }]); |
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.
Release 1.9.1 introduced
treatContentTypeAsHeader: verb === "head"which caused content-type properties in HEAD responses to always be classified as HTTP headers. When a HEAD response model had body properties alongside a content-type header, the content-type was moved to headers while the body silently used the wrong default content-type (application/json).Example — previously produced wrong OpenAPI (content-type as header + wrong
application/jsonbody):Changes
New
head-no-bodywarning — emitted when a@headresponse contains a body (HTTP spec: "head request must not return a message-body in the response"). Warning fires after void/status-code resolution sovoidreturn types don't trigger it spuriously.Content-type classification —
treatContentTypeAsHeader: verb === "head"is retained as the single mechanism for HEAD responses. Content-type properties are treated as regular HTTP headers for all HEAD responses, which correctly suppresses thecontent-type-ignoreddiagnostic and places them in the response headers.OpenAPI3 round-trip tests — updated to remove HEAD-with-body scenarios from test inputs rather than expecting the new warning, keeping the generated TypeSpec valid.
Original prompt
@headrequest with a body wrongly flags the content type #9832✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.