Azure / Azure/openapi-diff

Support xs-ms-enum values without the "value" label

Đang mở
#216 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
290
Fork
50
Merge trung bình
5 ngày 13 giờ
Pull request đã merge (30 ngày)
5

Mô tả

Some contract generators define the values of x-ms-enum as a list of actual values without labels.
The current version OpenApi-Diff doesn't support this format and throws a Newtonsoft.Json.JsonSerializationException in this case.

Example of x-ms-enum with and without the "value" label
` "enum": [
"Mammals",
"Fish",
"Birds",
"Reptiles",
"Amphibians",
"Invertebrates"
],
"type": "string",
"x-ms-enum": {
"name": "PetType",
"modelAsString": false,
"values": [
{
"value": 0,
"description": "humans and all other animals that are warm-blooded vertebrates",
"name": "Mammals"
},
{
"value": 1,
"description": "aquatic, craniate, gill-bearing animals that lack limbs with digits"
},
{
"value": 2,
"name": "Birds"
},
3,
4,
5
],
"x-nullable": false
}`

The issue with this XmsEnumExtension is that we cannot cast an object of primitive type (e.g. long, string) to a XmsEnumValue , thus all contracts that contains x-ms-enum with a list of values of primitive type causes a deserialization issue in the OpenApiDiff comparison.

The exception is the following

```
Newtonsoft.Json.JsonSerializationException : Error converting value 3 to type 'AutoRest.Swagger.Model.XmsEnumValue'. Path 'definitions.PetType.x-ms-enum.values[0]', line 235, position 11.
----> System.ArgumentException : Could not cast or convert from System.Int64 to AutoRest.Swagger.Model.XmsEnumValue.
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start by inspecting XmsEnumExtension and XmsEnumValue, then reproduce the Newtonsoft.Json deserialization failure with the shown x-ms-enum JSON in the OpenApi-Diff comparison path. Done means enum entries represented as primitive values, including 3, 4, and 5, deserialize and compare without throwing a JsonSerializationException.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
api, devtools
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.