generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 23
feat: [OpenAPI] ResponseMetadataListener with case insensitive header map
#1070
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
Open
rpanackal
wants to merge
88
commits into
main
Choose a base branch
from
feat/openapi/response-status-and-header
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
88 commits
Select commit
Hold shift + click to select a range
888bc4d
Move resttemplate moustache into dedicated folder
rpanackal 3473fff
Revert "Move resttemplate moustache into dedicated folder"
rpanackal 7991ce9
Add apache-httpclient/api.moustache
rpanackal 6638e7a
openapi apache sample
rpanackal c08ceb6
remove ``@Generated`
rpanackal a697b6e
Add apache-client common generated classes and dependency
rpanackal 28e8135
dependency and formatting
rpanackal c3e438f
Add all required file (pruned later)
rpanackal c934b1f
Fix dependencies
rpanackal ea0eeb6
Simply api-apache-sample
rpanackal b81f4c2
Merge branch 'main' into feat/openapi/optional-spring-base
rpanackal 50a57bb
Fix version issue
rpanackal 6a33cf6
Pom config and exclusions
rpanackal cde369f
Set format skip false for sample module
rpanackal 7aed42d
regenerate with prompt-registry.yaml
rpanackal d4747ad
regenerate with prompt-registry.yaml
rpanackal 03933a0
Remove ServerVariable.java and ServerConfiguration.java files
rpanackal 27cc015
NoArgs ctor preserved but remove Configuration
rpanackal 112360d
Remove apache specific date classes addition. Reuse existing class in…
rpanackal a9e609b
Pair - Simplify and improve code quality
rpanackal 2f684c6
Remove `Authentication` classes and `authNames` from `ApiClient.invok…
rpanackal aa60080
make unimported methods private and use ApacheHttpClient5Accessor
rpanackal 73ffecc
Remove invokeAPI methods in BaseApi and *Api.java
rpanackal f4358bc
Refactoring ApiClient
rpanackal 3ce5400
Refactoring ApiClient
rpanackal ad8a738
Fix dependency and warning
rpanackal d8add74
Remove method overloading per operation with additionalHeaders
rpanackal 0c0176c
Extract response handling out of ApiClient into ApiClientResponseHandler
rpanackal db04109
Make static ApiClient ctors
rpanackal ffada46
Remove ApiException and use enhanced OpenApiRequestException
rpanackal cd26cf8
Borrow sample module handling
rpanackal 8357f5f
Apache mustache parity
rpanackal 4d5b97b
Apache mustache parity
rpanackal e1390af
Apache mustache parity and object mapper config
rpanackal 97c5e03
Revert to sodastore generation in sample
rpanackal 59fedb1
Add apache/OpenApiResponse instead of void returns
rpanackal c5cba53
Remove guava dependency
rpanackal e6ec8b9
Update apache pom for general and generator configuration
rpanackal f16b2c9
Generate and test sodastore and petstore
rpanackal 1b4ffcb
Merge remote-tracking branch 'origin/main' into feat/openapi/refactor…
rpanackal c56376c
Merge branch 'feat/openapi/refactor-apache-templates' into feat/opena…
rpanackal 0773674
Extending existing integration test
rpanackal 943de3c
Complete and cleanup integration test
rpanackal cc08bfb
Make url building more forgiving
rpanackal bdc8c72
Almost @Value class but not final
rpanackal 3387432
Remove as much unnecessary integration test files
rpanackal 64c7bdd
Add unit testing for Apache components
rpanackal 8257a9a
Add unit testing for Apache components
rpanackal 45e4dbc
Merge remote-tracking branch 'origin/feat/openapi/test-apache-client-…
rpanackal 41ef22f
Add unit test for query params, client factory config and objectmappe…
rpanackal 50a0e0f
Merge branch 'main' into feat/openapi/optional-spring-base
rpanackal eb21453
Borrow downstream PR changes
rpanackal acff1d1
Merge branch 'feat/openapi/optional-spring-base' into feat/openapi/re…
rpanackal 9f00a54
Merge branch 'feat/openapi/refactor-apache-templates' into feat/opena…
rpanackal 1c0bef8
refactor: [OpenAPI] Part 1: Refactor Apache related files and templat…
rpanackal 84b4e9e
Merge branch 'main' into feat/openapi/optional-spring-base
rpanackal f02fd1d
Fix CI/CD
rpanackal cefb244
checkstyle
rpanackal 1632d2c
pmd
rpanackal 1e00604
pmd
rpanackal 31d8620
Merge branch 'feat/openapi/optional-spring-base' into feat/openapi/re…
rpanackal 0a71d8e
Merging
rpanackal 119dd09
Merge branch 'feat/openapi/refactor-apache-templates' into feat/opena…
rpanackal a84b2ca
Merging
rpanackal 476fef7
Fix serialization of null and
rpanackal 5884d6e
fix byte[] test and pmd
rpanackal 5f61ebf
fix oneOf serialization test
rpanackal 4835a34
Update datamodel/openapi/openapi-generator/src/main/resources/openapi…
rpanackal de76c72
Review: Apache Method enum and ctor formatting
rpanackal 067ddc8
Merge remote-tracking branch 'origin/feat/openapi/optional-spring-bas…
rpanackal de01665
Update datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk…
rpanackal b7d623e
Fix compliance issue and formatting
rpanackal 16f26ab
Merge branch 'feat/openapi/optional-spring-base' into feat/openapi/te…
rpanackal 1226e6f
Make return statement always present
rpanackal 4cf87b9
Merge branch 'feat/openapi/optional-spring-base' into feat/openapi/te…
rpanackal d8bc954
Reeview changes
rpanackal f1216a9
Case-insensitive header key match
rpanackal d8a945e
minor changes in mustache files
rpanackal 859a8f1
feat: [OpenAPI] Part 2: Testing Apache Client Support and some fixes.…
rpanackal f05242f
Fix missed line on merge
rpanackal c6483a2
Merge branch 'feat/openapi/optional-spring-base' into feat/openapi/re…
rpanackal 27c7843
Add response metadata listener
rpanackal 587e038
Test metadata listener and header lookup
rpanackal 49a1081
Merge branch 'main' into feat/openapi/response-status-and-header
rpanackal 3c7ee80
Add missing javadoc
rpanackal b75ed48
Add missing javadoc
rpanackal b94ace5
Rename to OpenApiResponseListener
rpanackal aa1f126
Rename to OpenApiResponseListener
rpanackal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,25 +6,18 @@ | |
| import javax.annotation.Nonnull; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| /** | ||
| * Response object for Apache HTTP client OpenAPI calls containing status code and headers | ||
| */ | ||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class OpenApiResponse | ||
| { | ||
|
|
||
| private final int statusCode; | ||
|
|
||
| @Nonnull | ||
| private final Map<String, List<String>> headers; | ||
|
|
||
| /** | ||
| * Create a new OpenApiResponse with status code and headers. | ||
| */ | ||
| OpenApiResponse( final int statusCode, @Nonnull final Map<String, List<String>> headers ) | ||
| { | ||
| this.statusCode = statusCode; | ||
| this.headers = Map.copyOf(headers); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
...core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/OpenApiResponseListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.sap.cloud.sdk.services.openapi.apache; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Listener for receiving metadata about HTTP responses. | ||
| * | ||
| * @since 5.25.0 | ||
| */ | ||
| @FunctionalInterface | ||
| public interface OpenApiResponseListener | ||
| { | ||
| /** | ||
| * Called when an HTTP response is received. | ||
| * | ||
| * @param response | ||
| * The response metadata. | ||
| */ | ||
| void onResponse( @Nonnull final OpenApiResponse response ); | ||
| } |
145 changes: 145 additions & 0 deletions
145
...ava/com/sap/cloud/sdk/services/openapi/apiclient/ApacheApiClientResponseHandlingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package com.sap.cloud.sdk.services.openapi.apiclient; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.verify; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
| import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
| import com.sap.cloud.sdk.services.openapi.apache.ApiClient; | ||
| import com.sap.cloud.sdk.services.openapi.apache.BaseApi; | ||
| import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; | ||
| import com.sap.cloud.sdk.services.openapi.apache.Pair; | ||
| import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @WireMockTest | ||
| class ApacheApiClientResponseHandlingTest | ||
| { | ||
| private static final String TEST_PATH = "/test"; | ||
| private static final String TEST_RESPONSE_BODY = "{\"message\": \"success\"}"; | ||
|
|
||
| @Test | ||
| void testResponseMetadataListener( final WireMockRuntimeInfo wmInfo ) | ||
| { | ||
| stubFor( | ||
| get(urlEqualTo(TEST_PATH)) | ||
| .willReturn( | ||
| aResponse() | ||
| .withStatus(200) | ||
| .withHeader("x-custom-header", "some-value") | ||
| .withBody(TEST_RESPONSE_BODY))); | ||
|
|
||
| final AtomicReference<OpenApiResponse> metadata = new AtomicReference<>(); | ||
| final ApiClient apiClient = | ||
| ApiClient.create().withBasePath(wmInfo.getHttpBaseUrl()).withOpenApiResponseListener(metadata::set); | ||
|
|
||
| final TestApi api = new TestApi(apiClient); | ||
| final TestResponse result = api.executeRequest(); | ||
|
|
||
| assertThat(result).isNotNull(); | ||
| assertThat(result.getMessage()).isEqualTo("success"); | ||
| assertThat(metadata.get()).isNotNull(); | ||
| assertThat(metadata.get().getStatusCode()).isEqualTo(200); | ||
| assertThat(metadata.get().getHeaders()).isNotEmpty(); | ||
| assertThat(metadata.get().getHeaders()).containsKey("x-custom-header"); | ||
|
|
||
| verify(1, getRequestedFor(urlEqualTo(TEST_PATH))); | ||
| } | ||
|
|
||
| @Test | ||
| void testCaseInsensitiveHeaderLookup( final WireMockRuntimeInfo wmInfo ) | ||
| { | ||
| stubFor( | ||
| get(urlEqualTo(TEST_PATH)) | ||
| .willReturn( | ||
| aResponse() | ||
| .withStatus(200) | ||
| .withBody(TEST_RESPONSE_BODY) | ||
| .withHeader("x-custom-header", "some-value"))); | ||
|
|
||
| final AtomicReference<OpenApiResponse> capturedResponse = new AtomicReference<>(); | ||
| final ApiClient apiClient = | ||
| ApiClient.create().withBasePath(wmInfo.getHttpBaseUrl()).withOpenApiResponseListener(capturedResponse::set); | ||
|
|
||
| final TestApi api = new TestApi(apiClient); | ||
| api.executeRequest(); | ||
|
|
||
| // Verify case-insensitive access works | ||
| final Map<String, List<String>> headers = capturedResponse.get().getHeaders(); | ||
| assertThat(headers.get("x-custom-header")).contains("some-value"); | ||
| assertThat(headers.get("X-Custom-Header")).contains("some-value"); | ||
| assertThat(headers.get("X-CUSTOM-HEADER")).contains("some-value"); | ||
| } | ||
|
|
||
| private static class TestApi extends BaseApi | ||
| { | ||
| private final String path; | ||
|
|
||
| TestApi( final ApiClient apiClient ) | ||
| { | ||
| this(apiClient, TEST_PATH); | ||
| } | ||
|
|
||
| TestApi( final ApiClient apiClient, final String path ) | ||
| { | ||
| super(apiClient); | ||
| this.path = path; | ||
| } | ||
|
|
||
| TestResponse executeRequest() | ||
| throws OpenApiRequestException | ||
| { | ||
| final List<Pair> localVarQueryParams = new ArrayList<>(); | ||
| final List<Pair> localVarCollectionQueryParams = new ArrayList<>(); | ||
| final Map<String, String> localVarHeaderParams = new HashMap<>(); | ||
| final Map<String, Object> localVarFormParams = new HashMap<>(); | ||
|
|
||
| final String[] localVarAccepts = { "application/json" }; | ||
| final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); | ||
|
|
||
| final String[] localVarContentTypes = {}; | ||
| final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); | ||
|
|
||
| final TypeReference<TestResponse> localVarReturnType = new TypeReference<TestResponse>() | ||
| { | ||
| }; | ||
|
|
||
| return apiClient | ||
| .invokeAPI( | ||
| path, | ||
| "GET", | ||
| localVarQueryParams, | ||
| localVarCollectionQueryParams, | ||
| null, | ||
| null, | ||
| localVarHeaderParams, | ||
| localVarFormParams, | ||
| localVarAccept, | ||
| localVarContentType, | ||
| localVarReturnType); | ||
| } | ||
| } | ||
|
|
||
| @Data | ||
| private static class TestResponse | ||
| { | ||
| @JsonProperty( "message" ) | ||
| private String message; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
(Minor)
Could we add the
@Betaannotation here?While I'm okay with current state, I feel like having options in the future would be nice:
withResponseListener