Friends Of AdonisFriends Of Adonis

Operations

In OpenAPI terms, paths are endpoints (resources), such as /users or /reports/summary, that your API exposes, and operations are the HTTP methods used to manipulate these paths, such as GET, POST or DELETE.

Tags

Tags allows you to categorize your endpoints, you can apply them to specific operations or on the controller.

import {  } from '@foadonis/openapi/decorators'
 
@('Demo')
export default class  {
  @('Other', 'Public')
  () {}
}
Tags will automatically be applied to your controllers using its name.

Headers

You can define custom headers that are expected as part of the request. You can apply it to specific operations or directly on the controller.

import {  } from '@foadonis/openapi/decorators'
 
@({
  : 'X-Language',
  : 'The currently defined language',
})
export default class  {
  @({ : 'X-Store' })
  () {}
}

Responses

You can define HTTP responses using the @ApiResponse decorator. You can stack them on a same operation for different status codes. It can also be used directly on the controller to be applied on all its operations.

import {  } from '@foadonis/openapi/decorators'
 
@({ : 403, : 'Forbidden' })
export default class  {
  @({
    : 201,
    : 'The record has been successfully created.',
    : User,
  })
  () {}
}

Media Type (content-type)

You can configure the Media type on your body and responses for specific operation. For example this allow you to enable file upload.

import { ,  } from '@foadonis/openapi/decorators'
 
class  {
  @({
    : { : 'array', : { : 'string', : 'binary' } },
  })
  : any
}
 
export default class  {
  @({
    : ,
    : 'multipart/form-data',
  })
  () {}
}

On this page