question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Default responses for all endpoints

See original GitHub issue

I suggest that we add “default responses” that can be defined as default response for All endpoints. This would avoid copy-paste for some common responses like:

429 Too Many Requests 405 Method Not Allowed

The format could be

produces:
  - application/json
responses:
  '429':
    description: to many requests in the given timeframe
    schema:
      $ref: '#/definitions/error'
paths:
...

Or if flexibility is required, we could alter the default response keyword to take a list of responsedefinitions. This could benefit with the response code range proposal (https://github.com/swagger-api/swagger-spec/issues/516).

responseDefinitions:
 "success":
    description: request successful
    code: 200
  "request limit":
    description: to many requests in the given timeframe
    code: 429, 419
    schema:
      $ref: '#/definitions/error'
  "server error":
    description: server error
    code: 500 - 599
    schema:
      $ref: '#/definitions/error'

paths
  test:
    get:
      responses:
        default:
         - "success"
         - "request limit"
         - "server error"

this would require some changes to the default response keyword.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:165
  • Comments:42 (7 by maintainers)

github_iconTop GitHub Comments

43reactions
MikeRalphsoncommented, Oct 21, 2020

I’m currently looking at the possible need to add a default / override for the JSON Schema, $schema $vocabulary etc keywords in OAS 3.1

A design question comes up between simplicity and extensibility of this “default” feature.

Would something like:

openapi: 3.1.0
info:
  title: API
  version: 1.0.0
defaults:
  responses:
    '405':
     description: Method not allowed
     schema:
       $ref: '#/components/responses/error'
    '429':
      description: Too many requests
      schema:
        $ref: '#/components/responses/error'
      headers:
       ....

address the requirements for people in this issue? Bearing in mind @darrelmiller’s very good advice in this tweet.

20reactions
saturovcommented, Jan 16, 2020

+1 dream about this feature

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a default 200 response to all API paths - GSoC - Postman
A default response is a response returned for cases not covered for a particular API path. You need to put yourself in the...
Read more >
Describing Responses - Swagger
Describing Responses. An API specification needs to specify the responses for all API operations. Each operation must have at least one response defined, ......
Read more >
Gateway responses in API Gateway - AWS Documentation
Setting up gateway responses to customize error responses​​ By default, the error response contains a short descriptive error message. For example, if you ......
Read more >
Stripe API reference – curl
By default, the Stripe API Docs demonstrate using curl to interact with the API ... Stripe uses conventional HTTP response codes to indicate...
Read more >
java - Rest api, adding another MediaType, default response
May that cause some problems with user apps that are using this endpoint? For example when they are not specyfing header with response...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found