小编Joa*_*osa的帖子

使用接口作为 swagger 模式 - NestJS DTO

我有以下代码:

import { IsNotEmpty, IsArray, ArrayMinSize } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class PublishDto {
  @IsNotEmpty()
  @IsArray()
  @ArrayMinSize(1)
  @ApiProperty({
    type: [Product]
  })
  products: Product[];
}

interface Product {
  id: string;
  title: string;
  sku: string;
  stock: number;
  description: string;
  shortDescription: string;
  imagesUrl: string[];
  price: number;
  department: string;
  category: string;
  brand: string;
  keywords: string[];
  isActive: boolean;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我试图将接口Product作为 swagger 上的模式,但它不起作用,我收到错误。任何想法?

swagger swagger-ui nestjs

8
推荐指数
1
解决办法
8243
查看次数

catch 块上对象的类型为“未知”

我正在尝试创建 axios 抽象,但在 catch 块上收到此错误。

对象的类型为“未知”。

import axios, { AxiosResponse } from "axios";
import { injectable } from "inversify";
import { HttpRequest, HttpResponse, IHttp } from "../../interfaces/Ihttp";

@injectable()
export class AxiosHttpClient implements IHttp {
  async request(params: HttpRequest): Promise<HttpResponse> {
    let axiosResponse: AxiosResponse;

    try {
      axiosResponse = await axios.request({
        url: params.url,
        method: params.method,
        data: params.body,
        headers: params.headers,
      });
    } catch (error) {
      axiosResponse = error.response;
    }

    return {
      statusCode: axiosResponse.status,
      data: axiosResponse.data,
    };
  }
}
Run Code Online (Sandbox Code Playgroud)

try-catch typescript axios

2
推荐指数
1
解决办法
2030
查看次数

标签 统计

axios ×1

nestjs ×1

swagger ×1

swagger-ui ×1

try-catch ×1

typescript ×1