serverless-java-container icon indicating copy to clipboard operation
serverless-java-container copied to clipboard

Add static factory methods to ApiGatewayRequestIdentity and AwsProxyRequestContext

Open dgomesbr opened this issue 6 months ago • 0 comments

Issue #, if available: issue #1495

Description of changes: This PR resolves issue #1495 by implementing static factory methods for both ApiGatewayRequestIdentity and AwsProxyRequestContext classes.

Implemented Changes

  1. Added getApiGatewayRequestIdentity() to ApiGatewayRequestIdentity class:

    • Creates an instance with realistic default values based on typical API Gateway requests
    • Sets appropriate values for all fields (including userAgent and sourceIp)
    • Null values for fields that typically don't have defaults
  2. Added getApiGatewayRequestIdentity(String sourceIp) to ApiGatewayRequestIdentity class:

    • Allows specifying a custom source IP while keeping other defaults
  3. Added getAwsProxyRequestContext() to AwsProxyRequestContext class:

    • Creates an instance with realistic default values from API Gateway
    • Sets appropriate values for all fields
    • Uses the default ApiGatewayRequestIdentity
  4. Added getAwsProxyRequestContext(String httpMethod) to AwsProxyRequestContext class:

    • Allows specifying a custom HTTP method while keeping other defaults

Benefits

  • Simplifies testing and priming implementations by providing easy-to-use factory methods
  • Reduces boilerplate code needed to set up these objects
  • Follows a similar approach to the one in reference implementation (AmazonAPIGatewayPrimingResource)

Questions for Maintainers

  1. Is the naming convention getAwsProxyRequestContext() and getApiGatewayRequestIdentity() preferred, or would you prefer a different naming pattern like builder() or of()?
  2. Are there specific default values for certain fields that you'd like to change?
  3. Would additional overloaded methods with different parameters be useful?

I've tested these changes locally and they work as expected.

By submitting this pull request

  • [x] I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • [x] I confirm that I've made a best effort attempt to update all relevant documentation.

dgomesbr avatar Jun 20 '25 14:06 dgomesbr