forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenApiOAuthFlowRules.cs
More file actions
47 lines (44 loc) · 1.79 KB
/
OpenApiOAuthFlowRules.cs
File metadata and controls
47 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
namespace Microsoft.OpenApi
{
/// <summary>
/// The validation rules for <see cref="OpenApiOAuthFlow"/>.
/// </summary>
[OpenApiRule]
public static class OpenApiOAuthFlowRules
{
/// <summary>
/// Validate the field is required.
/// </summary>
public static ValidationRule<OpenApiOAuthFlow> OAuthFlowRequiredFields =>
new(nameof(OAuthFlowRequiredFields),
(context, flow) =>
{
// authorizationUrl
if (flow.AuthorizationUrl == null)
{
context.Enter("authorizationUrl");
context.CreateError(nameof(OAuthFlowRequiredFields),
string.Format(SRResource.Validation_FieldIsRequired, "authorizationUrl", "OAuth Flow"));
context.Exit();
}
// tokenUrl
if (flow.TokenUrl == null)
{
context.Enter("tokenUrl");
context.CreateError(nameof(OAuthFlowRequiredFields),
string.Format(SRResource.Validation_FieldIsRequired, "tokenUrl", "OAuth Flow"));
context.Exit();
}
// scopes
if (flow.Scopes == null)
{
context.Enter("scopes");
context.CreateError(nameof(OAuthFlowRequiredFields),
string.Format(SRResource.Validation_FieldIsRequired, "scopes", "OAuth Flow"));
context.Exit();
}
});
}
}