-
Notifications
You must be signed in to change notification settings - Fork 59
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
[Feature] Enum types from strings or metadata #146
Comments
@sergey-tihon I made a first pass at this here but I am having trouble in a few areas and need pointers (I only took a guess at how to do it):
|
First of all, I am not surer that it will be easy task to generate provided enums
Serialization is done here https://github.com/fsprojects/SwaggerProvider/blob/master/src/SwaggerProvider.Runtime/ProvidedApiClientBase.fs#L34-L37 but you even can inherit from ProvidedClient and experiment with serialization without modifying TP code http://fsprojects.github.io/SwaggerProvider/#/Customization#serialization
Is it possible to add new controller here https://github.com/fsprojects/SwaggerProvider/tree/master/tests/Swashbuckle.WebApi.Server/Controllers and integrate |
@sergey-tihon I am very close to getting it to work. There are two failings tests, both with the same root cause (very similar to this issue), which looks like a serialization issue. EDIT: I think this issue may be due to headers and query parameters not going thru the EDIT2: It seems that "toQueryParams" falls back to use obj.ToString() if the type is not mapped, which makes sense as ToString inside DefinitionCompiler can use more context to serialize the type. I am however stuck with how to implement ToString on the enum type. (Note that other enum tests are not failing, which suggests this is an issue with the Option type):
|
Just got hit by this myself, in the sense that I thought my OpenApi was wrong as I expected a I appreciate that this isn't trivial to add (just mapping it to .NET enums clearly won't work, though DU's seem a natural fit). Just good to know this isn't supported atm. |
Just realising this, but isn’t generating DUs from a TP currently simply not supported? I mean, CLI enums seems to the best we can do here, right? Or is that essentially the suggestion here? |
Yes, all F# specific types are not supported (like DUs and records), that is why it is Not sure about CLI enums ... Never saw them emitted by TP. |
CLI enums would be better than nothing, that is for sure. In my case (see the picture above), I can assign just pure string - not DU and not even CLI enum. |
Here is a schema.json that demonstrates the issue.
When "enum" schema components are encountered in json schema, SwaggerProvider seems to strip their info away and just label the type as strings or int (depending on JsonStringEnumConverter).
This makes working with APIs a bit painful. Azure seems to deal with this issue using x-ms-enum which means it would add meta data for codegen (regardless of if its an int or string encoding for enum value).
Code to demonstrate issue, noting that it is not possible to even create a TaskType, one has to work out what the valid values are by looking at the raw JSON schema (and hoping it doesn't change like it did for me):
It would be nice if SwaggerProvider could generate this:
type TaskType = This | That | Other
based on x-ms-enum or stringRelated information
NET Core SDK & Linux
The text was updated successfully, but these errors were encountered: