Support xs-ms-enum values without the "value" label
- Vorherrschende Sprache
- C#
- Sterne
- 290
- Forks
- 50
- Ø Merge
- 5 T. 13 Std.
- Gemergte PRs (30 T.)
- 5
Beschreibung
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.
```
Beitragsleitfaden
Rechercherichtung
Beginnen Sie mit der Untersuchung von XmsEnumExtension und XmsEnumValue und reproduzieren Sie anschließend den Deserialisierungsfehler von Newtonsoft.Json mit dem gezeigten x-ms-enum JSON im Vergleichspfad von OpenApi-Diff. Als erledigt gilt die Aufgabe, wenn als primitive Werte dargestellte Enum-Einträge, einschließlich 3, 4 und 5, deserialisiert und verglichen werden können, ohne eine JsonSerializationException auszulösen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- api, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100