Skip to content

Feat: support adding headers from oas in o2k#277

Merged
harshadixit12 merged 2 commits intomainfrom
feat/support-adding-headers-from-oas-in-o2k
Sep 23, 2025
Merged

Feat: support adding headers from oas in o2k#277
harshadixit12 merged 2 commits intomainfrom
feat/support-adding-headers-from-oas-in-o2k

Conversation

@harshadixit12
Copy link
Contributor

@harshadixit12 harshadixit12 commented Sep 9, 2025

Summary:
If users have declared header parameters, and their values (in an enum) in the OAS - we will be including those in the generated routes.

Note - some decisions that need attention:

  • Headers are technically an array in kong route config - but based on header parameter and their enum in OAS, we can't determine if they intend to accept > 1 value in their kong route config per header. So, we will only create route header with a single value
  • default in OAS meant to be assumed by the server when a value is not provided (source) - a incoming HTTP request may or may not contain a value for a header. For now, wherever enum is defined for a header param in OAS, we are creating kong routes with headers, but none without headers.

Implements: Kong/deck#1702
Related conversation: https://kongstrong.slack.com/archives/C07AQH7SAF8/p1756099922036849

@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@a351d17). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #277   +/-   ##
=======================================
  Coverage        ?   70.26%           
=======================================
  Files           ?       24           
  Lines           ?     3541           
  Branches        ?        0           
=======================================
  Hits            ?     2488           
  Misses          ?      874           
  Partials        ?      179           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@harshadixit12 harshadixit12 force-pushed the feat/support-adding-headers-from-oas-in-o2k branch from 9c43d59 to 07f34fd Compare September 9, 2025 11:02
@harshadixit12 harshadixit12 marked this pull request as ready for review September 18, 2025 05:22

// Returns header parameters which can be used for routing for an operation
func findHeaderParamsForRouting(
operationLevelParameters []*v3.Parameter,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Prashansa-K I need some input here - do you think it's better if we also expect required: true for the headers we include in the route in kong config based on the enum values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have that restriction with other types (like in: path). We should follow the same here.
Any specific reason you feel that required: true would be useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In path, it is implied that the parameters are required
Headers parameters are optional.
On second thought, since we are generating routes with headers in criteria, those would only match when in the incoming request to gateway, header has a value and the value matches criteria - so it's not necessary for us to only consider required headers.

@Prashansa-K
Copy link
Contributor

Prashansa-K commented Sep 18, 2025

In this PR, we are only dealing with "enums". Other types like oneOf, anyOf, allOf, etc. are not dealt here. Are those not in scope of the task?

@harshadixit12
Copy link
Contributor Author

harshadixit12 commented Sep 18, 2025

In this PR, we are only dealing with "enums". Other types like oneOf, anyOf, allOf, etc. are not dealt here. Are those not in scope of the task? You mean oneOf inside parameter.schema?
This was a miss from me, let me check.

@harshadixit12
Copy link
Contributor Author

In this PR, we are only dealing with "enums". Other types like oneOf, anyOf, allOf, etc. are not dealt here. Are those not in scope of the task?

@Prashansa-K while the OAS technically allows allOf and oneOf in header schema, using it is not very common - and also deep nesting is generally discouraged. Supporting it would need us to recursively go through the schema, and identify possible values of the header - which would be high complexity + low ROI IMO
(we don't do this for path parameters either as of now)

We can consider it in future - what do you think?

@Prashansa-K
Copy link
Contributor

We can consider it in future - what do you think?

Sounds good. I was just ensuring the scope of the work. We can get back to the other types when the need arises.

@harshadixit12 harshadixit12 merged commit 64b7bc4 into main Sep 23, 2025
7 checks passed
@harshadixit12 harshadixit12 deleted the feat/support-adding-headers-from-oas-in-o2k branch September 23, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants