Azure / Azure/openapi-diff

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

未关闭
#216 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
290
派生
50
平均合并
5 天 13 小时
30 天内合并 PR
5

描述

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.
```

贡献指南

打开贡献指南

调研方向

首先检查 XmsEnumExtension 和 XmsEnumValue,然后在 OpenApi-Diff 的比较路径中,使用所示的 x-ms-enum JSON 重现 Newtonsoft.Json 的反序列化失败。完成的标准是:表示为原始值的枚举项(包括 3、4 和 5)能够反序列化并进行比较,而不会抛出 JsonSerializationException。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
api, devtools
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。