Skip to content

Commit ede77de

Browse files
committed
Update public api.
1 parent 3e4bf01 commit ede77de

File tree

2 files changed

+96
-20
lines changed

2 files changed

+96
-20
lines changed

test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.OpenApi.Hidi.Formatters;
1+
using Microsoft.OpenApi.Any;
2+
using Microsoft.OpenApi.Hidi.Formatters;
3+
using Microsoft.OpenApi.Interfaces;
24
using Microsoft.OpenApi.Models;
35
using Microsoft.OpenApi.Services;
46
using Xunit;
@@ -43,14 +45,103 @@ public void FormatOperationIdsInOpenAPIDocument(string operationId, string expec
4345
Assert.Equal(expectedOperationId, openApiDocument.Paths[path].Operations[operationType].OperationId);
4446
}
4547

48+
[Fact]
4649
public void RemoveAnyOfAndOneOfFromSchema()
4750
{
4851
// 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()
5096
{
5197
Info = new() { Title = "Test", Version = "1.0" },
5298
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+
},
54145
Components = new()
55146
{
56147
Schemas = new Dictionary<string, OpenApiSchema>
@@ -88,23 +179,6 @@ public void RemoveAnyOfAndOneOfFromSchema()
88179
}
89180
}
90181
};
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);
108182
}
109183
}
110184
}

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ namespace Microsoft.OpenApi.Models
10241024
Callback = 8,
10251025
[Microsoft.OpenApi.Attributes.Display("tags")]
10261026
Tag = 9,
1027+
[Microsoft.OpenApi.Attributes.Display("paths")]
1028+
Path = 10,
10271029
}
10281030
public class RuntimeExpressionAnyWrapper : Microsoft.OpenApi.Interfaces.IOpenApiElement
10291031
{

0 commit comments

Comments
 (0)