Language/Python
[NestJS] 스웨거에서 여러 Type의 Object Array 정의
junha6316
2022. 8. 22. 22:52
swagger를 사용하다 보면 여러 타입의 오브젝트가 들어간 Array를 정의해야할 때가 있다. 아래처럼하면 된다.
$ref가 돌아가지 않는다면 아래 링크를 통해 방법을 확인하자.
https://cocook.tistory.com/213
[NestJS] Swagger에서 refs 안될 때
Swagger에서 DTO를 이용해 서버 응답 값을 정의하는 기능이 있는데 직접 가져오는게 아닌 경로를 작성해주면 해당 경로에 있는 클래스를 가져와 붙여주는 기능이 있다. 경로는 분명히 맞는데 안되
cocook.tistory.com
export const API_RESPONSE: ApiResponseOptions = {
status: 200,
isArray: true,
description: "Successful response",
schema: {
type: "object",
properties: {
statusCode: { type: "string" },
res_code: { type: "string" },
data: {
type: "array",
items: {
anyOf: [
{ $ref: getSchemaPath(TestCreateDTO) },
{ $ref: getSchemaPath(TestUpdateDTO) },
],
},
},
},
},
};