saravanakumar1987 opened a new pull request, #30257:
URL: https://github.com/apache/camel/pull/30257

   # Description
   
   Fixes [CAMEL-27036](https://issues.apache.org/jira/browse/CAMEL-27036), the 
follow-up of the review of apache/camel#30144.
   
   ## What was wrong
   
   - `SMSEndpoint` marked `region` as required, but either the region or the 
endpoint is enough to create the client. `SMSUtils.createClient` throws `Region 
or endpoint is required` only when both are empty. The client of 
`com.aliyun:dysmsapi20170525` 4.6.0 uses the endpoint when it is set. Otherwise 
it takes the endpoint of the region from its endpoint map, and for a region 
that is not in the map, `dysmsapi.aliyuncs.com` from its endpoint rule 
`central`. So neither of the two options can be marked as required.
   - So the endpoint validation of the catalog reported a URI with an endpoint 
and without a region as missing the required option `region`.
   - The producer reads the header `CamelAlibabaSmsOperation` like the other 
input headers, but `SMSHeaders` had no constant for it. Only `SMSProperties` 
declared it, and the build reads only the headers class, so the header was 
missing from the header list of the component JSON, the Endpoint DSL and the 
doc page.
   - `SMSProperties` had `@Metadata` with texts of its own on its seven names. 
The build did not read them, and they differed from the texts in `SMSHeaders`.
   
   ## The change
   
   - `region` no longer has `@Metadata(required = true)`, and `endpoint` stays 
without it, as in camel-alibaba-sls, whose `createClient` has the same check.
   - `SMSHeaders` has `OPERATION` as its first constant, defined like the other 
constants of the class as `SMSProperties.OPERATION`, with the text of 
`AlibabaOtsHeaders.OPERATION`: "The operation that the producer performs. This 
header replaces the operation option. If this header is not set, an exchange 
property of the same name replaces the operation option." The producer resolves 
the operation in this order, with `OpenApiClientSupport.resolveString`: the 
header, then the exchange property, then the option.
   - `SMSProperties` keeps its seven constants, without the `@Metadata` 
annotations and their import.
   - The component JSON and its catalog copy have `region` as not required, and 
the header `CamelAlibabaSmsOperation`. The other headers and options keep their 
texts. In the Endpoint DSL, the Javadoc of `region(String)` no longer says 
"Required: true", and the header name builder has the new method 
`alibabaSmsOperation()`.
   - The doc page does not change. It has no sentence or hand-written table 
about the region, the operation header or the constant classes, and its 
examples set a region, which is enough.
   
   There is no upgrade-guide entry, because no route changes: the producer and 
`createClient` do not change. No option, header name or Java API is removed or 
renamed: `SMSProperties` keeps its constants, and the Endpoint DSL only gains a 
method. What changes is the metadata that tooling reads: the endpoint 
validation of the catalog now accepts a URI with an endpoint and without a 
region, and the header list of the component has one more header. The catalog 
cannot express that one of the two options is required, so it now also accepts 
a URI with neither. When Camel creates the client from the options, such a URI 
still fails at the first message with `Region or endpoint is required`.
   
   ## Tests
   
   - `CamelCatalogTest#testValidateEndpointAlibabaSms` comes directly after 
`testValidateEndpointJmsDefault`, in the style of the catalog test of 
apache/camel#30254 for camel-alibaba-eventbridge. A URI with `endpoint` and 
without `region` validates with success. A URI with `region` and without 
`endpoint` validates with success too. The header list of the component has 
`CamelAlibabaSmsOperation`.
   - There is no new test in the module, because the change is metadata only: 
`createClient` and the producer do not change, and the catalog test checks the 
metadata.
   
   ## How it was verified
   
   - With the new test and without the change, `testValidateEndpointAlibabaSms` 
failed at its first assertion: the catalog reported `region` as a missing 
required option.
   - Without the change, a small Java program that called 
`validateEndpointProperties` and `componentModel` on the catalog showed that 
the catalog accepted the URI with a region and without an endpoint, and that 
the header list of the component had six headers, without 
`CamelAlibabaSmsOperation`.
   - With the change, `mvn install -nsu` in the module ran the 2 tests of the 
module with no failure, error or rerun, and changed only the component JSON 
among the generated files. In that JSON, the six headers that were there before 
kept their texts, so the removed annotations of `SMSProperties` had no effect 
on it.
   - With the change, `mvn install -DskipTests -nsu` in `catalog/camel-catalog` 
regenerated the catalog copy of the component JSON, and in 
`dsl/camel-endpointdsl` it regenerated `SMSEndpointBuilderFactory`.
   - With the change and the regenerated files, the new test passes.
   
   ## Not changed
   
   - `endpoint` stays without `@Metadata(required = true)`. Its description 
already says that, if it is not set, the region option determines the endpoint, 
and that one of the two is required.
   - `SMSUtils` still reads the header names through the constants of 
`SMSProperties`, which have the same values.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -Dquickly -DskipTests` from the root 
folder on upstream `main` (8e904a3bb0f7, the parent of this commit), and then, 
with the change, `mvn install -nsu` in 
`components/camel-alibaba/camel-alibaba-sms`, which also runs its code 
generators, the formatter and the import sorter, and `mvn install -DskipTests 
-nsu` in `catalog/camel-catalog` and in `dsl/camel-endpointdsl`. I have 
committed all auto-generated changes: the component JSON, its catalog copy and 
`SMSEndpointBuilderFactory`.
   
   The commands that were run:
   
   ```
   # without the change, with the new test, in catalog/camel-catalog
   mvn -o -B test -Dtest=CamelCatalogTest#testValidateEndpointAlibabaSms 
-Dsurefire.failIfNoSpecifiedTests=false -Dsurefire.rerunFailingTestsCount=0
   # with the change, in components/camel-alibaba/camel-alibaba-sms
   mvn install -nsu
   # then in catalog/camel-catalog and in dsl/camel-endpointdsl
   mvn install -DskipTests -nsu
   # then the test command again, in catalog/camel-catalog
   ```
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   The change, the test and this text were drafted with Claude Code 
(Anthropic), from the ticket, the code of camel-alibaba-sms, camel-alibaba-ots, 
camel-catalog and the Endpoint DSL, the sources of 
`com.aliyun:dysmsapi20170525` 4.6.0 and `com.aliyun:tea-openapi` 0.3.20, and 
the bytecode of `com.aliyun:endpoint-util` 0.0.8. The test was run as described 
above. The change and the claims of this text were checked by an independent AI 
review.
   
   _Claude Code on behalf of saravanakumar1987_
   
   🤖 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]

Reply via email to