diff --git a/src/NSwag.CodeGeneration/Models/OperationModelBase.cs b/src/NSwag.CodeGeneration/Models/OperationModelBase.cs index c3149853e3..c4cf834a81 100644 --- a/src/NSwag.CodeGeneration/Models/OperationModelBase.cs +++ b/src/NSwag.CodeGeneration/Models/OperationModelBase.cs @@ -69,6 +69,9 @@ protected abstract TResponseModel CreateResponseModel(OpenApiOperation operation /// Gets the operation tags. public List Tags => _operation.Tags; + /// Gets the operation security. + public IEnumerable>> Security => _operation.Security.Select(s => s.AsEnumerable().ToDictionary(kv => kv.Key, kv => kv.Value)); + /// Gets or sets the HTTP path (i.e. the absolute route). public string Path { get; set; } diff --git a/src/NSwag.Core/OpenApiOperation.cs b/src/NSwag.Core/OpenApiOperation.cs index 98230d700d..5b94606768 100644 --- a/src/NSwag.Core/OpenApiOperation.cs +++ b/src/NSwag.Core/OpenApiOperation.cs @@ -150,7 +150,7 @@ public IReadOnlyList ActualParameters /// Gets or sets a security description. [JsonProperty(PropertyName = "security", Order = 14, DefaultValueHandling = DefaultValueHandling.Ignore)] - public ICollection Security { get; set; } + public ICollection Security { get; set; } = new Collection(); /// Gets or sets the servers (OpenAPI only). [JsonProperty(PropertyName = "servers", Order = 15, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]