@David_M Thanks for the question. I took your question and passed it to the Kong Developer AI Assistant to see what it would recommend (Near the top of https://developer.konghq.com/) . I have pasted the response below. I’m not sure the answer is sufficient, as you want to use deck openapi2kong so I don’t believe you can control the generated routes to use capture groups as suggested. I wanted to provide the feedback here but I’ll also see if there is a better answer. Feel free to experiment with the AI Assistant and test the results, I hope it helps.
The core concept you may be missing is using regex capture groups in your route paths combined with the Request Transformer plugin’s replace.uri to rewrite the upstream path. This is a native Kong approach that requires no pre-function at all.
How it works
Instead of relying on a pre-function to strip the namespace prefix, you define your route paths with a named capture group for the “real” path, then use the Request Transformer plugin to set replace.uri to just the captured portion.
For example, for the /inf/security/users case:
Route path:
~/inf/security/(?<path>[^#?/]+.*)
Request Transformer plugin config:
config:
replace:
uri: /$(uri_captures['path'])
This rewrites /inf/security/users → /users upstream, with no pre-function involved. [dynamic path upstream] [route path transform]
About deck file namespace and pre-functions
The deck file namespace docs describe its prefix-removal logic in priority order:
-
If the Route has strip_path=true, the added prefix is already stripped — no pre-function needed.
-
If the Service has a path matching the prefix, the service path is updated.
-
Otherwise, a pre-function plugin is added to strip the prefix.
[namespace command]
Since openapi2kong generates regex routes ending in $ (e.g., ~/inf/security/users$), strip_path=true on a regex route will strip the entire matched path, not just the prefix — so you’d lose /users entirely. That’s why deck file namespace falls back to a pre-function in your case.
Recommended approach
Rather than using deck file namespace for path stripping, integrate the Request Transformer plugin into your deck file pipeline using deck file add-plugins after the openapi2kong step. Configure routes with capture groups and use replace.uri with $(uri_captures['path']) to reconstruct the upstream path. [rewrite path example]
This way your logging pre-function remains the only pre-function, and path rewriting is handled cleanly by the Request Transformer plugin.