Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
Expand Down Expand Up @@ -184,13 +184,20 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
schema = context.CreateEdmTypeSchema(operation.ReturnType);
}

string mediaType = Constants.ApplicationJsonMediaType;
if (operation.ReturnType.AsPrimitive()?.PrimitiveKind() == EdmPrimitiveTypeKind.Stream)
{
// Responses of types Edm.Stream should be application/octet-stream
mediaType = Constants.ApplicationOctetStreamMediaType;
}

OpenApiResponse response = new()
{
Description = "Success",
Content = new Dictionary<string, OpenApiMediaType>
{
{
Constants.ApplicationJsonMediaType,
mediaType,
new OpenApiMediaType
{
Schema = schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@ public void CreateResponseForEdmFunctionReturnCorrectResponses(bool isFunctionIm
}
}

[Fact]
public void CreateResponseForEdmFunctionOfStreamReturnTypeReturnsCorrectResponse()
{
// Arrange
string operationName = "getMailboxUsageStorage";
IEdmModel model = EdmModelHelper.GraphBetaModel;
ODataContext context = new(model);

// Act
OpenApiResponses responses;
IEdmOperation operation = model.SchemaElements.OfType<IEdmOperation>().First(o => o.Name == operationName);
Assert.NotNull(operation); // guard
ODataPath path = new(new ODataOperationSegment(operation));
responses = context.CreateResponses(operation, path);

// Assert
Assert.NotNull(responses);
Assert.NotEmpty(responses);
Assert.Equal(2, responses.Count);
Assert.Equal(new string[] { "200", "default" }, responses.Select(r => r.Key));

OpenApiResponse response = responses["200"];
Assert.NotNull(response.Content);
OpenApiMediaType mediaType = response.Content["application/octet-stream"];
}

[Theory]
[InlineData("ShareTrip", false, "204")]
[InlineData("ResetDataSource", true, "204")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27568,7 +27568,7 @@
<Function Name="getMailboxUsageStorage" IsBound="true" IsComposable="true">
<Parameter Name="reportRoot" Type="graph.reportRoot" />
<Parameter Name="period" Type="Edm.String" Nullable="false" Unicode="false" />
<ReturnType Type="Collection(graph.mailboxUsageStorage)" Nullable="false" />
<ReturnType Type="Edm.Stream" Nullable="false" />
</Function>
<Function Name="getOffice365ActivationCounts" IsBound="true" IsComposable="true">
<Parameter Name="reportRoot" Type="graph.reportRoot" />
Expand Down