-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix body optionality for contentType and request body setting #45528
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
Conversation
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances how request bodies and headers are handled by:
- Adding ISO_INSTANT formatting support for
OffsetDateTime
in query and header parameters - Only setting the
Content-Type
header when a non-null body is present and choosing serialization based on JSON vs. other types - Updating generated client templates and updating/removing legacy tests to reflect the new body‐optional behavior
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
sdk/clientcore/core/src/main/java/io/clientcore/core/utils/GeneratedCodeUtils.java | Added OffsetDateTime query‐parameter formatting support |
sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/RequestBodyHandler.java | Refactored configureRequestBody to honor body optionality and JSON |
sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/templating/JavaParserTemplateProcessor.java | Updated template logic for body header handling and skip content-type |
sdk/clientcore/annotation-processor/pom.xml | Lowered Jacoco coverage thresholds |
sdk/clientcore/annotation-processor/src/test/java/io/clientcore/annotation/processor/utils/RequestBodyHandlerTest.java | Removed outdated RequestBodyHandler tests |
sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/serializers/XmlSerializableTests.java | Tweaked XML tests to propagate new header logic |
sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/TestInterfaceServiceClientGenerationTests.java | Adjusted JSON body expectations (now quoted) |
sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/implementation/TestInterfaceClientServiceImpl.java | Regenerated client impls to only set Content-Type when body exists |
sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/implementation/SpecialReturnBodiesService.java | Added new rfc3339 and omit operations to service interface |
sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SpecialReturnBodiesServiceImpl.java | Implemented new rfc3339 and omit behaviors with ISO_INSTANT |
sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SimpleXmlSerializableServiceImpl.java | Moved XML header setup inside null check |
Comments suppressed due to low confidence (3)
sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/RequestBodyHandler.java:51
- [nitpick] The variable name
contentTypeParamParamOpt
is verbose and contains a repeated 'Param'. Consider renaming it tocontentTypeParamOpt
for clarity.
Optional<HttpRequestContext.MethodParameter> contentTypeParamParamOpt
sdk/clientcore/annotation-processor/src/test/java/io/clientcore/annotation/processor/utils/RequestBodyHandlerTest.java:1
- Removing the
RequestBodyHandlerTest
leaves new request-body logic untested. Add replacement tests to cover cases whereContent-Type
is only set when the body is non-null.
Entire test file removed
sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/RequestBodyHandler.java:247
- Switching to always JSON‐serialize non-null bodies introduces quoting for string payloads (including empty strings). This is a behavioral change—ensure it’s documented as a breaking change in release notes.
if (bodyContentType != null && bodyContentType.trim().equalsIgnoreCase(ContentType.APPLICATION_JSON)) {
...src/main/java/io/clientcore/annotation/processor/templating/JavaParserTemplateProcessor.java
Show resolved
Hide resolved
@@ -457,6 +441,10 @@ private void addHeadersToRequest(BlockStmt body, HttpRequestContext method) { | |||
// Start building the header addition for the HttpRequest. | |||
StringBuilder addHeader = new StringBuilder(); | |||
|
|||
String constantName = LOWERCASE_HEADER_TO_HTTPHEADENAME_CONSTANT.get(headerKey.toLowerCase(Locale.ROOT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo in the name - LOWERCASE_HEADER_TO_HTTPHEADERNAME_CONSTANT
@@ -457,6 +441,10 @@ private void addHeadersToRequest(BlockStmt body, HttpRequestContext method) { | |||
// Start building the header addition for the HttpRequest. | |||
StringBuilder addHeader = new StringBuilder(); | |||
|
|||
String constantName = LOWERCASE_HEADER_TO_HTTPHEADENAME_CONSTANT.get(headerKey.toLowerCase(Locale.ROOT)); | |||
if ("CONTENT_TYPE".equals(constantName)) { | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add a comment to specify why we are skipping content type header handling here.
Description