Skip to content

Property driven global headers #2364

Closed
Closed
@mini-ninja-64

Description

@mini-ninja-64

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions