Enabling URL Rewrite through API Definition - Not working

Hi Team,

I’m trying to implement url rewrite capability through API definition but i’m getting following error.

apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
  name: url-rewrite
spec:
  name: URL Rewrite
  use_keyless: true
  protocol: http
  active: true
  proxy:
    target_url: http://httpbin.org
    listen_path: /url-rewrite
    strip_listen_path: true
  version_data:
    default_version: Default
    not_versioned: true
    versions:
      Default:
        name: Default
        use_extended_paths: true
        extended_paths:
          url_rewrites:
            # any request to the /get endpoint, will be re-written to /xml
            - path: /get
              match_pattern: /get
              method: GET
              rewrite_to: /xml

[email protected]% kubectl apply -f URLRewrite-Ingress.yaml -n
The ApiDefinition “url-rewrite” is invalid: spec.version_data.versions.Default.extended_paths.url_rewrites.triggers: Required value

When i verified the CRD, triggers is not a mandatory object.

Even i tried to define the triggers as well but still no luck.

apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
  name: url-rewrite
spec:
  name: URL Rewrite
  use_keyless: true
  protocol: http
  active: true
  proxy:
    target_url: http://httpbin.org
    listen_path: /url-rewrite
    strip_listen_path: true
  version_data:
    default_version: Default
    not_versioned: true
    versions:
      Default:
        name: Default
        use_extended_paths: true
        extended_paths:
          url_rewrites:
            # any request to the /get endpoint, will be re-written to /xml
            - path: /get
              match_pattern: /get
              method: GET
              rewrite_to: /xml
              triggers:
                - "on": "any"
                  options:
                    path_part_matches:
                      "/get":
                        match_rx: "/get"
                  rewrite_to: /xml

When i execute the definition getting following error,

The ApiDefinition “url-rewrite” is invalid:
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.path_part_matches./get.reverse: Required value
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.header_matches: Required value
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.payload_matches: Required value
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.query_val_matches: Required value
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.request_context_matches: Required value
spec.version_data.versions.Default.extended_paths.url_rewrites.triggers.options.session_meta_matches: Required value

I believe i’m missing something. I was referring to tyk-operator/dynamic_auth.yaml at master · TykTechnologies/tyk-operator · GitHub

Team,
Is triggers is mandatory element to be passed?

Hello - this should help you: tyk-operator/url_rewrite_basic.yaml at master · TykTechnologies/tyk-operator · GitHub

apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
  name: url-rewrite
spec:
  name: URL Rewrite
  use_keyless: true
  protocol: http
  active: true
  proxy:
    target_url: http://httpbin.org
    listen_path: /url-rewrite
    strip_listen_path: true
  version_data:
    default_version: Default
    not_versioned: true
    versions:
      Default:
        name: Default
        use_extended_paths: true
        paths:
          black_list: [ ]
          ignored: [ ]
          white_list: [ ]
        extended_paths:
          url_rewrites:
            # any request to the /get endpoint, will be re-written to /xml
            - path: /get
              match_pattern: /get
              method: GET
              rewrite_to: /xml
              triggers: []
1 Like