Closed petrkoutnycz closed 2 years ago
Problem is that CompiledName attribute does not work with members of union type. It works with values and functions.
The JSON serializers at runtime know about CompiledName
and it should work fine.
Are you targeting F# on dotnet or Fable?
Is your generated type missing [<Fable.Core.StringEnum>]
? It should be there.
I will need more information in order to debug your issue. Snowflaqe config, JSON returned from the GraphQL API, the runtime error you are getting and how the GraphQL schema looks like.
Here's the repo: https://github.com/petrkoutnycz/snowflaqe-issue-62
And this is the issue:
Generally, I dont think it is necessary to change the original casing.
Hi @petrkoutnycz thanks a lot for the sample repo. At first glance, I think this might be the culprit "serializer": "system"
can you try using the default serializer (by removing this config option or setting it to "newtonsoft") and see if the runtime errors disappear? I will do my own testing in the meantime
I confirm that there is no exception with newtonsoft
serializer, though the result is not successful and contains null values.
Hmm that's interesting. Not sure why this would happen, the newtonsoft
serializer definitely understands CompiledName
. The only way for me to debug this, is if I have the JSON content and the types that you are trying to deserialize to. Let me test things out and see why this is happening
I'd say that it'd be easier to skip the casing changes altogether to avoid such problems.
I'd say that it'd be easier to skip the casing changes altogether
@petrkoutnycz unfortunately, GraphQL enums are not always valid as union case names by default. For example, they could be lower-case.
Until I've figured out why the serializers are failing in runtime, I've added a boolean option called normalizeEnumCases
which is set to true
by default (preserving current behavior) that determines whether changes to enum values should applied. To fix your issue, set this option to false
in your snowflaqe.json
:
{
"normalizeEnumCases": false
}
Thank you, I really appreciate your quick response :-)
Generated union types currently contain members with different casing than the original enums. Problem is that
CompiledName
attribute does not work with members of union type. It works with values and functions.Example
Following code shows that value of
PPA
generates a propertyPpa
which causes a problem during the runtime.enum MyEnumType { Shopping PPA }
produces
type ProductLabelDomainType = | [<CompiledName "Shopping">] Shopping | [<CompiledName "PPA">] Ppa