Skip to content

Commit c957e3c

Browse files
committed
- adds primary error message extension
Signed-off-by: Vincent Biret <[email protected]>
1 parent 1152540 commit c957e3c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
4+
// ------------------------------------------------------------
5+
6+
using System;
7+
using Microsoft.OpenApi.Any;
8+
using Microsoft.OpenApi.Interfaces;
9+
using Microsoft.OpenApi.Writers;
10+
11+
namespace Microsoft.OpenApi.MicrosoftExtensions;
12+
13+
/// <summary>
14+
/// Extension element for OpenAPI to add tag the primary error message to use on error types. x-ms-primary-error-message
15+
/// </summary>
16+
public class OpenApiPrimaryErrorMessageExtension : IOpenApiExtension
17+
{
18+
/// <summary>
19+
/// Name of the extension as used in the description.
20+
/// </summary>
21+
public static string Name => "x-ms-primary-error-message";
22+
/// <inheritdoc />
23+
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
24+
{
25+
if(writer is null) throw new ArgumentNullException(nameof(writer));
26+
writer.WriteValue(IsPrimaryErrorMessage);
27+
}
28+
/// <summary>
29+
/// Whether this property is the primary error message to use on error types.
30+
/// </summary>
31+
public bool IsPrimaryErrorMessage { get; set; }
32+
/// <summary>
33+
/// Parses the <see cref="IOpenApiAny"/> to <see cref="OpenApiPrimaryErrorMessageExtension"/>.
34+
/// </summary>
35+
/// <param name="source">The source object.</param>
36+
/// <returns>The <see cref="OpenApiPrimaryErrorMessageExtension"/>.</returns>
37+
public static OpenApiPrimaryErrorMessageExtension Parse(IOpenApiAny source)
38+
{
39+
if (source is not OpenApiBoolean rawObject) throw new ArgumentOutOfRangeException(nameof(source));
40+
return new OpenApiPrimaryErrorMessageExtension() {
41+
IsPrimaryErrorMessage = rawObject.Value
42+
};
43+
}
44+
}

0 commit comments

Comments
 (0)