Skip to content

Improve description of responses with the same status code - #11891

Open
Jeremy Wharton (jewharton) wants to merge 1 commit into
microsoft:mainfrom
jewharton:jw/resp-group-desc
Open

Improve description of responses with the same status code#11891
Jeremy Wharton (jewharton) wants to merge 1 commit into
microsoft:mainfrom
jewharton:jw/resp-group-desc

Conversation

@jewharton

Copy link
Copy Markdown

An operation may have multiple responses with the same status code. Previously, only one response per status code was considered when determining the description for that status code. The resolution rules were as follows:

  1. If the response was a member of a union, use the outermost union documentation comment if it exists.

  2. If the response was an envelope, use the envelope's @doc if it exists.

  3. If the response was an @error model, use the operation's @errorsDoc if it exists; otherwise, use the operation's @returnsDoc if it exists.

  4. Otherwise, fall back to the default RFC 2616 description for the status code.

Now, all responses sharing a status code are considered:

  1. Compute the description each response would produce if it were the only response with that status code (its union comment, falling back to its envelope comment).

  2. If every response sharing the status code produces the same description, then use that description.

  3. Otherwise, if all such responses are @error models, use the operation's @errorsDoc; if none are, use the operation's @returnsDoc.

  4. Otherwise, fall back to the default RFC 2616 description for the status code.

@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.

@jewharton

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is a confirmed bug in status-code range parsing (ResponseIndex.entries()), and the union construction for grouped response types drops per-member documentation that the TypeKit can preserve.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates @typespec/http response processing so that when an operation has multiple responses sharing the same status code, the response description is derived by considering all variants rather than only the first one.

Changes:

  • Refactors response collection to group processed response variants by status code and build a combined HttpOperationResponse per group.
  • Updates description resolution to compare per-variant “single-response” descriptions (union/envelope docs) and otherwise fall back to @returnsDoc/@errorsDoc or RFC defaults.
  • Adds tests covering the new multi-response-per-status-code description rules.
File summaries
File Description
packages/http/src/responses.ts Groups responses by status code and computes a shared description across all responses with that status code.
packages/http/test/response-descriptions.test.ts Adds tests validating description selection when multiple responses share the same status code.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/http/src/responses.ts Outdated
Comment thread packages/http/src/responses.ts
Comment thread packages/http/test/response-descriptions.test.ts
Copilot AI review requested due to automatic review settings September 9, 2026 06:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

ResponseIndex.entries() currently mis-parses status-code ranges (producing NaN start/end), which would break range-based responses at runtime.

Review details

Suppressed comments (1)

packages/http/src/responses.ts:166

  • ResponseIndex.entries() parses status-code ranges incorrectly: keys are stored as ${start},${end} (see #indexKey), but entries() splits with ":", which yields NaN start/end and breaks range status codes.
      } else if (indexKey.includes(",")) {
        const [, start, end] = indexKey.split(":");
        parsedStatusCodes = { start: Number(start), end: Number(end) };
      } else {
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two newly added tests assert incorrect default/derived descriptions for status code 200, and the new shared-description logic incorrectly ignores empty-string docs due to a truthiness check.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

packages/http/test/response-descriptions.test.ts:136

  • This test says it falls back to the default description, but the expected string is the 201 "created" message; for status code 200 the default in this suite is "The request has succeeded." (see the first test).
  strictEqual(
    op.responses[0].description,
    "The request has succeeded and a new resource has been created as a result.",
  );
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread packages/http/src/responses.ts
Comment thread packages/http/test/response-descriptions.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

It introduces a user-visible behavior change in @typespec/http without an accompanying .chronus changelog entry.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread packages/http/src/responses.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The changeset entry needs to meet the repo’s feature-entry guidance, and the PR should clarify (or adjust) the additional behavioral change to HttpOperationResponse.type when multiple responses share a status code.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment thread packages/http/src/responses.ts
Comment thread packages/http/test/response-descriptions.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

It introduces a concrete behavioral regression risk in downstream consumers (notably the experimental typekit’s error detection) and also changes HttpOperationResponseContent object shape by always including body: undefined.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread packages/http/src/responses.ts Outdated
Comment thread packages/http/src/responses.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is an unused local (tk) in packages/http/src/responses.ts that will fail lint/noUnusedLocals and should be removed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread packages/http/src/responses.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The .chronus entry appears misclassified as feature instead of fix, which would lead to an incorrect version bump per the repository’s Chronus changeKind definitions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the stated resolution rules, includes comprehensive new tests for the added branches, and ships an appropriate .chronus fix entry.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@timotheeguerin Timothee Guerin (timotheeguerin) added the int:azure-specs Run integration tests against azure-rest-api-specs label Sep 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http@11891

commit: 4645111

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http
Show changes

@typespec/http - fix ✏️

Improve how response descriptions are chosen when multiple responses share a status code. When an operation has multiple responses with the same HTTP status code, all responses sharing that code are considered when computing the description associated with that code instead of just one.,> ,> tsp,> @doc("A cat."),> model Cat { @statusCode _: 200, meow: boolean },> ,> @doc("A dog."),> model Dog { @statusCode _: 200, bark: boolean },> ,> // The response description defaults to "The request has succeeded.",> // because the doc comments for the variants conflict.,> op read(): Cat | Dog;,>

An operation may have multiple responses with the same status code.
Previously, only one response per status code was considered when
determining the description for that status code. The resolution
rules were as follows:

1. If the response was a member of a union, use the outermost union
   documentation comment if it exists.

2. If the response was an envelope, use the envelope's `@doc` if it
   exists.

3. If the response was an `@error` model, use the operation's
   `@errorsDoc` if it exists; otherwise, use the operation's
   `@returnsDoc` if it exists.

4. Otherwise, fall back to the default RFC 2616 description for the
   status code.

Now, all responses sharing a status code are considered:

1. Compute the description each response would produce if it were the
   only response with that status code (its union comment, falling back
   to its envelope comment).

2. If every response sharing the status code produces the same
   description, then use that description.

3. Otherwise, if all such responses are `@error` models, use the
   operation's `@errorsDoc`; if none are, use the operation's
   `@returnsDoc`.

4. Otherwise, fall back to the default RFC 2616 description for the
   status code.
Copilot AI review requested due to automatic review settings September 9, 2026 22:47
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:openapi3 Issues for @typespec/openapi3 emitter label Sep 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The .chronus entry should attribute this user-visible OpenAPI output change to @typespec/openapi3 as well (lockstep stable group), not only @typespec/http.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +3 to +5
packages:
- "@typespec/http"
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:openapi3 Issues for @typespec/openapi3 emitter int:azure-specs Run integration tests against azure-rest-api-specs lib:http

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants