Skip to content

Commit 2a48a30

Browse files
authored
Adds schema to content types of stream properties that have a collection of acceptable media types (#436)
* Add schema to content types of stream properties * Add test to validate schema is not null and has right property values * Fix tests * Bumps up version
1 parent 37c1a8c commit 2a48a30

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.5.0-preview5</Version>
18+
<Version>1.5.0-preview6</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
@@ -26,6 +26,7 @@
2626
- Fixes casing in default propertyName for `innerError` in the `ErrorMainSchema`
2727
- Adds support for `x-ms-enum-flags` extension for flagged enums
2828
- Use containment together with RequiresExplicitBinding annotation to check whether to append bound operations to navigation properties #430
29+
- Adds schema to content types of stream properties that have a collection of acceptable media types #435
2930
</PackageReleaseNotes>
3031
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3132
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ protected string GetOperationId(string prefix, string identifier)
136136
/// <returns>The entity content description.</returns>
137137
protected IDictionary<string, OpenApiMediaType> GetContentDescription()
138138
{
139-
var content = new Dictionary<string, OpenApiMediaType>();
140-
141-
OpenApiSchema schema = new OpenApiSchema
142-
{
143-
Type = "string",
144-
Format = "binary"
145-
};
146-
147139
// Fetch the respective AcceptableMediaTypes
148140
(_, var property) = GetStreamElements();
149141
IEnumerable<string> mediaTypes = null;
@@ -153,11 +145,21 @@ protected IDictionary<string, OpenApiMediaType> GetContentDescription()
153145
CoreConstants.AcceptableMediaTypes);
154146
}
155147

148+
OpenApiSchema schema = new()
149+
{
150+
Type = "string",
151+
Format = "binary"
152+
};
153+
154+
var content = new Dictionary<string, OpenApiMediaType>();
156155
if (mediaTypes != null)
157156
{
158157
foreach (string item in mediaTypes)
159158
{
160-
content.Add(item, null);
159+
content.Add(item, new OpenApiMediaType
160+
{
161+
Schema = schema
162+
});
161163
}
162164
}
163165
else

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityGetOperationHandlerTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ private void VerifyMediaEntityGetOperation(string annotation, bool enableOperati
9393
var statusCode = useHTTPStatusCodeClass2XX ? Constants.StatusCodeClass2XX : Constants.StatusCode200;
9494
Assert.Equal(new[] { statusCode, "default" }, getOperation.Responses.Select(r => r.Key));
9595
Assert.Equal(new[] { statusCode, "default" }, getOperation2.Responses.Select(r => r.Key));
96+
Assert.NotNull(getOperation.Responses[statusCode].Content.Values?.Select(x => x.Schema));
97+
98+
foreach (var item in getOperation.Responses[statusCode].Content)
99+
{
100+
Assert.Equal("binary", item.Value.Schema.Format);
101+
Assert.Equal("string", item.Value.Schema.Type);
102+
}
96103

97104
if (!string.IsNullOrEmpty(annotation))
98105
{

0 commit comments

Comments
 (0)