Skip to content
Open
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
Expand Up @@ -208,10 +208,10 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
openApiSchema.Type = JsonSchemaType.Object;
}
}
else if (returnType.IsPrimitive())
else if (returnType.IsPrimitive() || returnType.IsEnum())
{
// A property or operation response that is of a primitive type is represented as an object with a single name/value pair,
// whose name is value and whose value is a primitive value.
// A property or operation response that is of a primitive or enum type is represented as an object with a single name/value pair,
// whose name is value and whose value is a primitive or enum value.
schema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,40 @@ public async Task CreateResponseForDeltaEdmFunctionReturnCorrectResponses(bool e
Assert.True(JsonNode.DeepEquals(expectedJsonNode, actualJsonNode));
}
}

[Fact]
public void CreateResponseForEdmFunctionReturningEnumWrapsInValueProperty()
{
// Arrange
var model = new EdmModel();
var enumType = new EdmEnumType("NS", "Color");
enumType.AddMember("Red", new EdmEnumMemberValue(0));
enumType.AddMember("Blue", new EdmEnumMemberValue(1));
model.AddElement(enumType);

var function = new EdmFunction("NS", "GetFavoriteColor", new EdmEnumTypeReference(enumType, isNullable: false), isBound: false, entitySetPathExpression: null, isComposable: true);
model.AddElement(function);

var context = new ODataContext(model);
var document = new OpenApiDocument();

// Act
var responses = context.CreateResponses(function, document);

// Assert
Assert.NotNull(responses);
Assert.True(responses.ContainsKey("200"));
var response = responses["200"];
Assert.NotNull(response.Content);
Assert.True(response.Content.ContainsKey("application/json"));
var mediaType = response.Content["application/json"];
Assert.NotNull(mediaType.Schema);
Assert.Equal(JsonSchemaType.Object, mediaType.Schema.Type);
Assert.NotNull(mediaType.Schema.Properties);
Assert.True(mediaType.Schema.Properties.ContainsKey("value"));

var valueSchema = mediaType.Schema.Properties["value"];
Assert.NotNull(valueSchema);
}
}
}