Having an Empty Schema: A Guide to Configuring @ApiProperty in NestJS

When I create @ApiProperty() in my Dto, it looks like this:

export class UpdateMeassageDto {

@ApiProperty()

message: {

    hash: string;


    created_at: Date;


    updated_at: Date;
}

}

However, the result turns out to be empty. Here's what it looks like:

https://i.sstatic.net/kYGP5.jpg

Answer №1

Consider creating a new Message type with the following properties:

export class Message{

    @ApiProperty()
    hash: string;

    @ApiProperty()
    created_at: Date;

    @ApiProperty()
    updated_at: Date;
}

Next, make sure to update your DTO to include the Message type like this:

export class UpdateMessageDto {

    @ApiProperty()
    message: Message
}

Answer №2

Here is a way to achieve it:

import { ApiProperty, getSchemaPath } from '@nestjs/swagger';

export class MessageDto {
    @ApiProperty({
        type: 'string',
        example: 'hx1231',
    })
    hash: string;

    @ApiProperty({
        type: 'date',
        example: '2021-08-04T19:39:00.829Z',
    })
    created_at: Date;

    @ApiProperty({
        type: 'string',
        format: 'date-time',
        example: '2021-08-04T19:39:00.829Z',
    })
    updated_at: Date;
}

export class UpdateMessageDto {
    @ApiProperty({
        type: 'array',
        items: { $ref: getSchemaPath(MessageDto) },
    })
    message: MessageDto;
}

Each property requires an ApiProperty. The use of $ref allows for the reuse of one DTO within another DTO. Additionally, consider integrating class-validator into the DTOs for enhanced functionality.

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

Unraveling the mysteries of intricate JSON array and object data

I am currently facing a challenge in extracting complex JSON data for my Angular application. Here is an example of how the data is structured: { "members": [ { "member_id": "1", "first_name": "John", " ...

Prohibit the use of explicit type parameters or limit the union type parameters to enhance the safety of the types

When the getValues() function is called without explicit type parameters, the Typescript code functions correctly. However, calling it with explicit type parameters can result in errors (as seen in invocation getValues<'a' | 'b' | &a ...

What is the best approach to handling an undefined quantity of input FormControls within Angular?

I have a unique task in my Angular application where I need to collect an unspecified number of entries, such as names, into a list. My goal is to convert this list of names into an array. To facilitate this process, I would like to offer users the abilit ...

Jest v29 Upgrade Issue: Test environment jest-environment-jsdom not found

Are there any success stories of upgrading to the newest version of Jest, specifically version 29? I keep encountering an error message: Error: Test environment jest-environment-jsdom cannot be found. Please ensure that the testEnvironment configuration ...

Check the functionality of a React functional component by conducting unit tests on its functions

Is there a way to properly unit test a function within a Functional component in React? Since wrapper.instance() will return null for functional components, what is the best approach to ensure this function is included in testing to achieve maximum coverag ...

Typescript controller inheritance leading to Error: $injector:unpr Unknown Provider due to minification

LATEST UPDATE: 2019/07/16 The issue I am facing is actually a result of misusing $inject. Instead of declaring it as private $inject in api-service.ts, it should have been public static $inject = [...]. During the minification process, explicit injection ...

The setupFile defined in Jest's setupFilesAfterEnv configuration is not recognized by the VSCode IDE unless the editor is actively open

I've put together a simplified repository where you can find the issue replicated. Feel free to give it a try: https://github.com/Danielvandervelden/jest-error-minimal-repro Disclaimer: I have only tested this in VSCode. I'm encountering diffic ...

Group multiple typescript files into separate outFile modules

Can TypeScript files be grouped into multiple outFiles? I want to bundle my Typescript code, but instead of one single JS file, I would like to organize my TS into separate JS files such as controllers.js and plugins.js. The options in the TypeScript pro ...

Implementing Multiple Exports within the next.config.json File

I am trying to combine withPWA and withTypescript in my configurations but I'm not sure how to do it... This is the code in my next.config.json file : const withPWA = require("next-pwa"); module.exports = withPWA({ pwa: { dest: "public", }, ...

The element 'loginToken' is not found within the type '{ loginToken: string; } | { error: Error; } | { username: string; password: string; }'

I'm currently working on creating a reducer using Typescript and Redux, but I keep running into this error: Property 'loginToken' is not recognized in type '{ loginToken: string; } | { error: Error; } | { username: string; password: str ...

Issue encountered when attempting to chain promises with async/await functionality

Here is my current code snippet: await enterName(); await enterCity(); await submit(); async enterName() { element.sendKeys('name'); } async submit() { element.submit(); waitForAngular(); } The problem I am facing is that when calling the subm ...

Is there a way to restrict props.children.some to only accept image types?

Currently troubleshooting the following issue: An error is occurring: 'Property 'type' does not exist on type 'true | ReactChild | ReactFragment | ReactPortal'. Property 'type' does not exist on type 'string'. ...

TypeScript: safely reassigning object properties for type safety

What I aim to achieve I am looking to create a JavaScript function that can remap property names of the first argument using the second argument. The goal is to utilize this remap function to generate query string parameters. For instance, transforming { ...

Oops! We encountered an error: Uncaught (in promise): [object Object]. Angular 5 version is

Trying to implement an upload button using Angular 5, I have the following code in my .ts file: handleFiles(e) { this.file = e.srcElement.files[0]; if (this.file.size > 2097152) { let snackBarRef = this.snackBar.open('Images must ...

Using debounceTime and distinctUntilChanged in Angular 6 for efficient data handling

I recently came across a tutorial on RxJS that demonstrated the use of debounce and distinctUntilChanged. I'm trying to implement it in Angular 6, but I'm facing some challenges. Here is the code from the tutorial: var observable = Rx.Observabl ...

A guide to filtering out items from observables during processing with RxJS and a time-based timer

I have a complex calculation that involves fetching information from an HTTP endpoint and combining it with input data. The result of this calculation is important for my application and needs to be stored in a variable. async calculation(input: MyInputTy ...

Combining Vue with Typescript and rollup for a powerful development stack

Currently, I am in the process of bundling a Vue component library using TypeScript and vue-property-decorator. The library consists of multiple Vue components and a plugin class imported from a separate file: import FormularioForm from '@/FormularioF ...

Determine if all resources on a page in Angular 4 have finished loading by keeping a loader spinning until everything is fully loaded

As part of my work on an Angular app, I am developing a loader to enhance user experience. While the typical approach involves utilizing a boolean parameter for subscribing to HTTP requests, in my case, the service's response consists of multiple ima ...

Displaying decimal values in Angular as percentages

In my Angular application, I have a numeric textbox that displays a percentage value and allows users to update it. https://i.stack.imgur.com/eCOKe.png <label for="fees">Fees %</label> <div class="inpu ...

The conventional method for including React import statements

I'm curious if there is a standard convention for writing import statements in React. For instance, I currently have the following: import React, { useState, FormEvent } from 'react'; import Avatar from '@material-ui/core/Avatar'; ...