Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws-controllers-k8s/code-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.37.0
Choose a base ref
...
head repository: aws-controllers-k8s/code-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.38.0
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 14, 2024

  1. Add support for empty shapes, used as booleans in SDK (#536)

    Issue #, if available: prerequisite for WAFv2 [RuleGroup](aws-controllers-k8s/wafv2-controller#6) and [WebACL](aws-controllers-k8s/wafv2-controller#7) CRDs
    
    Description of changes:
    
    Some WAFv2 API fields have empty json specs `{}`, e.g. https://docs.aws.amazon.com/waf/latest/APIReference/API_AllQueryArguments.html
    
    For these type of fields, codegen currently errors out because it infers their gotypes as e.g. 
    `AllQueryArguments *AllQueryArguments`
    
    but does not generate a `type AllQueryArguments struct` since the struct itself is empty, and not picked up by `newFieldRecurse` function.
    
    The solution proposed in this PR is to allow users to define `marker-shapes`, which instruct codegen to overwrite the type of these empty structs as `[]byte`, both when generating the APIs and when setting up the SDK. 
    
    e.g. [generator.yaml](https://github.com/aws-controllers-k8s/wafv2-controller/blob/bb682409da8f96c5035783602b9d948c8cc8e21f/apis/v1alpha1/generator.yaml#L15-L24) for WAFv2, and inline:
    
    ```
    empty_shapes:
    - All
    - Method
    - UriPath
    - QueryString
    - AllQueryArguments
    - RateLimitIP
    - RateLimitForwardedIP
    - RateLimitHTTPMethod
    - NoneAction
    ```
    
    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
    TiberiuGC authored Aug 14, 2024
    Configuration menu
    Copy the full SHA
    bdf3f26 View commit details
    Browse the repository at this point in the history
  2. Support custom nested fields that have path that contains types other…

    … than struct (#538)
    
    Issue #, if available:
    
    Description of changes:
    
    Say we want to overwrite a nested field type e.g. for `WAFv2` controller (this is needed due to a cyclic dependency):
    ```
    resources:
      RuleGroup:
          Rules.Statement.AndStatement:
            type: string
    ```
    
    Currently, the [overwrite code logic](https://github.com/aws-controllers-k8s/code-generator/blob/62466746500d0c01fcfa8e8e3ca6abd9386e4687/pkg/model/crd.go#L660-L687) does not work for the above scenario and it returns the following error:
    ```
    Expected parent field to be of type structure, but found list
    ```
    
    This happens because `Rules` is not of type `struct`, but `[]struct`, and the referenced code logic requires that all fields within the path (i.e. `Rules` and `Statement` to be of type `struct`).
    
    This PR relaxes the logic to allow fields within the path to also be of types `[]struct` and `map[]struct`.
    
    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
    TiberiuGC authored Aug 14, 2024
    Configuration menu
    Copy the full SHA
    959eaa5 View commit details
    Browse the repository at this point in the history
Loading