Swagger Decorators

A prebuilt swagger decorator to make creating your swagger documentation is simple as possible.

Decorator

import { SwaggerPropertyDecorator } from '@juicyllama/core'

@SwaggerPropertyDecorator(options)

Options

Provide the following optional options to the decorator:

OptionTypeDescription
typeSwaggerPropertyTypeThe type of the property
requiredbooleanIs the property required
hiddenbooleanShould the property be hidden from the documentation
descriptionstringThe description of the property
examplestring | number | boolean | Date | objectAn example of the property
enumanyAn enum of the property
refSwaggerPropertyReferenceThe reference to a type

SwaggerPropertyType

Import the enum from the core package and reference it in your decorator.

import { SwaggerPropertyType } from '@juicyllama/core'

enum SwaggerPropertyType {
    STRING,
    NUMBER,
    BOOLEAN,
    DATE,
    ARRAY,
    OBJECT,
    ENUM,
    EMAIL,
}

SwaggerPropertyReference

If you would like to reference other common resources in your documentation, you can use the following enum.

import { SwaggerPropertyReference } from '@juicyllama/core'

export enum SwaggerPropertyReference {
    ACCOUNT = 'ACCOUNT',
    ACCOUNTS = 'ACCOUNTS',
    CONTACTS = 'CONTACTS',
    USER = 'USER',
    USERS = 'USERS',
}

Output

Depending on the inputs you provide, the decorator will build the swagger documentation for you.

For example, if you provide the following:

import { SwaggerPropertyDecorator, SwaggerPropertyType } from '@juicyllama/core'

@SwaggerPropertyDecorator({
    type: SwaggerPropertyType.NUMBER,
    description: 'The unique identifier for this record',
    example: 1,
})

The output in your endpoints will be a documented property of type number, with the description and example shown above.


Docs v.0.14.0 Copyright © 2024