koa-swagger-decorator icon indicating copy to clipboard operation
koa-swagger-decorator copied to clipboard

Add support for "default" response

Open sidec15 opened this issue 3 years ago • 1 comments

Currently is not possible to define a default response block because the "response" decorator accepts an argument with type IResponses:

export interface IResponses {
  [name: number]: any;
}

So is not possible to assign a string as key.

The desiderata woud be to allow the following:

@responses({
	200: { description: "success",
	"default": {description: "default error"}
})

The resulting json must have the following structure:

responses:
	200:
	  description: Success
	  schema:
		$ref: '#/definitions/User'
	# Definition of all error statuses
	default:
	  description: Unexpected error
	  schema:
		$ref: '#/definitions/Error'

sidec15 avatar May 19 '21 08:05 sidec15

A possible workaround could be:

const DEFAULT_ERROR_KEY: number = "default" as unknown as number

@responses({
	200: { description: "success",
	[DEFAULT_ERROR_KEY]: {description: "default error"}
})

sidec15 avatar May 19 '21 08:05 sidec15