Tips on stopping the spreading of nested DTO property in Swagger

Currently, I am setting up a query with the following structure for my GET endpoint:


        export class AnalyticsRequestDTO<
            G extends GroupableKeys,
            P extends PopulateableKeys<G> | undefined = undefined
        >
        implements AggregateRunLogAnalyticsOptions<G, P>
        {
            @IsObject()
            @IsOptional()
            @ApiProperty({
                description: 'Filters to apply logs',
                required: false,
            })
            filter: AnalyticsFilterDTO = {}

            @IsArray()
            @ApiProperty({
                description: 'The fields to group by',
                required: false,
            })
            groupBy: G[]

            @IsArray()
            @IsOptional()
            @ApiProperty({
                description: 'The fields to populate',
                type: [String],
                required: false,
            })
            populate?: P[]
        }
    

The issue lies in the fact that the AnalyticsFilterDTO is being spread. I want to prevent this behavior as it causes failures when the query is not wrapped properly. Here's the complete controller code:


        @Get('/app/:appId/pages')
        public async getPageRuleStatistics<G extends GroupableKeys>(
            @Param('appId', MongoIdPipe) applicationId: string,
            @Query() query: AnalyticsRequestDTO<G>,
            @Query('forceRebuild', new DefaultValuePipe(false), ParseBoolPipe)
            forceRebuild = false
        ): Promise<AnalyticsResultsDTO<G>> {
            //Implementation details here...
        }
    

To address this issue, modifications need to be made to the DTO structure. Any suggestions on how to go about this?

Answer №1

When utilizing the dto as a query, having a nested object seems unattainable.

However, if you incorporate it in the request body, you have the capability to specify the property type, ultimately displaying the necessary payload:

@ApiProperty({
    description: 'Filters to apply logs',
    required: false,
    type: AnalyticsFilterDTO,
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to resolve the error 'Cannot use import statement outside a module' while executing cdk deploy

https://i.sstatic.net/umv1S.png In my project, I have a TypeScript and JavaScript blend structure. The bin folder contains a file that creates the CDK stack, while the lib folder holds all of my CDK code for creating AWS resources. However, within the lib ...

Does combineLatest detach this from an angular service function?

Check out this test service on Stackblitz! It utilizes the combineLatest method inside the constructor to invoke a service method: constructor() { console.log("TEST SERVICE CONSTRUCTED") this.setParameters.bind(this) this.assignFixedParamete ...

Utilizing Prisma Enum with Nest JS: A Comprehensive Guide

While working on my backend with Prisma and NestJS, I have encountered an issue. I defined an enum in Prisma that works fine in debug mode, but when I generate the Prisma client using nest build, I get an error. Object.values(client_1.RoomSharingType).join ...

What limitations prevent me from utilizing a switch statement to refine class types in Typescript?

Unique Playground Link with Comments This is a standard illustration of type narrowing through the use of interfaces. // Defining 2 types of entities enum EntityType { ANIMAL = 'ANIMAL', PLANT = 'PLANT', } // The interface for ani ...

Combining data types to create a unified set of keys found within a complex nested structure

This problem is really testing my patience. No matter what I do, I just can't seem to make it work properly. Here's the closest I've come so far: // Defining a complex type type O = Record<'a', Record<'b' | 'x& ...

Clarity 3 enhancement: Encounter of NullInjectorError with TreeFocusManagerService

Upon updating my project to Angular9/Clarity3 from Angular8/Clarity2, I encountered some issues while navigating the app. I was able to fix some problems, but now I'm facing a NullInjectorError: ERROR Error: Uncaught (in promise): NullInjectorErr ...

What is the most effective method for dividing a string in TypeScript?

Here is the scenario: receiving a string input that looks like Input text: string = "today lunch 200 #hotelname" Output subject: "today lunch" price: 200 tag: #hotelname My initial solution looks like this: text: string = "today lunch 200 #hotelname" ...

What is the process for obtaining a nested FormControl?

Below is the structure of my form: form = new FormGroup({ name: new FormControl('', Validators.required), comment: new FormControl(''), endpointsPermissions: new FormControl({ read: new FormControl(null), write: new FormCo ...

Zoom-to-fit functionality in Three.js with spacing adjustment

I am currently working on developing a zoom-to-fit function that can accurately adjust a list of points to fit within a specified drawing area, while also allowing for customizable offsets on all sides of the image. In essence, I aim to zoom-to-fit within ...

Type determined by the variable's condition

Is there a way to dynamically select the right type from a list of types, like a "type map," by passing a variable as component props? I've been trying to implement this concept called "Conditional Types" in TypeScript, but couldn't find a soluti ...

Encountering the "Maximum Update Depth Exceeded" error in React Typescript with hooks

I encountered this error: Uncaught Error: Maximum update depth exceeded. It seems to be related to calling setState multiple times within componentWillUpdate or componentDidUpdate. React limits nested updates to prevent infinite loops. I am unsure of what ...

When attempting to access a static method in TypeScript, an error occurs indicating that the property 'users_index' does not exist on the type 'typeof UserApiController'

Just dipping my toes into TypeScript and attempting to invoke a function on a class. In file A: import userAPIController from "./controllers/customer/userAPIController"; userAPIController.users_index(); In file B: export default class UserApiControlle ...

The sticky navbar fails to stay in place when the content becomes too lengthy

This is my current state of code (minified, for explanation only) index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-w ...

Issue with TypeScript while trying to define a property of a named function expression using 'let' instead of 'const'

As I continued my journey through the TypeScript handbook, I stumbled upon an intriguing concept while learning about Call Signatures. The code snippet provided in the handbook goes like this: type DescribableFunction = { description: string; (someArg: n ...

Exporting the state of a Redux reducer as an array in a TypeScript file

Having an issue where my reducer is undefined and I can't seem to figure out why. It's working fine when it's not an array, but when it is an array it stops working. This is how my code looks like in groupSlice.ts: export interface GroupSta ...

Animating progress bars using React Native

I've been working on implementing a progress bar for my react-native project that can be used in multiple instances. Here's the code I currently have: The progress bar tsx: import React, { useEffect } from 'react' import { Animated, St ...

Dealing with the "expression has changed after it was checked" error in Angular 2, specifically when a component property relies on the current datetime

My component's styling is dependent on the current datetime. I have a function within my component that looks like this: private fontColor( dto : Dto ) : string { // date of execution for the dto let dtoDate : Date = new Date( dto.LastExecu ...

ConfirmUsername is immutable | TypeScript paired with Jest and Enzyme

Currently, I am experimenting with Jest and Enzyme on my React-TS project to test a small utility function. While working on a JS file within the project, I encountered the following error: "validateUsername" is read-only. Here is the code for the utilit ...

Tips for inputting transition properties in Material UI Popper

Currently, I am making use of material ui popper and I would like to extract the transition into a separate function as illustrated below: import React from 'react'; import { makeStyles, Theme, createStyles } from '@material-ui/core/styles& ...