Skip to content

Swagger Docs don't generate when example() throws an exception. #69

@jraynor196

Description

@jraynor196

Hi-

We are using an older version 0.8 and it wasn't generating the swagger documents. I've upgraded to the latest version (2.3.1) and also it was not generating. I've traced the issue to an abstract DTO we had defined.

export abstract class AbstractDto {
    /**
     * Required method for all DTOs for Swagger documentation.
     * Forces subclass to implement the required Swagger / OpenAPI "public static example()" method.
     */
    public static example(): ApiResponseDto<unknown> | AbstractDto {
        //JDR - TEST Commenting the throw out to see if Swagger Generates
        //throw new Error(`Concrete DTO implementations must implement their own method: "public static example(): ApiResponseDto"`); 
        return this;
    }
}

Originally it just had the throw. As you can see I commented out the throw and had it return itself. After I did that the swagger documentation generated without error. We have the exception in place there to ensure all implement the "example" method when creating. But this causes the generation of open-api.json GET call to fail. We don't want to remove our guardrail here if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions