oscerd opened a new pull request, #28961: URL: https://github.com/apache/camel/pull/28961
Fixes [CAMEL-26249](https://issues.apache.org/jira/browse/CAMEL-26249), found while adding the catalog body types (CAMEL-24961). ## 1. pojoRequest=true ignored the operation **Was:** `GoogleCloudTextToSpeechProducer.process` went to `processPojo` whenever `pojoRequest` was true, and `processPojo` always called `synthesizeSpeech` with a `SynthesizeSpeechRequest` body. `listVoices?pojoRequest=true` with a `ListVoicesRequest` body failed with an `InvalidPayloadException`, and with a `SynthesizeSpeechRequest` body it synthesized. The `CamelGoogleCloudTextToSpeechOperation` header was not read either. **Now:** the producer resolves the operation first (header, then endpoint), and `pojoRequest` only chooses how the request is built. `listVoices` with `pojoRequest=true` sends the `ListVoicesRequest` of the body and gives the `List<Voice>`; another body (or no body) fails with an `InvalidPayloadException`. `synthesize` with `pojoRequest=true` works as before. ## 2. listVoices always filtered by languageCode **Was:** `languageCode` defaults to `en-US`, so the `!= null` check in `processListVoices` was always true and `listVoices` only ever listed the `en-US` voices. **Now:** `listVoices` filters by the language only when the `languageCode` option was set, on the endpoint or on the component configuration; without it the request has no language code and lists the voices of all languages. `synthesize` still uses `en-US` by default. The documented default of the option is unchanged: the configuration records whether `setLanguageCode` was called (a package-private `isLanguageCodeSet()`), so `languageCode=en-US` set explicitly still filters by `en-US`. The option description says the default applies to `synthesize` only. ## Tests - New `GoogleCloudTextToSpeechProducerTest` (10 tests) with a Mockito mock of `TextToSpeechClient`: listVoices with a `ListVoicesRequest`, with a `SynthesizeSpeechRequest` and with no body under `pojoRequest=true`; the operation header with `pojoRequest=true`; synthesize with `pojoRequest=true`; listVoices without `languageCode`, with `languageCode=fr-FR`, with `languageCode=en-US` set on the endpoint and with a language code set on the component; synthesize still sending `en-US`. - With the `src/main` changes reverted, 4 of the 10 new tests fail, each on an assertion that shows the old behaviour: the three pojo listVoices/header tests (an `InvalidPayloadException` asking for a `SynthesizeSpeechRequest`, or a synthesis instead of a failure) and listVoices without `languageCode` (the request had `en-US`). The 6 that pass are the no-body pojo case (it failed before too, asking for a `SynthesizeSpeechRequest`), pojo synthesize, the three explicit language code cases and synthesize with the default: they guard what must not change. - Module tests: 15 tests, 0 failures. ## Docs and generated files Component doc: the pojoRequest body per operation, a `ListVoicesRequest` example, what `listVoices` returns with and without `languageCode`, and the operation header name (it said `GoogleCloudTextToSpeechOperation`, the header is `CamelGoogleCloudTextToSpeechOperation`). `@BodyTypes`: the `pojoRequest=true` input no longer claims `SynthesizeSpeechRequest` for every operation, and the `pojoRequest=true` output entry (bytes) is removed, as the output follows the operation. The regenerated `google-text-to-speech.json` (body types and the `languageCode` description) and the doc are copied into the catalog, and the endpoint DSL javadoc of `languageCode` is regenerated. Upgrade guide entry: `listVoices` lists all voices unless `languageCode` is set, and `pojoRequest=true` follows the operation. ## Not changed - There is no header for the language code, so "set explicitly" means the endpoint or component option; with `pojoRequest=true` the `ListVoicesRequest` decides. Adding a header would be a new feature. - The alternative was to drop the documented default of `languageCode` (null, with `synthesize` falling back to `en-US`). That changes the catalog default and the getter, so the explicit-set flag was used instead. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
