Bird
0
0

You want to add a custom header parameter globally to all API operations in SpringDoc OpenAPI. Which approach is correct?

hard📝 Conceptual Q8 of 15
Spring Boot - API Documentation
You want to add a custom header parameter globally to all API operations in SpringDoc OpenAPI. Which approach is correct?
ACreate a custom OpenApiCustomiser bean that adds the header parameter
BAdd @RequestHeader annotation on every controller method
CSet the header parameter in application.properties
DUse @OpenAPIDefinition annotation with global headers attribute
Step-by-Step Solution
Solution:
  1. Step 1: Understand global customization options

    SpringDoc allows global API customization via OpenApiCustomiser beans.
  2. Step 2: Identify correct method to add header globally

    Implementing OpenApiCustomiser lets you add a header parameter to all operations programmatically.
  3. Step 3: Eliminate incorrect options

    Adding @RequestHeader everywhere is manual; properties file and @OpenAPIDefinition do not support global headers directly.
  4. Final Answer:

    Create a custom OpenApiCustomiser bean that adds the header parameter -> Option A
  5. Quick Check:

    Global header = OpenApiCustomiser bean [OK]
Quick Trick: Use OpenApiCustomiser bean for global headers [OK]
Common Mistakes:
  • Manually annotating every method
  • Expecting properties file to add headers
  • Misusing @OpenAPIDefinition for headers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes