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 enum types with numeric values #889

Open
endgame opened this issue Jan 17, 2023 · 4 comments
Open

Support enum types with numeric values #889

endgame opened this issue Jan 17, 2023 · 4 comments

Comments

@endgame
Copy link
Collaborator

endgame commented Jan 17, 2023

Example: Every value in apigateway's CacheClusterSize type contains only numbers and dots, so they all get mashed together into a single strange pattern:

https://github.com/boto/botocore/blob/ac9ce8eb9ab4296608c95c5d04461266925d90e2/botocore/data/apigateway/2015-07-09/service-2.json#L2337-L2350

Affected types include:

  • amazonka-apigateway: CacheClusterSize
  • amazonka-cloudhsm: ClientVersion
@endgame endgame changed the title amazonka-apigateway: CacheClusterSize enum has no patterns Support enum types with numeric values Jan 17, 2023
endgame added a commit to endgame/amazonka that referenced this issue Jan 17, 2023
Same output as brendanhay#862, but
sticks to `HashMap` internally to avoid triggering
https://github.com/brendanhay/amazonka/issue/888

A couple of enums change value in a strange way, because the generator
cannot handle enums-of-numeric values. See
brendanhay#889
@brendanhay
Copy link
Owner

Given both of the examples have floating point values - is the desired behaviour to just replace "." "_" to make a valid constructor/identifier? Or is some kind of floating point equivalent of {To,From}Enum a desired here?

@endgame
Copy link
Collaborator Author

endgame commented May 2, 2023

I think we should just do replace '.' '_' to begin with and look at doing something else if/when that proves insufficient. Are you thinking of PRing this for 2.0?

@brendanhay
Copy link
Owner

Yeah - considering if there’s any low hanging things that are breaking changes. I’ll take a look at this one today.

@endgame endgame added this to the 2.0 milestone May 2, 2023
@endgame endgame removed the post 2.0 label May 2, 2023
@endgame
Copy link
Collaborator Author

endgame commented May 17, 2023

Okay, I've looked into this and it's annoying enough and affecting few enough people that I want to kick it back to post-2.0:

  • When a ShapeF () is parsed out from JSON, it builds the Enum using a HashMap Id Text
  • To build that Id it calls mkId on the enum values from botocore
  • mkId formats the identifier using format = upperHead . Text.dropWhile (not . Char.isAlpha)
  • This makes these all-numeric enum values format to "", so they clobber each other in the HashMap
  • A proper fix would involve passing the type name around, but once we're inside the FromJSON (ShapeF ()) instance we don't know what type we're in (because shape names are stored as a JSON object)

I don't really want to keep piling hacks atop hacks in this version of the generator. In the medium term, I want to build an AST representation of the data as it is represented in botocore, parsed out using waargonaut. (Unlike aeson, waargonaut remembers the order of keys in JSON objects, which is important for things like correctly emitting field names in order). Once we have that AST, I want to build a new version of the generator which takes the simplest necessary service description and write an adapter function between them. This will mean that people using IAM authentication with API Gateway can generate their own amazonka-style APIs to access them; Amazon's own Selling Partner API (SP-API) is a prominent example.

@endgame endgame removed this from the 2.0 milestone May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants