Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -333,6 +333,12 @@ private static bool TryGetValueForParameter(
return false;
}

if (leaf.Type.IsNonNullType())
{
throw new BadRequestException(
$"Required route parameter '{leaf.ParameterKey}' is missing");
}
Comment thread
tobias-tengler marked this conversation as resolved.
Outdated

parameterValue = s_nullValueNode;
return true;
}
Expand All @@ -357,6 +363,12 @@ private static bool TryGetValueForParameter(
return false;
}

if (leaf.Type.IsNonNullType())
{
throw new BadRequestException(
$"Required query parameter '{leaf.ParameterKey}' is missing");
}
Comment thread
tobias-tengler marked this conversation as resolved.
Outdated

parameterValue = s_nullValueNode;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ public async Task Http_Get_With_Query_Parameter()
response.MatchSnapshot();
}

[Fact]
public async Task Http_Get_With_Missing_Required_Query_Parameter()
{
// arrange
var storage = new TestOpenApiDefinitionStorage(
"""
query SearchProducts($text: String, $first: Int!)
@http(method: GET, route: "/products/search", queryParameters: ["text", "first"]) {
searchProductsPaginated(text: $text, first: $first)
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var response = await client.GetAsync("/products/search?text=Chair");

// assert
response.MatchSnapshot();
}

[Fact]
public async Task Http_Get_Without_Query_Parameter_That_Has_Default_Value()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Headers:
Content-Type: application/problem+json
-------------------------->
Status Code: BadRequest
-------------------------->
{"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"Bad Request","status":400,"detail":"Required query parameter 'first' is missing"}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public string SearchProducts(string? text, float? minPrice)
var formattedMinPrice = minPrice?.ToString(CultureInfo.InvariantCulture);
return $"Searched for: {text ?? "all"}, minPrice: {formattedMinPrice}";
}

public string SearchProductsPaginated(string? text, int first)
=> $"Searched for: {text ?? "all"}, first: {first}";
}

public class Mutation
Expand Down
Loading