Skip to content

Commit 6dc21b3

Browse files
committed
chore: marks new APIs as experimental
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 098f24e commit 6dc21b3

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
// Polyfill for ExperimentalAttribute which is only available in .NET 8+.
5+
// Since the compiler queries for this attribute by name, having it source-included
6+
// is sufficient for the compiler to recognize it.
7+
namespace System.Diagnostics.CodeAnalysis
8+
{
9+
#if !NET8_0_OR_GREATER
10+
/// <summary>
11+
/// Indicates that an API is experimental and it may change in the future.
12+
/// </summary>
13+
/// <remarks>
14+
/// This attribute allows call sites to be flagged with a diagnostic that indicates that an experimental
15+
/// feature is used. Authors can use this attribute to ship preview features in their assemblies.
16+
/// </remarks>
17+
[AttributeUsage(
18+
AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct |
19+
AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property |
20+
AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate,
21+
Inherited = false)]
22+
internal sealed class ExperimentalAttribute : Attribute
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="ExperimentalAttribute"/> class,
26+
/// specifying the ID that the compiler will use when reporting a use of the API.
27+
/// </summary>
28+
/// <param name="diagnosticId">The ID that the compiler will use when reporting a use of the API.</param>
29+
public ExperimentalAttribute(string diagnosticId)
30+
{
31+
DiagnosticId = diagnosticId;
32+
}
33+
34+
/// <summary>
35+
/// Gets the ID that the compiler will use when reporting a use of the API.
36+
/// </summary>
37+
public string DiagnosticId { get; }
38+
39+
/// <summary>
40+
/// Gets or sets the URL for corresponding documentation.
41+
/// The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID.
42+
/// </summary>
43+
public string? UrlFormat { get; set; }
44+
}
45+
#endif
46+
}

src/Microsoft.OpenApi/Services/OpenApiPathHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
#pragma warning disable OAI020 // Internal implementation uses experimental APIs
45
using System;
56
using System.Collections.Generic;
7+
using System.Diagnostics.CodeAnalysis;
68

79
namespace Microsoft.OpenApi;
810

911
/// <summary>
1012
/// Provides helper methods for converting OpenAPI JSON Pointer paths between specification versions.
1113
/// </summary>
14+
[Experimental("OAI020", UrlFormat = "https://aka.ms/openapi/net/experimental/{0}")]
1215
public static class OpenApiPathHelper
1316
{
1417
private static readonly Dictionary<OpenApiSpecVersion, IOpenApiPathRepresentationPolicy[]> _policies = new()

src/Microsoft.OpenApi/Validations/OpenApiValidatorError.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
#pragma warning disable OAI020 // Internal implementation uses experimental APIs
5+
using System.Diagnostics.CodeAnalysis;
6+
47
namespace Microsoft.OpenApi
58
{
69
/// <summary>
@@ -29,6 +32,7 @@ public OpenApiValidatorError(string ruleName, string pointer, string message) :
2932
/// The equivalent pointer in the target version, the original pointer if no transformation is needed,
3033
/// or <c>null</c> if the pointer has no equivalent in the target version.
3134
/// </returns>
35+
[Experimental("OAI020", UrlFormat = "https://aka.ms/openapi/net/experimental/{0}")]
3236
public string? GetVersionedPointer(OpenApiSpecVersion targetVersion)
3337
{
3438
if (Pointer is null)

test/Microsoft.OpenApi.Tests/Services/OpenApiPathHelperTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
#nullable enable
5+
#pragma warning disable OAI020 // Type is for evaluation purposes only
56
using Xunit;
67

78
namespace Microsoft.OpenApi.Tests.Services;

0 commit comments

Comments
 (0)