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
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private async Task<OpenApiPaths> GeneratePathsAsync(
{
Operations = await operationsGenerator(document, group, schemaRepository)
});
};
}

return paths;
}
Expand Down Expand Up @@ -1064,9 +1064,18 @@ private OpenApiResponse GenerateResponse(
string statusCode,
ApiResponseType apiResponseType)
{
var description = ResponseDescriptionMap
.FirstOrDefault((entry) => Regex.IsMatch(statusCode, entry.Key))
.Value;
string description = null;

#if NET10_0_OR_GREATER
description = apiResponseType.Description;
#endif

if (string.IsNullOrEmpty(description))
{
description = ResponseDescriptionMap
.FirstOrDefault((entry) => Regex.IsMatch(statusCode, entry.Key))
.Value;
}

var responseContentTypes = InferResponseContentTypes(apiDescription, apiResponseType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,118 @@
}
}
}
},
"/XmlComments/Car": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product using asParameters record",
"parameters": [
{
"name": "Id",
"in": "query",
"description": "Uniquely identifies the product",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "Description",
"in": "query",
"description": "Describes the product",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
},
"/XmlComments/CarWithProduces": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product With Produces attribute",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
},
"/XmlComments/CarWithProducesDefaultResponseType": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product With ProducesDefaultResponseType attribute",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
},
"default": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
}
},
"components": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,118 @@
}
}
}
},
"/XmlComments/Car": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product using asParameters record",
"parameters": [
{
"name": "Id",
"in": "query",
"description": "Uniquely identifies the product",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "Description",
"in": "query",
"description": "Describes the product",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
},
"/XmlComments/CarWithProduces": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product With Produces attribute",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
},
"/XmlComments/CarWithProducesDefaultResponseType": {
"get": {
"tags": [
"Xml"
],
"summary": "Returns a specific product With ProducesDefaultResponseType attribute",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
},
"default": {
"description": "A Product",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
}
}
}
}
}
}
}
},
"components": {
Expand Down
35 changes: 34 additions & 1 deletion test/WebSites/WebApi/EndPoints/XmlCommentsEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace WebApi.EndPoints;
#if NET10_0_OR_GREATER
using Microsoft.AspNetCore.Mvc;
#endif

namespace WebApi.EndPoints;

/// <summary>
/// Class of Extensions to add XmlEndpoints
Expand All @@ -14,6 +18,12 @@ public static IEndpointRouteBuilder MapXmlCommentsEndpoints(this IEndpointRouteB

group.MapGet("/Car/{id}", GetProduct);

#if NET10_0_OR_GREATER
group.MapGet("Car", GetProductAsParameters);
group.MapGet("CarWithProduces",GetProductWithProduces);
group.MapGet("CarWithProducesDefaultResponseType",GetProductProducesDefaultResponseType);
#endif

return app;
}
/// <summary>
Expand All @@ -23,6 +33,29 @@ public static IEndpointRouteBuilder MapXmlCommentsEndpoints(this IEndpointRouteB
/// <response code="200">A Product Id</response>
private static Product GetProduct(int id)
=> new() { Id = id, Description = "A product" };

#if NET10_0_OR_GREATER
/// <summary>
/// Returns a specific product using asParameters record
/// </summary>
[ProducesResponseType(typeof(Product), 200, Description = "A Product")]
private static Product GetProductAsParameters([AsParameters] Product productAsParameters)
=> productAsParameters;

/// <summary>
/// Returns a specific product With Produces attribute
/// </summary>
[Produces(typeof(Product), Description = "A Product")]
private static Product GetProductWithProduces(int id)
=> new() { Id = id, Description = "A product" };

/// <summary>
/// Returns a specific product With ProducesDefaultResponseType attribute
/// </summary>
[ProducesDefaultResponseType(typeof(Product), Description = "A Product")]
private static Product GetProductProducesDefaultResponseType(int id)
=> new() { Id = id, Description = "A product" };
#endif
}

/// <summary>
Expand Down