Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@TypedException() decorator for swagger documents #548

Merged
merged 4 commits into from
Aug 16, 2023

Conversation

samchon
Copy link
Owner

@samchon samchon commented Aug 16, 2023

New decorator @TypedException() has been newly added.

For reference, this decorator function does not affect to the method's behavior, but only affects to the swagger documents generation. Also, it does not affect to the SDK library generation yet, but will be used in the future.

Declaration

export function TypedException<T extends object>(
    status: number | "2XX" | "3XX" | "4XX" | "5XX",
    description?: string | undefined,
): MethodDecorator;

Use Case

import {
    TypedBody,
    TypedException,
    TypedParam,
    TypedRoute,
} from "@nestia/core";
import { Controller } from "@nestjs/common";
import typia, { TypeGuardError } from "typia";

import { IBbsArticle } from "@api/lib/structures/IBbsArticle";
import { IInternalServerError } from "@api/lib/structures/IInternalServerError";
import { INotFound } from "@api/lib/structures/INotFound";
import { IUnprocessibleEntity } from "@api/lib/structures/IUnprocessibleEntity";

@Controller("bbs/articles")
export class BbsArticlesController {
    @TypedRoute.Post(":section")
    @TypedException<TypeGuardError>(400, "invalid request")
    @TypedException<INotFound>(404, "unable to find the matched section")
    @TypedException<IUnprocessibleEntity>(428)
    @TypedException<IInternalServerError>("5XX", "internal server error")
    public async store(
        @TypedParam("section") section: string,
        @TypedBody() input: IBbsArticle.IStore,
    ): Promise<IBbsArticle>;
}

@samchon samchon added the enhancement New feature or request label Aug 16, 2023
@samchon samchon self-assigned this Aug 16, 2023
@samchon samchon merged commit be5066c into master Aug 16, 2023
3 checks passed
@samchon samchon deleted the features/TypedException branch August 16, 2023 19:13
@samchon
Copy link
Owner Author

samchon commented Aug 16, 2023

Close #540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant