Skip to content

Commit fd64fd7

Browse files
committed
rename and document content abstractions
1 parent a7ddff6 commit fd64fd7

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/OpenAPI.WebApiGenerator/CodeGeneration/ResponseBodyContentGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ internal sealed class {{ClassName}} : {{responseClassName}}
6666
{{contentTypeFieldName}} = {{(_isContentTypeRange ? "contentType" : $"\"{_contentType.MediaType}\"")}};
6767
}
6868
69-
/// <inheritdoc/>
70-
public static ContentMediaType<{{responseClassName}}> ContentMediaType { get; } = new(MediaTypeHeaderValue.Parse("{{_contentType}}"));
69+
internal static ContentMediaType<{{responseClassName}}> ContentMediaType { get; } = new(MediaTypeHeaderValue.Parse("{{_contentType}}"));
7170
protected override IJsonValue Content { get; }
7271
protected override string ContentSchemaLocation { get; } = "{{SchemaLocation}}";
7372
}

src/OpenAPI.WebApiGenerator/CodeGeneration/ResponseContentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public string GenerateResponseContentClass()
6262
return
6363
$$$"""
6464
{{{_response.Description.AsComment("summary", "para")}}}
65-
internal {{{(_contentGenerators.Any() ? "abstract" : "sealed")}}} class {{{_responseClassName}}} : Response{{{(_contentGenerators.Any() ? $", IResponse<{_responseClassName}>" : "")}}}
65+
internal {{{(_contentGenerators.Any() ? "abstract" : "sealed")}}} class {{{_responseClassName}}} : Response{{{(_contentGenerators.Any() ? $", IContent<{_responseClassName}>" : "")}}}
6666
{
6767
private string? {{{contentTypeFieldName}}} = null;{{{
6868
_contentGenerators.AggregateToString(generator =>

src/OpenAPI.WebApiGenerator/CodeGeneration/ResponseGenerator.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,28 @@ protected void EnsureExpectedContentType(MediaTypeHeaderValue contentType, Media
6969
}}
7070
}
7171
72-
internal interface IResponse<T> where T : class
72+
/// <summary>
73+
/// Represents a response with content
74+
/// </summary>
75+
/// <typeparam name="T">Response</typeparam>
76+
internal interface IContent<T> where T : Response
7377
{
7478
/// <summary>
75-
/// Contents for this response
79+
/// Contents for the response
7680
/// </summary>
7781
internal static abstract ContentMediaType<T>[] ContentMediaTypes { get; }
7882
}
7983
80-
internal interface IContent<T> where T : class, IResponse<T>
81-
{
82-
internal static abstract ContentMediaType<T> ContentMediaType { get; }
83-
}
84-
84+
/// <summary>
85+
/// Typed content media type
86+
/// </summary>
87+
/// <typeparam name="T">Response</typeparam>
8588
internal readonly record struct ContentMediaType<T>(MediaTypeHeaderValue Value)
86-
where T : class
89+
where T : Response
8790
{
91+
/// <summary>
92+
/// Implicitly convert back to MediaTypeHeaderValue
93+
/// </summary>
8894
public static implicit operator MediaTypeHeaderValue(ContentMediaType<T> mediaType) => mediaType.Value;
8995
}
9096
@@ -97,7 +103,7 @@ internal partial class Request
97103
/// <typeparam name="T">The response to match against</typeparam>
98104
/// <returns>True if a matched media type was found</returns>
99105
internal bool TryMatchAcceptMediaType<T>(
100-
[NotNullWhen(true)] out ContentMediaType<T>? matchedContentMediaType) where T : class, IResponse<T>
106+
[NotNullWhen(true)] out ContentMediaType<T>? matchedContentMediaType) where T : Response, IContent<T>
101107
{
102108
var mediaTypes = T.ContentMediaTypes;
103109
var acceptHeaders = HttpContext.Request.GetTypedHeaders().Accept;

0 commit comments

Comments
 (0)