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

Add functionality for customizing derived Haskell type names #140

Merged

Conversation

jmickelin
Copy link

@jmickelin jmickelin commented Mar 2, 2020

Introduces a third way to handle Avro namespaces, namely by providing your own function to map namespaced Avro types to Haskell types.

This provides a middle ground between IgnoreNamespaces (doesn't handle name clashes) and HandleNamespaces (very very verbose), allowing you to do for example:

disambiguateOffendingType :: Text -> [Text] -> Text
disambiguateOffendingType t ns
  | ns <> [t] == ["some", "namespace", "somewhere" "OffendingType"] = "OffendingType"
  | ns <> [t] == ["some", "other", "namespace", "using", "the", "same", "type", "name", "for", "whatever", "reason", "OffendingType"] = "OffendingTypeOther"
  | otherwise = t

Used like so:

deriveAvroWithOptions defaultOptions { namespaceBehavior = Custom disambiguateOffendingType } "my-avro-file.avsc"

@AlexeyRaga
Copy link
Member

Thanks!

@AlexeyRaga AlexeyRaga merged commit 8e40518 into haskell-works:master Mar 6, 2020
@jmickelin jmickelin deleted the custom-typename-deriving branch March 18, 2020 13:39
@jmickelin jmickelin restored the custom-typename-deriving branch March 18, 2020 13:58
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

Successfully merging this pull request may close these issues.

2 participants