Skip to content
Thibaut SEVERAC edited this page Dec 11, 2023 · 13 revisions

📖 Home

Welcome to the moleculer-auto-openapi wiki!

Feel free to use the Table of Contents on the right to navigate.


File Upload

When using the file upload mechanism with moleculer-web, be aware that it uses action parameters to send the file. This means that you cannot use action's parameters for other purposes in this specific case.

It's important to note that moleculer-web does not support sending a file as well as other fields at the same time. So, the params will be automatically added to query, forcing them to body will skip them

The multiPartFileFieldName setting allows you to define the field name for the uploaded file. However, this modification is purely aesthetic and does not affect the file received by the action. More details about this setting can be found here.

If you set a limit in busboys in moleculer-web, either at the route level or at the alias level, and that limit is "1", the mixin will generate a single field, facilitating the upload of a single file. Otherwise, it will generate a field array, enabling the upload of multiple files.

ℹ️ Remember that in case of receiving multiple files, the action will be invoked separately for each one.

Filter documentation

The filterAliases is a method in our service. This method matches to the type filterAliasesFn (Documentation: Link).

Global example:

{
    name: 'openapi',
    // [...]
    methods: {
        filterAliases: (ctx: Context<OA_GENERATE_DOCS_INPUT>, aliases: Array<Alias>): Array<Alias> => {
            return aliases;
        }
    } as ServiceMethods & { filterAliases: filterAliasesFn },
}

In this example, filterAliases is defined to return aliases as it is.

Example : Filtering by params

Here, aliases are being filtered based on the presence of the 'admin' parameter in the context. If 'admin' param exists, it shows aliases for service named 'admin'.

{
    methods: {
        filterAliases: (ctx: Context<OA_GENERATE_DOCS_INPUT & {admin?:string}>, aliases: Array<Alias>): Array<Alias> => {
            return aliases.filter(alias => ctx.params?.admin !== undefined ? alias.service?.name == "admin" : alias.service?.name == "admin")
        }
    } as ServiceMethods & { filterAliases: filterAliasesFn },
}

Example : Filtering by metas

In this example, the 'filterAliases' is checking if 'admin' exists in the metadata. If it does, it filters and shows aliases for service named 'admin'.

{
    methods: {
        filterAliases: (ctx: Context<OA_GENERATE_DOCS_INPUT, {admin?: boolean}>, aliases: Array<Alias>): Array<Alias> => {
            return aliases.filter(alias => ctx.meta?.admin ? alias.service?.name == "admin" : alias.service?.name == "admin")
        }
    } as ServiceMethods & { filterAliases: filterAliasesFn },
}
Clone this wiki locally