Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Description to ProducesResponseType (and others) for better OpenAPI document creation#58193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
captainsafia merged 25 commits intodotnet:mainfromsander1095:main
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
1f433b6
Started adding Description to several attributes
sander1095Mar 17, 2024
364e278
Merge branch 'dotnet:main' into main
sander1095Apr 30, 2024
d71759c
Add new properties to unshipped apis
sander1095Apr 30, 2024
019bd17
Some more progress of adding Description in some places
sander1095Apr 30, 2024
e7885ab
Merge branch 'dotnet:main' into main
sander1095May 10, 2024
4b75efc
Merge branch 'dotnet:main' into main
sander1095Aug 16, 2024
6da811a
Small improvements based on API review comments
sander1095Aug 16, 2024
951676d
Added missing modifier to property
sander1095Aug 16, 2024
3bdbe26
Make changes in unshipped.txt so the http project builds
sander1095Aug 16, 2024
442d101
Add Description to OpenApiRouteHandlerBuilderExtensions and extra con…
sander1095Aug 16, 2024
f7416da
Changed code to follow overload rules and fix compile issues
sander1095Aug 16, 2024
443babd
Fix minor typo
sander1095Sep 16, 2024
7700ccc
Remove code from OpenApiRouteHandlerBUilderExtensions based on Safiaś…
sander1095Sep 16, 2024
9614111
Fix incorrect XML Comment
sander1095Sep 16, 2024
365c7d6
Fixed some more Public API issues
sander1095Sep 16, 2024
6964a4d
Merge branch 'dotnet:main' into main
sander1095Sep 16, 2024
a384d69
Add unit test
sander1095Sep 16, 2024
c071c35
Add some more unit tests
sander1095Sep 16, 2024
aa366b7
Remove unnecessary set from interface
sander1095Sep 17, 2024
2d1314f
Merge branch 'dotnet:main' into main
sander1095Sep 17, 2024
4e9fcd8
Merge branch 'dotnet:main' into main
sander1095Oct 1, 2024
24128f6
Remove unnecessary change in public api shipped file
sander1095Oct 1, 2024
bb3e442
Also update unshipped file so the build succeeds!
sander1095Oct 1, 2024
d5dae48
Apply the new Description in response models
sander1095Oct 9, 2024
6d388db
Merge branch 'dotnet:main' into main
sander1095Oct 25, 2024
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
PrevPrevious commit
NextNext commit
Remove code from OpenApiRouteHandlerBUilderExtensions based on Safiaś…
… commentAlso removed new constructors based on Safiaś comment
  • Loading branch information
@sander1095
sander1095 committedSep 16, 2024
commit7700ccc5d849cd20c0cbdfe31ba6d0d4b5269a9e
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ public interface IProducesResponseTypeMetadata
/// <summary>
/// Gets the description of the response.
/// </summary>
string? Description { get; }
string? Description { get;set;}

/// <summary>
/// Gets the content types supported by the metadata.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,12 +21,10 @@ public sealed class ProducesResponseTypeMetadata : IProducesResponseTypeMetadata
/// <param name="statusCode">The HTTP response status code.</param>
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
/// <param name="contentTypes">Content types supported by the response.</param>
/// <param name="description">The description of the response.</param>
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null, string? description = null)
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null)
{
StatusCode = statusCode;
Type = type;
Description = description;

if (contentTypes is null || contentTypes.Length == 0)
{
Expand All@@ -52,22 +50,12 @@ static void ValidateContentType(string type)
}
}

// 9.0 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
/// <summary>
/// Initializes an instance of <see cref="ProducesResponseTypeMetadata"/>.
/// </summary>
/// <param name="statusCode">The HTTP response status code.</param>
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
/// <param name="contentTypes">Content types supported by the response.</param>
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null) : this(statusCode, type, contentTypes, description: null) { }

// Only for internal use where validation is unnecessary.
private ProducesResponseTypeMetadata(int statusCode, Type? type, IEnumerable<string> contentTypes, string? description = null)
private ProducesResponseTypeMetadata(int statusCode, Type? type, IEnumerable<string> contentTypes)
{
Type = type;
StatusCode = statusCode;
ContentTypes = contentTypes;
Description = description;
}

