Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -859,7 +859,7 @@ private static List<int> GetSuccessStatusCodes(InputOperation operation)

foreach (var statusCode in response.StatusCodes)
{
if (statusCode >= 200 && statusCode < 300)
if (statusCode >= 200 && statusCode < 400)
{
statusCodes.Add(statusCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,56 @@ public void ValidateProperties()
Assert.IsFalse(propertyHash.ContainsKey("PipelineMessageClassifier204"));
}

[Test]
Comment thread
JoshLove-msft marked this conversation as resolved.
public void Validate3xxRedirectStatusCode()
{
// Test that 3xx status codes (like 302 redirect) are handled correctly
var inputServiceMethod = InputFactory.BasicServiceMethod(
"TestRedirect",
InputFactory.Operation(
"Redirect302",
responses:
[
InputFactory.OperationResponse(
statusCodes: [302],
headers:
[
new InputOperationResponseHeader(
"location",
"location",
"Location header for redirect",
null,
InputPrimitiveType.String)
])
]));

var inputClient = InputFactory.Client("TestClient", methods: [inputServiceMethod]);
var clientProvider = new ClientProvider(inputClient);
var restClient = clientProvider.RestClient;

Assert.IsNotNull(restClient);

// Validate that the classifier for 302 status code exists
Dictionary<string, PropertyProvider> propertyHash = restClient.Properties.ToDictionary(p => p.Name);
Assert.IsTrue(propertyHash.ContainsKey("PipelineMessageClassifier302"),
"PipelineMessageClassifier302 should be present for 302 redirect");

var pipelineMessageClassifier302 = propertyHash["PipelineMessageClassifier302"];
Assert.AreEqual("PipelineMessageClassifier", pipelineMessageClassifier302.Type.Name);
Assert.AreEqual("PipelineMessageClassifier302", pipelineMessageClassifier302.Name);
Assert.AreEqual(MethodSignatureModifiers.Private | MethodSignatureModifiers.Static, pipelineMessageClassifier302.Modifiers);

// Validate that fields are created correctly
Dictionary<string, FieldProvider> fieldHash = restClient.Fields.ToDictionary(f => f.Name);
Assert.IsTrue(fieldHash.ContainsKey("_pipelineMessageClassifier302"),
"_pipelineMessageClassifier302 field should be present for 302 redirect");

var pipelineMessageClassifier302Field = fieldHash["_pipelineMessageClassifier302"];
Assert.AreEqual("PipelineMessageClassifier", pipelineMessageClassifier302Field.Type.Name);
Assert.AreEqual("_pipelineMessageClassifier302", pipelineMessageClassifier302Field.Name);
Assert.AreEqual(FieldModifiers.Private | FieldModifiers.Static, pipelineMessageClassifier302Field.Modifiers);
}

[TestCaseSource(nameof(GetMethodParametersTestCases))]
public void TestGetMethodParameters(InputServiceMethod inputServiceMethod)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
"output-folder": ".",
"namespace": "Response.Redirect",
"library-name": "Response.Redirect"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
directory: ../../../../../../../http-specs/specs/response/redirect
32 changes: 32 additions & 0 deletions packages/http-specs/specs/response/redirect/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@typespec/http";
Comment thread
JoshLove-msft marked this conversation as resolved.
Outdated
import "@typespec/spector";

using Http;
using Spector;

/**
* Test for HTTP redirect status codes.
*/
@scenarioService("/response/redirect")
namespace Response.Redirect;

@scenario
@scenarioDoc("""
Test case for 302 redirect response.

Verify that the client can receive and process a 302 redirect response with a Location header.
This is commonly used in OAuth-style authorization flows where the service provides a redirect
URI that the application can use to navigate users to the mobile operator's network for authentication.

Expected status code 302 and response headers:
- Location: /redirected
""")
@route("/302")
@get
op redirect302(): {
@statusCode
_: 302;

@header
location: url;
};
18 changes: 18 additions & 0 deletions packages/http-specs/specs/response/redirect/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { passOnSuccess, ScenarioMockApi, MockApiDefinition } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

const validRedirect302: MockApiDefinition = {
uri: "/response/redirect/302",
method: "get",
request: {},
response: {
status: 302,
headers: {
location: "/redirected",
},
},
kind: "MockApiDefinition",
};

Scenarios.Response_Redirect_redirect302 = passOnSuccess(validRedirect302);
Loading