|
1 |
| -using System.Collections.Generic; |
| 1 | +using System.Collections.Generic; |
2 | 2 | using Newtonsoft.Json;
|
3 | 3 | using Styra.Opa.OpenApi.Models.Components;
|
4 | 4 |
|
5 | 5 | namespace Styra.Opa;
|
6 | 6 |
|
7 | 7 | public class OpaBatchInputs : Dictionary<string, Dictionary<string, object>>
|
8 | 8 | {
|
9 |
| - public override string ToString() |
10 |
| - { |
11 |
| - return JsonConvert.SerializeObject(this); |
12 |
| - } |
| 9 | + public override string ToString() |
| 10 | + { |
| 11 | + return JsonConvert.SerializeObject(this); |
| 12 | + } |
13 | 13 | }
|
14 | 14 |
|
15 | 15 | public class OpaBatchResults : Dictionary<string, OpaResult>
|
16 | 16 | {
|
17 |
| - public override string ToString() |
18 |
| - { |
19 |
| - return JsonConvert.SerializeObject(this); |
20 |
| - } |
| 17 | + public override string ToString() |
| 18 | + { |
| 19 | + return JsonConvert.SerializeObject(this); |
| 20 | + } |
21 | 21 | }
|
22 | 22 |
|
23 | 23 | public class OpaBatchErrors : Dictionary<string, OpaError>
|
24 | 24 | {
|
25 |
| - public override string ToString() |
26 |
| - { |
27 |
| - return JsonConvert.SerializeObject(this); |
28 |
| - } |
| 25 | + public override string ToString() |
| 26 | + { |
| 27 | + return JsonConvert.SerializeObject(this); |
| 28 | + } |
29 | 29 | }
|
30 | 30 |
|
31 | 31 | // Used for converting inputs for the Batch Query API, and converting result types
|
32 | 32 | // into useful higher-level types.
|
33 | 33 | public static class DictionaryExtensions
|
34 | 34 | {
|
35 |
| - public static Dictionary<string, Input> ToOpaBatchInputRaw(this Dictionary<string, Dictionary<string, object>> inputs) |
| 35 | + public static Dictionary<string, Input> ToOpaBatchInputRaw(this Dictionary<string, Dictionary<string, object>> inputs) |
| 36 | + { |
| 37 | + var opaBatchInputs = new Dictionary<string, Input>(); |
| 38 | + foreach (var kvp in inputs) |
36 | 39 | {
|
37 |
| - var opaBatchInputs = new Dictionary<string, Input>(); |
38 |
| - foreach (var kvp in inputs) |
39 |
| - { |
40 |
| - opaBatchInputs[kvp.Key] = Input.CreateMapOfAny(kvp.Value); |
41 |
| - } |
42 |
| - return opaBatchInputs; |
| 40 | + opaBatchInputs[kvp.Key] = Input.CreateMapOfAny(kvp.Value); |
43 | 41 | }
|
| 42 | + return opaBatchInputs; |
| 43 | + } |
44 | 44 |
|
45 |
| - // The OpenApi.Models.Errors variant of the ServerError type. |
46 |
| - public static OpaBatchErrors ToOpaBatchErrors(this Dictionary<string, Styra.Opa.OpenApi.Models.Errors.ServerError> errors) |
| 45 | + // The OpenApi.Models.Errors variant of the ServerError type. |
| 46 | + public static OpaBatchErrors ToOpaBatchErrors(this Dictionary<string, Styra.Opa.OpenApi.Models.Errors.ServerError> errors) |
| 47 | + { |
| 48 | + var opaBatchErrors = new OpaBatchErrors(); |
| 49 | + foreach (var kvp in errors) |
47 | 50 | {
|
48 |
| - var opaBatchErrors = new OpaBatchErrors(); |
49 |
| - foreach (var kvp in errors) |
50 |
| - { |
51 |
| - opaBatchErrors[kvp.Key] = new OpaError(kvp.Value); |
52 |
| - } |
53 |
| - return opaBatchErrors; |
| 51 | + opaBatchErrors[kvp.Key] = new OpaError(kvp.Value); |
54 | 52 | }
|
| 53 | + return opaBatchErrors; |
| 54 | + } |
55 | 55 |
|
56 |
| - // The OpenApi.Models.Components variant of the ServerError type. |
57 |
| - public static OpaBatchErrors ToOpaBatchErrors(this Dictionary<string, Styra.Opa.OpenApi.Models.Components.ServerError> errors) |
| 56 | + // The OpenApi.Models.Components variant of the ServerError type. |
| 57 | + public static OpaBatchErrors ToOpaBatchErrors(this Dictionary<string, Styra.Opa.OpenApi.Models.Components.ServerErrorWithStatusCode> errors) |
| 58 | + { |
| 59 | + var opaBatchErrors = new OpaBatchErrors(); |
| 60 | + foreach (var kvp in errors) |
58 | 61 | {
|
59 |
| - var opaBatchErrors = new OpaBatchErrors(); |
60 |
| - foreach (var kvp in errors) |
61 |
| - { |
62 |
| - opaBatchErrors[kvp.Key] = new OpaError(kvp.Value); |
63 |
| - } |
64 |
| - return opaBatchErrors; |
| 62 | + opaBatchErrors[kvp.Key] = new OpaError(kvp.Value); |
65 | 63 | }
|
| 64 | + return opaBatchErrors; |
| 65 | + } |
66 | 66 |
|
67 |
| - public static OpaBatchResults ToOpaBatchResults(this Dictionary<string, SuccessfulPolicyResponse> responses) |
| 67 | + public static OpaBatchResults ToOpaBatchResults(this Dictionary<string, SuccessfulPolicyResponse> responses) |
| 68 | + { |
| 69 | + var opaBatchResults = new OpaBatchResults(); |
| 70 | + foreach (var kvp in responses) |
68 | 71 | {
|
69 |
| - var opaBatchResults = new OpaBatchResults(); |
70 |
| - foreach (var kvp in responses) |
71 |
| - { |
72 |
| - opaBatchResults[kvp.Key] = (OpaResult)kvp.Value; |
73 |
| - } |
74 |
| - return opaBatchResults; |
| 72 | + opaBatchResults[kvp.Key] = (OpaResult)kvp.Value; |
75 | 73 | }
|
| 74 | + return opaBatchResults; |
| 75 | + } |
76 | 76 | }
|
0 commit comments