Vizzuality/landgriffon

View on GitHub
api/src/decorators/api-tree-response.decorator.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { applyDecorators, Type } from '@nestjs/common';
import { ApiOkResponse, getSchemaPath } from '@nestjs/swagger';

export function ApiOkTreeResponse(options: {
  treeNodeType: Type;
}): MethodDecorator {
  return applyDecorators(
    ApiOkResponse({
      schema: {
        allOf: [
          { $ref: getSchemaPath(options.treeNodeType) },
          {
            properties: {
              children: {
                type: 'array',
                items: { $ref: getSchemaPath(options.treeNodeType) },
              },
            },
          },
        ],
      },
    }),
  );
}