Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property driven global headers #2364

Closed
mini-ninja-64 opened this issue Aug 29, 2023 · 3 comments
Closed

Property driven global headers #2364

mini-ninja-64 opened this issue Aug 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@mini-ninja-64
Copy link

Is your feature request related to a problem? Please describe.

When using springdoc-openapi I have found that sometimes it is necessary to define common headers for all endpoints. I am unaware of a simple way to configure these global headers in my OpenApi document.

Describe the solution you'd like

Ideally I would like a property driven approach where users can provide configuration of global headers which are automatically converted into OpenApi parameters and then referenced on all endpoints.

Describe alternatives you've considered

A solution to this exact problem is provided here, but this still requires users to manually apply a reference to the component on their API document, which could result in a lot of code duplication.

This can currently be solved by overriding the OpenApi bean or using an OpenApi customizer and creating global parameters which are automatically added to the OpenApi documents components section and then modifying all paths in the document to reference the global parameter $ref.

Additional context
I have experimented with implementing this using the following properties style and the method outlined above:

springdoc:
  common-headers:
    # Array of regex patterns used to exclude common 
    # headers from certain endpoints, they match on 
    # the paths documented by OpenApi.
    excluded-paths: []
    headers:
      - name: common-header
        example: header-value
        required: true      
        # Regex patterns to use for exclusions of this
        # particular common header, these are combined 
        # with those provided at the top level.
        excluded-paths: []

My main question comes down to would this be a feature springdoc would be willing to accept, if so I am happy to raise a PR for an implementation / discuss the concept further \(≧▽≦)/

cc: @Jack272Hughes @michaelmcfadyensky

@bnasslahsen bnasslahsen added the enhancement New feature or request label Oct 15, 2023
@bnasslahsen
Copy link
Contributor

@mini-ninja-64,

We are open to contributions, but this feature is not right now part of our priority list as there are other workarounds.
Feel free to propose a PR, if you feel it useful for the community.

@mini-ninja-64
Copy link
Author

@mini-ninja-64,

We are open to contributions, but this feature is not right now part of our priority list as there are other workarounds.
Feel free to propose a PR, if you feel it useful for the community.

Perfect, thank you, I will open a PR as proposed to add this feature!

@bnasslahsen
Copy link
Contributor

@mini-ninja-64,

You should be able to define extra spec properties based on this feature: #2418 that will be available for the next release.

Meanwhile don't hesitate to give it a try with the latest SNAPSHOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants