samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.76k stars 91 forks source link

I want to use `@TypedException` with same statusCode, differenct Error message. (`@TypedException` doesn't work with object union type) #816

Closed 8471919 closed 6 months ago

8471919 commented 6 months ago

Summary

Write a short summary of the bug in here.

In npx nestia swagger. when I use union type of object type, @TypedExeption doesn't make swagger document.

interface A {
  code: 1;
  message: 'hi';
}
interface B {
  code: 2;
  message: 'hello';
}

@TypedException<A | B>(200)
async func() {
  ...
}

Exception is not displayed on the swagger document.

Code occuring the bug

Exactly I want to use @TypedException this way,

namespace ERROR_MESSAGE {
  export interface USER_NOT_FOUND {
    code: 404;
    message: "Can not find user";
  }

  export interface USER_INFO_NOT_FOUND {
    code: 404;
    message: "No User info";
  }
}

@TypedException<ERROR_MESSAGE.USER_NOT_FOUND | ERROR_MESSAGE.USER_INFO_NOT_FOUND>(404)
@Get('user-info')
async getUserInfo() {
  return userInfo;
}

but, Union type doesn't work about object union type. image this is the result of above code. Here is no exception description.

and this not work too.

@TypedException<ERROR_MESSAGE.USER_NOT_FOUND>(404)
@TypedException<ERROR_MESSAGE.USER_INTO_NOT_FOUND>(404)
@Get('user-info')
async getUserInfo() {
  return userInfo;
}

and I want for you to make this using "oneOf" of swagger.

rojiwon123 commented 6 months ago

@samchon This error occurs during the "DO ASSIGN" process in the ExceptionAnalyzer module. The exception cases are as follows:

Moreover, when the exception schema is generic, it's necessary to ensure that the imports of the types injected as generics are done correctly. For example, if there's a type name like Exception<NotFound | Unauthorize>, the Exception type, NotFound type, and Unauthorized type should each be imported correctly.

samchon commented 6 months ago

If namespaced type being utilized, such bug be occured.

I'll fix this problem ASAP. Thanks for reporting.