Repository navigation
Expand file tree
/
Copy pathAsyncApiSecurityScheme.cs
More file actions
118 lines (102 loc) · 4.83 KB
/
Copy pathAsyncApiSecurityScheme.cs
File metadata and controls
118 lines (102 loc) · 4.83 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Models
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
public class AsyncApiSecurityScheme : IAsyncApiSerializable, IAsyncApiExtensible
{
/// <summary>
/// REQUIRED. The type of the security scheme. Valid values are "userPassword", "apiKey", "X509", "symmetricEncryption", "asymmetricEncryption", "httpApiKey", "http", "oauth2", "openIdConnect", "plain", "scramSha256", "scramSha512", and "gssapi".
/// </summary>
public virtual SecuritySchemeType Type { get; set; }
/// <summary>
/// A short description for security scheme. CommonMark syntax MAY be used for rich text representation.
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// REQUIRED. The name of the header, query or cookie parameter to be used.
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// REQUIRED. The location of the API key. Valid values are "user" and "password" for apiKey and "query", "header" or "cookie" for httpApiKey.
/// </summary>
public virtual ParameterLocation In { get; set; }
/// <summary>
/// REQUIRED. The name of the HTTP Authorization scheme to be used
/// in the Authorization header as defined in RFC7235.
/// </summary>
public virtual string Scheme { get; set; }
/// <summary>
/// A hint to the client to identify how the bearer token is formatted.
/// Bearer tokens are usually generated by an authorization server,
/// so this information is primarily for documentation purposes.
/// </summary>
public virtual string BearerFormat { get; set; }
/// <summary>
/// REQUIRED. An object containing configuration information for the flow types supported.
/// </summary>
public virtual AsyncApiOAuthFlows Flows { get; set; }
/// <summary>
/// REQUIRED. OpenId Connect URL to discover OAuth2 configuration values.
/// </summary>
public virtual Uri OpenIdConnectUrl { get; set; }
/// <summary>
/// Specification Extensions.
/// </summary>
public virtual IDictionary<string, IAsyncApiExtension> Extensions { get; set; } = new Dictionary<string, IAsyncApiExtension>();
/// <summary>
/// Serialize to AsyncApi V2 document without using reference.
/// </summary>
public virtual void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
// type
writer.WriteRequiredProperty(AsyncApiConstants.Type, this.Type.GetDisplayName());
// description
writer.WriteOptionalProperty(AsyncApiConstants.Description, this.Description);
switch (this.Type)
{
case SecuritySchemeType.UserPassword:
break;
case SecuritySchemeType.ApiKey:
writer.WriteOptionalProperty(AsyncApiConstants.In, this.In.GetDisplayName());
break;
case SecuritySchemeType.X509:
break;
case SecuritySchemeType.SymmetricEncryption:
break;
case SecuritySchemeType.AsymmetricEncryption:
break;
case SecuritySchemeType.HttpApiKey:
writer.WriteOptionalProperty(AsyncApiConstants.Name, this.Name);
writer.WriteOptionalProperty(AsyncApiConstants.In, this.In.GetDisplayName());
break;
case SecuritySchemeType.Http:
writer.WriteOptionalProperty(AsyncApiConstants.Scheme, this.Scheme);
writer.WriteOptionalProperty(AsyncApiConstants.BearerFormat, this.BearerFormat);
break;
case SecuritySchemeType.OAuth2:
writer.WriteOptionalObject(AsyncApiConstants.Flows, this.Flows, (w, o) => o.SerializeV2(w));
break;
case SecuritySchemeType.OpenIdConnect:
writer.WriteOptionalProperty(AsyncApiConstants.OpenIdConnectUrl, this.OpenIdConnectUrl?.ToString());
break;
case SecuritySchemeType.Plain:
break;
case SecuritySchemeType.ScramSha256:
break;
case SecuritySchemeType.ScramSha512:
break;
case SecuritySchemeType.Gssapi:
break;
default:
break;
}
// extensions
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}