fix(generator): fall back to java.lang.Object for unknown types.#31517
fix(generator): fall back to java.lang.Object for unknown types.#31517diegomarquezp wants to merge 5 commits intomainfrom
Conversation
|
fix demo for |
|
There seem to be removed methods, is that expected? |
| # return result | ||
| # | ||
| # raise ValueError('Unknown type: %s format: %s' % (json_type, json_format)) | ||
| # Fallback to the unformatted base type if exact format mapping is not found. |
There was a problem hiding this comment.
I see that the generated code changed from
private java.util.Map<String, Any> entries;
to
private java.util.Map<String, java.lang.Object> entries;
Is it possible to test it in a real client?
There was a problem hiding this comment.
I added a Main class to the demo PR #31516
The description now explains that we could compile and fetch a StructuredEntities object.
Edit: googleapis/discovery-artifact-manager@3910620 contains the change from March 25. My local clone of |
|
I see that there are a lot of type changes in the demo PR from |
I added a special case to process result = self.type_map.get((json_type, None))
if result and json_type != 'string':
return resultWhen it comes to the demos, I fixed the discovery revision problem and we now only have cloudbuild (no changes) and compute. |
Fixes #31266
Background
When compiling specific alpha/beta generated model endpoints (e.g.,
StructuredEntriesingoogle-api-services-compute), the Java compiler crashes on:This happens because the property
"entries"uses a schema format that the current Java generator does not explicitly handle, defined in the upstream discovery document here:discoveries/compute.alpha.json
Since
('any', 'google.protobuf.Value')has no dedicated mapping, the code generation fell through to the default class transformation logic.Faulty snippet in
java_generator.py:This resulted in the pseudo-class reference
Any.Changes Proposed
JavaLanguageModel._GetTypeInfoso that any unmapped(type, format)signature automatically strips the format requirement and probes the base(type, None)type list instead.google.protobuf.Value) to standard mappings (likejava.lang.Object), avoiding unintended transitive dependencies on externalprotobuf-javalibraries.Testing & Impact Verification
v1/2.0.0libraries to check for unintended regressions.