Bird
0
0

You want to define a reusable error response in OpenAPI to use in multiple endpoints. Where should you define it and how do you reference it?

hard📝 Application Q8 of 15
Rest API - API Documentation
You want to define a reusable error response in OpenAPI to use in multiple endpoints. Where should you define it and how do you reference it?
ADefine under servers and reference with $ref: '#/servers/ErrorResponse'
BDefine under components/responses and reference with $ref: '#/components/responses/ErrorResponse'
CDefine under info and reference with $ref: '#/info/ErrorResponse'
DDefine under paths and reference with $ref: '#/paths/ErrorResponse'
Step-by-Step Solution
Solution:
  1. Step 1: Identify reusable components location

    Reusable responses are defined under components/responses in OpenAPI.
  2. Step 2: Understand referencing syntax

    References use $ref with the path #/components/responses/Name.
  3. Final Answer:

    Define under components/responses and reference with $ref: '#/components/responses/ErrorResponse' -> Option B
  4. Quick Check:

    Reusable responses live in components/responses [OK]
Quick Trick: Use components/responses for reusable error definitions [OK]
Common Mistakes:
MISTAKES
  • Defining reusable responses under paths
  • Referencing with wrong $ref paths
  • Placing reusable items in info or servers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes