|
1 |
| -using Microsoft.OpenApi.Hidi.Formatters; |
| 1 | +using Microsoft.OpenApi.Any; |
| 2 | +using Microsoft.OpenApi.Hidi.Formatters; |
| 3 | +using Microsoft.OpenApi.Interfaces; |
2 | 4 | using Microsoft.OpenApi.Models;
|
3 | 5 | using Microsoft.OpenApi.Services;
|
4 | 6 | using Xunit;
|
@@ -43,14 +45,103 @@ public void FormatOperationIdsInOpenAPIDocument(string operationId, string expec
|
43 | 45 | Assert.Equal(expectedOperationId, openApiDocument.Paths[path].Operations[operationType].OperationId);
|
44 | 46 | }
|
45 | 47 |
|
| 48 | + [Fact] |
46 | 49 | public void RemoveAnyOfAndOneOfFromSchema()
|
47 | 50 | {
|
48 | 51 | // Arrange
|
49 |
| - var openApiDocument = new OpenApiDocument() |
| 52 | + var openApiDocument = GetSampleOpenApiDocument(); |
| 53 | + |
| 54 | + // Act |
| 55 | + var powerShellFormatter = new PowerShellFormatter(); |
| 56 | + var walker = new OpenApiWalker(powerShellFormatter); |
| 57 | + walker.Walk(openApiDocument); |
| 58 | + |
| 59 | + var testSchema = openApiDocument.Components.Schemas["TestSchema"]; |
| 60 | + var averageAudioDegradationProperty = testSchema.Properties["averageAudioDegradation"]; |
| 61 | + var defaultPriceProperty = testSchema.Properties["defaultPrice"]; |
| 62 | + |
| 63 | + // Assert |
| 64 | + Assert.Null(averageAudioDegradationProperty.AnyOf); |
| 65 | + Assert.Equal("number", averageAudioDegradationProperty.Type); |
| 66 | + Assert.Equal("float", averageAudioDegradationProperty.Format); |
| 67 | + Assert.True(averageAudioDegradationProperty.Nullable); |
| 68 | + Assert.Null(defaultPriceProperty.OneOf); |
| 69 | + Assert.Equal("number", defaultPriceProperty.Type); |
| 70 | + Assert.Equal("double", defaultPriceProperty.Format); |
| 71 | + Assert.NotNull(testSchema.AdditionalProperties); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public void ResolveFunctionParameters() |
| 76 | + { |
| 77 | + // Arrange |
| 78 | + var openApiDocument = GetSampleOpenApiDocument(); |
| 79 | + |
| 80 | + // Act |
| 81 | + var powerShellFormatter = new PowerShellFormatter(); |
| 82 | + var walker = new OpenApiWalker(powerShellFormatter); |
| 83 | + walker.Walk(openApiDocument); |
| 84 | + |
| 85 | + var idsParameter = openApiDocument.Paths["/foo"].Operations[OperationType.Get].Parameters.Where(static p => p.Name == "ids").FirstOrDefault(); |
| 86 | + |
| 87 | + // Assert |
| 88 | + Assert.Null(idsParameter.Content); |
| 89 | + Assert.NotNull(idsParameter.Schema); |
| 90 | + Assert.Equal("array", idsParameter.Schema.Type); |
| 91 | + } |
| 92 | + |
| 93 | + private static OpenApiDocument GetSampleOpenApiDocument() |
| 94 | + { |
| 95 | + return new OpenApiDocument() |
50 | 96 | {
|
51 | 97 | Info = new() { Title = "Test", Version = "1.0" },
|
52 | 98 | Servers = new List<OpenApiServer>() { new() { Url = "https://localhost/" } },
|
53 |
| - Paths = new() { }, |
| 99 | + Paths = new() { |
| 100 | + { "/foo", new() |
| 101 | + { |
| 102 | + Operations = new Dictionary<OperationType, OpenApiOperation>() |
| 103 | + { |
| 104 | + { |
| 105 | + OperationType.Get, new() |
| 106 | + { |
| 107 | + OperationId = "Foo.GetFoo", |
| 108 | + Parameters = new List<OpenApiParameter> |
| 109 | + { |
| 110 | + new OpenApiParameter() |
| 111 | + { |
| 112 | + Name = "ids", |
| 113 | + In = ParameterLocation.Query, |
| 114 | + Content = new Dictionary<string, OpenApiMediaType> |
| 115 | + { |
| 116 | + { |
| 117 | + "application/json", |
| 118 | + new OpenApiMediaType |
| 119 | + { |
| 120 | + Schema = new OpenApiSchema |
| 121 | + { |
| 122 | + Type = "array", |
| 123 | + Items = new OpenApiSchema |
| 124 | + { |
| 125 | + Type = "string" |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + }, |
| 133 | + Extensions = new Dictionary<string, IOpenApiExtension> |
| 134 | + { |
| 135 | + { |
| 136 | + "x-ms-docs-operation-type", new OpenApiString("function") |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + }, |
54 | 145 | Components = new()
|
55 | 146 | {
|
56 | 147 | Schemas = new Dictionary<string, OpenApiSchema>
|
@@ -88,23 +179,6 @@ public void RemoveAnyOfAndOneOfFromSchema()
|
88 | 179 | }
|
89 | 180 | }
|
90 | 181 | };
|
91 |
| - |
92 |
| - // Act |
93 |
| - var powerShellFormatter = new PowerShellFormatter(); |
94 |
| - var walker = new OpenApiWalker(powerShellFormatter); |
95 |
| - walker.Walk(openApiDocument); |
96 |
| - |
97 |
| - var averageAudioDegradationProperty = openApiDocument.Components.Schemas["TestSchema"].Properties["averageAudioDegradation"]; |
98 |
| - var defaultPriceProperty = openApiDocument.Components.Schemas["TestSchema"].Properties["defaultPrice"]; |
99 |
| - |
100 |
| - // Assert |
101 |
| - Assert.Null(averageAudioDegradationProperty.AnyOf); |
102 |
| - Assert.Equal("number", averageAudioDegradationProperty.Type); |
103 |
| - Assert.Equal("float", averageAudioDegradationProperty.Format); |
104 |
| - Assert.True(averageAudioDegradationProperty.Nullable); |
105 |
| - Assert.Null(defaultPriceProperty.OneOf); |
106 |
| - Assert.Equal("number", defaultPriceProperty.Type); |
107 |
| - Assert.Equal("double", defaultPriceProperty.Format); |
108 | 182 | }
|
109 | 183 | }
|
110 | 184 | }
|
0 commit comments