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

Latest Preview 1.0 - beta4 - Enum inferred type is int #186

Closed
jkone27 opened this issue Jun 12, 2021 · 7 comments
Closed

Latest Preview 1.0 - beta4 - Enum inferred type is int #186

jkone27 opened this issue Jun 12, 2021 · 7 comments

Comments

@jkone27
Copy link
Contributor

jkone27 commented Jun 12, 2021

Description

https://swagger.io/docs/specification/data-models/enums/

 {
            "name": "target",
            "in": "query",
            "description": "Service to search. Leave blank or specify 'undefined' to search globally, specify any other target to search just that section of data.",
            "required": false,
            "type": "string",
            "enum": [ "Undefined", "CustomerName", "CustomerAddress", "CustomerEmail", "OrderNumber", "CustomerPaymentProviderReference", "CustomerPaymentInternalReference", "FlightProductCheckinAddress", "Pnr", "TicketNumber", "CustomerCompany", "InsurancePolicyNumber", "SupplierReference" ]
}

and SwaggerProvider generated type instead is int, wheras should be string (or eventually an Enum with valid values, before it was string with the old "LTS" package

This causes new generate types not to be compatible with "old" ones.

image

image

@Thorium
Copy link
Member

Thorium commented Jun 22, 2022

I have the same issue, schema:
"country_code":{"enum":["Unknown","CAN","USA"],"type":"string"}

... with SwaggerProwider 0.12 (NewtonSoft serialization) it used to serialize to String properly.
After SwaggerProwider 1.0 (System.Text.Json serialization) it serializes incorrectly to Option<Int>.

@Thorium
Copy link
Member

Thorium commented Jun 22, 2022

The real problem here is that NewtonSoft is already running at v13, and SwaggerProvider 0.12 package has a fixed dependency:

[Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/) (>= 12.0.3 && < 12.1.0)

I hope @sergey-tihon will release SwaggerProvider 0.12.2 having relaxed the NewtonSoft max version for people who want to continue using working serialization.

Edit: Here is a PR (which cannot be merged to master)
89e87b6

@sergey-tihon
Copy link
Member

@Thorium 0.12.2 is release - https://www.nuget.org/packages/SwaggerProvider/0.12.2 and thanks for the fix.

@jkone27 can you share the full schema with the issue and code snippet (what TP you used? SwaggerProvider or OpenApiProvider?)

@Thorium
Copy link
Member

Thorium commented Jun 25, 2022

Here is a random schema for SwaggerProvider that has the enum-issue:
https://api.sandbox.repayonline.com/rgapi/v1/swagger
https://api.sandbox.repayonline.com/rgapi/swagger/ui/index

@jkone27
Copy link
Contributor Author

jkone27 commented Jun 30, 2022

I used OpenApiProvider, dont have the schema with me rn but i hope @Thorium provided one is as good to reproduce

@sergey-tihon
Copy link
Member

Should be fixed in SwaggerProvider 2.0.0-beta2

@petrkoutnycz
Copy link

@sergey-tihon As I commented elsewhere, I would really appreciate having ability to have enum/discriminated union generated upon swagger schema when applicable. Should I create another issue for it?

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

4 participants