Closed AlistairB closed 3 years ago
Hi there!
So, I wanted to regenerate things to use a new features of the API, and I stumbled on the same problem as you (which I re-fixed, instead of checking your changes first). I also have figured out this last problem, which sadly doesn't have one straightforward solution.
One of job of the generator is to create types for each type in the API, and lenses for each field. Since different type have fields with the same names, it's necessary to disambiguate the lenses. Here, we do this by adding a prefix based on the type.
This is what the getPrefix
function does. For that, it calls acronymPrefixes
to get a bunch candidates (we try out a lot of different prefixes). Then, we pick one acronym that isn't already used for these fields.
So, gogol makes a api wrapper that works for every single version of the api. Sadly, it looks like google went over-the-top with the versioning for some of these api. For this problematic one, videointelligence
, we have: v1, v1beta2, v1p1beta, v1p2beta1 and v1p3beta1. Multiple of these have variant of DetectedLandmark
, called something like GoogleCloudVideointelligenceV1p1beta1_DetectedLandmark
.
So when we get to GoogleCloudVideointelligenceV1p1beta1_DetectedLandmark
, we probably have already picked prefixed for a few other DetectedLandmark
. So none of the tentative prefixes generated by acronymPrefixes
works. And we fail.
V1p1beta1
) in the prefix.HasName
with a lens name
). Or any other solution to "the record problem" (which is widely documented).Thanks @madjar for the awesome analysis on the videointelligence issue! :heart:
I think your solution is perfect as a quick fix.
I'm not sure if it is the right end game solution, but it is better than exploding as it does now and it doesn't introduce any breakage.
Agree this is tricky. Versions do appear to be deprecated officially ie. https://cloud.google.com/video-intelligence/docs/reference/rest , so perhaps such versions can be dropped from support. I believe v1
is the only version officially supported for videointelligence
Perhaps @brendanhay has plans around this for gogol v2.
Regardless, I think the short term fix is good and essentially a bug fix to the current design. I would create a separate issue for a redesign and prioritize it against other improvements.
Anyway, @brendanhay I think is ready for review.
Thanks @madjar and @AlistairB!
Longer term (v2) I'll probably just supply the Generic
instances and use DuplicateRecordFields
- directing users of the libraries to generic-{lens,optics}
or RecordDotSyntax
when it becomes available. This would "fix" most of the the fields' issues, with all datatypes/constructors being prefixed by version in a consistent fashion.
Regarding:
Finally, we could decide to drop some of the versions (though I don't know how we would choose).
I think we'd probably just keep anything stable with no prerelease suffix, such as v1
, v2
, etc. and then order any bleeding edge versions and take only the "newest".
For example the available versions [v1, v1beta2, v1p1beta, v1p2beta1, v1p3beta1, v2, v2alpha1, v2alpha3]
would only result in [v1, v1beta2, v2, v2alpha3]
being considered as inputs for generation.
Awesome! Thanks folks!
I was looking quickly generic lenses and optics, and at RecordDotSyntax
to see if there is a quick way to implement it as of now. It would probably be possible to expose the proper typeclass instances to expose lenses and fields, but probably not in a way that works for all approaches without depending on them all. For that, having records that have their actual name, and Generic
, will be the way to go.
As a side note, I think RecordDotSyntax
will not be enough: given the amount of _Just
lenses I had to sprinkle over my read path, lenses are going to be needed.
Hi,
I've fixed a couple of issues in the 2 commits so far. I'm mostly cargo culting the fixes so it could be the wrong solution, but it seems to make it pass.
The next issue I don't know how to fix:
Any ideas?