public static SecurityRequirement LoadSecurityRequirement(ParseNode node) { var mapNode = node.CheckMapNode("security"); var obj = new SecurityRequirement(); foreach (var property in mapNode) { var scheme = SecurityScheme.LoadByReference(new ValueNode(mapNode.Context, property.Name)); obj.Schemes.Add(scheme, property.Value.CreateSimpleList <string>(n2 => n2.GetScalarValue())); } return(obj); }
public static string StringValue(this SecurityRequirement securityRequirement) { switch (securityRequirement) { case SecurityRequirement.High: return("H"); case SecurityRequirement.Medium: return("M"); case SecurityRequirement.Low: return("L"); default: throw new ArgumentOutOfRangeException(nameof(securityRequirement), securityRequirement, null); } }
private static SecurityRequirement ParseSecurityRequirement(JsonElement definition) { foreach (JsonProperty item in definition.EnumerateObject()) { SecurityRequirement scheme = new SecurityRequirement() { SchemeName = item.Name, Scopes = new string[item.Value.GetArrayLength()] }; int i = 0; foreach (JsonElement element in item.Value.EnumerateArray()) { scheme.Scopes[i++] = element.GetString(); } return(scheme); } return(null); }
public static void WriteSecurityRequirement(IParseNodeWriter writer, SecurityRequirement securityRequirement) { writer.WriteStartMap(); foreach (var scheme in securityRequirement.Schemes) { writer.WritePropertyName(scheme.Key.Pointer.TypeName); writer.WriteStartList(); foreach (var scope in scheme.Value) { writer.WriteValue(scope); } writer.WriteEndList(); } writer.WriteEndMap(); }
public static SecurityRequirement LoadSecurityRequirement(ParseNode node) { var mapNode = node.CheckMapNode("security"); var obj = new SecurityRequirement(); foreach (var property in mapNode) { var scheme = SecurityScheme.LoadByReference(new ValueNode(mapNode.Context, property.Name)); if (scheme != null) { obj.Schemes.Add(scheme, property.Value.CreateSimpleList <string>(n2 => n2.GetScalarValue())); } else { node.Context.ParseErrors.Add(new OpenApiError(node.Context.GetLocation(), $"Scheme {property.Name} is not found")); } } return(obj); }
private static SecurityRequirement[] ParseSecurityRequirements(JArray securitySchemes) { if (securitySchemes == null) { return null; } var result = new List<SecurityRequirement>(); foreach (JObject securityObject in securitySchemes) { var security = ((securitySchemes.First() as JObject).First as JProperty); var item = new SecurityRequirement { Name = security.Name, Values = (security.Value as JArray).Values<string>().ToArray() }; result.Add(item); } return result.ToArray(); }