Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/OpenApi/sample/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public ActionResult<CurrentWeather> HttpQueryMethod()
public ActionResult<CurrentWeather> UnsupportedHttpMethod()
=> Ok(new CurrentWeather(100));

[HttpQuery]
[Route("/query-with-body")]
public ActionResult<MvcTodo> HttpQueryWithBodyMethod([FromBody] MvcTodo todo)
=> Ok(todo);

public class HttpQuery() : HttpMethodAttribute(["QUERY"]);

public class HttpFoo() : HttpMethodAttribute(["FOO"]);
Expand Down
3 changes: 2 additions & 1 deletion src/OpenApi/src/Extensions/ApiDescriptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class ApiDescriptionExtensions
public static HttpMethod? GetHttpMethod(this ApiDescription apiDescription) =>
apiDescription.HttpMethod?.ToUpperInvariant() switch
{
// Only add methods documented in the OpenAPI spec: https://spec.openapis.org/oas/v3.1.1.html#path-item-object
// Only add methods documented in the OpenAPI spec: https://spec.openapis.org/oas/v3.2.0.html#path-item-object
"GET" => HttpMethod.Get,
"POST" => HttpMethod.Post,
"PUT" => HttpMethod.Put,
Expand All @@ -29,6 +29,7 @@ internal static class ApiDescriptionExtensions
"HEAD" => HttpMethod.Head,
"OPTIONS" => HttpMethod.Options,
"TRACE" => HttpMethod.Trace,
"QUERY" => HttpMethod.Query,
_ => null,
};

Expand Down
3 changes: 2 additions & 1 deletion src/OpenApi/src/Services/OpenApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ internal static class OpenApiConstants
HttpMethod.Options,
HttpMethod.Head,
HttpMethod.Patch,
HttpMethod.Trace
HttpMethod.Trace,
HttpMethod.Query
];
// Represents primitive types that should never be represented as
// a schema reference and always inlined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static class HttpMethodTestData
new object[] { "HEAD", HttpMethod.Head },
new object[] { "OPTIONS", HttpMethod.Options },
new object[] { "TRACE", HttpMethod.Trace },
new object[] { "QUERY", HttpMethod.Query },
new object[] { "gEt", HttpMethod.Get }, // Test case-insensitivity
};
}
Expand All @@ -88,4 +89,20 @@ public void GetHttpMethod_ReturnsHttpMethodForApiDescription(string httpMethod,
// Assert
Assert.Equal(expectedHttpMethod, result);
}

[Fact]
public void GetHttpMethod_ReturnsNullForUnsupportedMethod()
{
// Arrange - Test that unsupported HTTP methods return null
var apiDescription = new ApiDescription
{
HttpMethod = "UNSUPPORTED"
};

// Act
var result = apiDescription.GetHttpMethod();

// Assert
Assert.Null(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,88 @@
}
}
}
},
"/query": {
"x-oai-additionalOperations": {
"QUERY": {
"tags": [
"Test"
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
}
}
}
}
}
}
},
"/query-with-body": {
"x-oai-additionalOperations": {
"QUERY": {
"tags": [
"Test"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
}
}
}
}
}
}
},
"components": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,88 @@
}
}
}
},
"/query": {
"x-oai-additionalOperations": {
"QUERY": {
"tags": [
"Test"
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
}
}
}
}
}
}
},
"/query-with-body": {
"x-oai-additionalOperations": {
"QUERY": {
"tags": [
"Test"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
}
}
}
}
}
}
},
"components": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,84 @@
}
}
}
},
"/query": {
"query": {
"tags": [
"Test"
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CurrentWeather"
}
}
}
}
}
}
},
"/query-with-body": {
"query": {
"tags": [
"Test"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/MvcTodo"
}
}
}
}
}
}
}
},
"components": {
Expand Down
Loading
Loading