我有以下代码:
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 上的模式,但它不起作用,我收到错误。任何想法?
我正在尝试创建 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)