/// <summary>
Expand All@@ -83,7 +71,7 @@ private ProducesResponseTypeMetadata(int statusCode, Type? type, IEnumerable<str
/// <summary>
/// Gets or sets the description of the response.
/// </summary>
public string? Description { get;privateset; }
public string? Description { get; set; }

/// <summary>
/// Gets or sets the content types associated with the response.
Expand All@@ -96,5 +84,5 @@ public override string ToString()
return DebuggerHelpers.GetDebugText(nameof(StatusCode), StatusCode, nameof(ContentTypes), ContentTypes, nameof(Type), Type, includeNullValues: false, prefix: "Produces");
}

internal static ProducesResponseTypeMetadata CreateUnvalidated(Type? type, int statusCode, IEnumerable<string> contentTypes, string? description) => new(statusCode, type, contentTypes, description);
internal static ProducesResponseTypeMetadata CreateUnvalidated(Type? type, int statusCode, IEnumerable<string> contentTypes) => new(statusCode, type, contentTypes);
}
1 change: 0 additions & 1 deletionsrc/Http/Http.Abstractions/src/PublicAPI.Shipped.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -413,7 +413,6 @@ Microsoft.AspNetCore.Http.ProblemDetailsContext.ProblemDetails.set -> void
Microsoft.AspNetCore.Http.ProblemDetailsContext.ProblemDetailsContext() -> void
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ContentTypes.get -> System.Collections.Generic.IEnumerable<string!>!
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null) -> void
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.StatusCode.get -> int
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Type.get -> System.Type?
Microsoft.AspNetCore.Http.QueryString
Expand Down
5 changes: 3 additions & 2 deletionssrc/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ Microsoft.AspNetCore.Http.Metadata.IParameterBindingMetadata.IsOptional.get -> b
Microsoft.AspNetCore.Http.Metadata.IParameterBindingMetadata.Name.get -> string!
Microsoft.AspNetCore.Http.Metadata.IParameterBindingMetadata.ParameterInfo.get -> System.Reflection.ParameterInfo!
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Description.get -> string?
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Description.set -> void
Microsoft.AspNetCore.Http.Metadata.IProducesResponseTypeMetadata.Description.get -> string?
*REMOVED*Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null) -> void
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null, string? description = null) -> void
Microsoft.AspNetCore.Http.Metadata.IProducesResponseTypeMetadata.Description.set -> void
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null) -> void
6 changes: 3 additions & 3 deletionssrc/Http/Http.Extensions/src/RequestDelegateFactory.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1039,15 +1039,15 @@ private static void PopulateBuiltInResponseTypeMetadata(Type returnType, Endpoin

if (returnType == typeof(string))
{
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(type: typeof(string), statusCode: 200, PlaintextContentType, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(type: typeof(string), statusCode: 200, PlaintextContentType));
}
else if (returnType == typeof(void))
{
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, PlaintextContentType), description: null);
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, PlaintextContentType));
}
else
{
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, DefaultAcceptsAndProducesContentType), description: null);
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, DefaultAcceptsAndProducesContentType));
}
}

Expand Down
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/AcceptedAtRouteOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -122,6 +122,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/AcceptedOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/BadRequestOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status400BadRequest, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status400BadRequest, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/ConflictOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status409Conflict, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status409Conflict, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/CreatedAtRouteOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -125,6 +125,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/CreatedOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,6 +99,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/InternalServerErrorOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status500InternalServerError, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status500InternalServerError, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/NotFoundOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status404NotFound, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status404NotFound, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/OkOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status200OK, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status200OK, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/UnprocessableEntityOfT.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status422UnprocessableEntity, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status422UnprocessableEntity, ContentTypeConstants.ApplicationJsonContentTypes));
}
}
2 changes: 1 addition & 1 deletionsrc/Http/Http.Results/src/ValidationProblem.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,6 +76,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
ArgumentNullException.ThrowIfNull(method);
ArgumentNullException.ThrowIfNull(builder);

builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(HttpValidationProblemDetails), StatusCodes.Status400BadRequest, ContentTypeConstants.ProblemDetailsContentTypes, description: null));
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(HttpValidationProblemDetails), StatusCodes.Status400BadRequest, ContentTypeConstants.ProblemDetailsContentTypes));
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp