Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-python"
---

Honor `replaceResponseWithVoid` for basic client methods, returning `None` while preserving the service response on the wire.
5 changes: 4 additions & 1 deletion packages/http-client-python/emitter/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,10 @@ function emitHttpResponse(
if (response.type && !isAzureCoreErrorResponse(response.type)) {
type = getType(context, response.type);
}
} else if (method && !method.kind.includes("basic")) {
} else if (
method &&
(!method.kind.includes("basic") || (method.isOverride && method.response.type === undefined))
) {
if (method.response.type) {
type = getType(context, method.response.type);
}
Expand Down
50 changes: 50 additions & 0 deletions packages/http-client-python/emitter/test/emitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ it("preserves an XML response body with the legacy bytes encoding", async () =>
);
});

it("honors void response replacements without changing the wire response", async () => {
const { codeModel, diagnostics } = await emitCodeModel(`
import "@typespec/http";
import "@azure-tools/typespec-client-generator-core";
using TypeSpec.Http;
using Azure.ClientGenerator.Core;

@service namespace Test;
model Widget { name: string; }
@post op discard(): Widget;
#suppress "@azure-tools/typespec-client-generator-core/override-response-replacement" "Intentional void response."
@@override(discard, replaceResponseWithVoid(discard));
`);

expectDiagnostics(diagnostics, []);
expect(codeModel.clients).toContainEqual(
expect.objectContaining({
operationGroups: expect.arrayContaining([
expect.objectContaining({
operations: expect.arrayContaining([
expect.objectContaining({
name: "discard",
responses: [
expect.objectContaining({
statusCodes: [200],
contentTypes: ["application/json"],
}),
],
}),
]),
}),
]),
}),
);
expect(codeModel.clients).toContainEqual(
expect.objectContaining({
operationGroups: expect.arrayContaining([
expect.objectContaining({
operations: expect.arrayContaining([
expect.objectContaining({
name: "discard",
responses: [expect.not.objectContaining({ type: expect.anything() })],
}),
]),
}),
]),
}),
);
});

it.each([undefined, false, true])(
"propagates enable-sse-reconnect=%s to the Python generator",
async (enabled) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
from specs.azure.clientgenerator.core.responsereplacement.aio import ResponseReplacementClient


@pytest.fixture
async def client():
async with ResponseReplacementClient() as client:
yield client


@pytest.mark.asyncio
async def test_void_response(client: ResponseReplacementClient):
assert await client.void_response() is None
result = await client.void_response(
cls=lambda response, value, headers: (
value,
response.http_response.status_code,
response.http_response.json(),
)
)
assert result == (None, 200, {"name": "widget"})
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
from specs.azure.clientgenerator.core.responsereplacement import ResponseReplacementClient


@pytest.fixture
def client():
with ResponseReplacementClient() as client:
yield client


def test_void_response(client: ResponseReplacementClient):
assert client.void_response() is None
result = client.void_response(
cls=lambda response, value, headers: (
value,
response.http_response.status_code,
response.http_response.json(),
)
)
assert result == (None, 200, {"name": "widget"})
Loading