-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support OpenAPI summaries, descriptions, and examples for minimal APIs #40045
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/Http/Http.Abstractions/src/Metadata/IDescriptionMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Defines a contract used to specify a description in <see cref="Endpoint.Metadata"/>. | ||
/// </summary> | ||
public interface IDescriptionMetadata | ||
{ | ||
/// <summary> | ||
/// Gets the description associated with the endpoint. | ||
/// </summary> | ||
string Description { get; } | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Http/Http.Abstractions/src/Metadata/IExampleMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Defines a contract used to specify an example for a parameter, request body, or response | ||
/// associated with an <see cref="Endpoint"/>. | ||
/// </summary> | ||
public interface IExampleMetadata | ||
{ | ||
/// <summary> | ||
/// Gets the summary associated with the example. | ||
/// </summary> | ||
string Summary { get; } | ||
|
||
/// <summary> | ||
/// Gets the description associated with the example. | ||
/// </summary> | ||
string Description { get; } | ||
|
||
/// <summary> | ||
/// Gets an example value associated with an example. | ||
/// This property is mutually exclusibe with <see cref="ExternalValue"/>. | ||
/// </summary> | ||
object? Value { get; } | ||
|
||
/// <summary> | ||
/// Gets a reference to an external value associated with an example. | ||
/// This property is mutually exclusibe with <see cref="Value"/>. | ||
/// </summary> | ||
string? ExternalValue { get; } | ||
|
||
/// <summary> | ||
/// If the example targets a parameter, gets | ||
/// or sets the name of the parameter associated with the target. | ||
/// </summary> | ||
string? ParameterName { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Http/Http.Abstractions/src/Metadata/ISummaryMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Defines a contract used to specify a summary in <see cref="Endpoint.Metadata"/>. | ||
/// </summary> | ||
public interface ISummaryMetadata | ||
{ | ||
/// <summary> | ||
/// Gets the summary associated with the endpoint. | ||
/// </summary> | ||
string Summary { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Specifies a description for the endpoint in <see cref="Endpoint.Metadata"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// The OpenAPI specification supports a description attribute on operations and parameters that | ||
/// can be used to annotate endpoints with detailed, multiline descriptors of their behavior. | ||
/// behavior. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate | AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] | ||
public sealed class DescriptionAttribute : Attribute, IDescriptionMetadata | ||
{ | ||
/// <summary> | ||
/// Initializes an instance of the <see cref="DescriptionAttribute"/>. | ||
/// </summary> | ||
/// <param name="description">The description associated with the endpoint or parameter.</param> | ||
public DescriptionAttribute(string description) | ||
{ | ||
Description = description; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Description { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Specifies an example associated with a parameter, request body, or response of an <see cref="Endpoint"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// The OpenAPI specification supports an examples property that can be used to annotate | ||
/// request bodies, parameters, and responses with examples of the data type associated | ||
/// with each element. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] | ||
public sealed class ExampleAttribute : Attribute, IExampleMetadata | ||
{ | ||
/// <summary> | ||
/// Initializes an instance of the <see cref="ExampleAttribute"/> given | ||
/// a <see cref="Value"/>. | ||
/// </summary> | ||
public ExampleAttribute(string summary, string description, object value) | ||
{ | ||
Summary = summary; | ||
Description = description; | ||
Value = value; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes an instance of the <see cref="ExampleAttribute"/> given | ||
/// an <see cref="ExternalValue"/>. | ||
/// </summary> | ||
public ExampleAttribute(string summary, string description, string externalValue) | ||
{ | ||
Summary = summary; | ||
Description = description; | ||
ExternalValue = externalValue; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Description { get; } | ||
|
||
/// <inheritdoc /> | ||
public string Summary { get; } | ||
|
||
/// <inheritdoc /> | ||
public object? Value { get; } | ||
|
||
/// <inheritdoc /> | ||
public string? ExternalValue { get; } | ||
|
||
/// <inheritdoc /> | ||
public string? ParameterName { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
#nullable enable | ||
Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions | ||
static Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions.ConfigureRouteHandlerJsonOptions(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<Microsoft.AspNetCore.Http.Json.JsonOptions!>! configureOptions) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! | ||
Microsoft.AspNetCore.Http.DescriptionAttribute | ||
Microsoft.AspNetCore.Http.DescriptionAttribute.DescriptionAttribute(string! description) -> void | ||
Microsoft.AspNetCore.Http.DescriptionAttribute.Description.get -> string! | ||
Microsoft.AspNetCore.Http.SummaryAttribute | ||
Microsoft.AspNetCore.Http.SummaryAttribute.SummaryAttribute(string! summary) -> void | ||
Microsoft.AspNetCore.Http.SummaryAttribute.Summary.get -> string! | ||
Microsoft.AspNetCore.Http.ExampleAttribute | ||
Microsoft.AspNetCore.Http.ExampleAttribute.ExampleAttribute(string! summary, string! description, object! value) -> void | ||
Microsoft.AspNetCore.Http.ExampleAttribute.ExampleAttribute(string! summary, string! description, string! externalValue) -> void | ||
Microsoft.AspNetCore.Http.ExampleAttribute.Description.get -> string! | ||
Microsoft.AspNetCore.Http.ExampleAttribute.Summary.get -> string! | ||
Microsoft.AspNetCore.Http.ExampleAttribute.ExternalValue.get -> string? | ||
Microsoft.AspNetCore.Http.ExampleAttribute.Value.get -> object? | ||
Microsoft.AspNetCore.Http.ExampleAttribute.ParameterName.get -> string? | ||
Microsoft.AspNetCore.Http.ExampleAttribute.ParameterName.set -> void |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Http; | ||
|
||
/// <summary> | ||
/// Specifies a summary in <see cref="Endpoint.Metadata"/>. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)] | ||
public sealed class SummaryAttribute : Attribute, ISummaryMetadata | ||
{ | ||
/// <summary> | ||
/// Initializes an instance of the <see cref="SummaryAttribute"/>. | ||
/// </summary> | ||
/// <param name="summary">The summary associated with the endpoint or parameter.</param> | ||
public SummaryAttribute(string summary) | ||
{ | ||
Summary = summary; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Summary { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.