Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kooli89 opened this issue Nov 29, 2021 · 2 comments
Open

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

kooli89 opened this issue Nov 29, 2021 · 2 comments

Comments

@kooli89
Copy link
Contributor

kooli89 commented Nov 29, 2021

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.
kooli89 pushed a commit to kooli89/openapi-diff that referenced this issue Nov 29, 2021
This commit fixes the following issue Azure#216
@jianyexi
Copy link
Contributor

jianyexi commented Dec 1, 2021

@kooli89 why to support the json format ? it does not make sense , as value in the "values" should have same pattern

@kooli89
Copy link
Contributor Author

kooli89 commented Dec 2, 2021

Hi @jianyexi,
I do agree that in one contract the "values" should have the same pattern.
In the example above I just wanted to show all the possible patterns.
openapi-diff supports almost all the patterns, but not the one without labels like the following example
"values": [0, 1, 2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants