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

Open API doc not generated for PartialType DTO #1074

Closed
kalaivanan-muthusamy opened this issue Dec 6, 2020 · 5 comments
Closed

Open API doc not generated for PartialType DTO #1074

kalaivanan-muthusamy opened this issue Dec 6, 2020 · 5 comments

Comments

@kalaivanan-muthusamy
Copy link

Bug Report

When using the PartialType for DTO, it is not reflected in the OpenAPI documentation.
https://docs.nestjs.com/openapi/mapped-types

Input Code

export class CreateUserDTO {
  @IsNotEmpty()
  @IsString()
  name: string;
}

export class UpdateUserDTO extends PartialType(CreateUserDTO) {
}

Current behavior

UpdateUserDTO schema in the OpenAPI documentation is missing the name property

Expected behavior

OpenAPI document to have name: string in UpdateUserDTO Schema. But missing the name property in the generated schema.

Environment


Nest version: 7.0.0

 
For Tooling issues:
- Node version: 12.18.1
- Platform: Windows

Others:

@jmcdo29
Copy link
Member

jmcdo29 commented Dec 6, 2020

Please provide a minimum reproduction repository.

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Dec 7, 2020
@kalaivanan-muthusamy
Copy link
Author

Sample Repo: https://github.com/kalaivanan-muthusamy/nestjs-swagger-issue-1074

image
image

I am expecting the properties in CreateUserDto should also exist in UpdateUserDto as optional. But the properties are not present in the schema

@kamilmysliwiec
Copy link
Member

Import PartialType from @nestjs/swagger

@kalaivanan-muthusamy
Copy link
Author

kalaivanan-muthusamy commented Dec 8, 2020

I missed it completely. It is clearly mentioned in the document. Thanks for the wonderful document.

This should be the issue with cli then. As CLI is importing the PartialType from @nestjs/mapped-types instead @nestjs/swagger.

Opened the PR for the expected change
nestjs/schematics#545

Austinate added a commit to Austinate/guess-the-distance-backend that referenced this issue Mar 25, 2022
Change is required for swagger to generate doc on PartialType-based DTOs, per nestjs/swagger#1074 (comment)
@ZeeshanAhmadKhalil
Copy link

But it's not Making the properties in StarterDto required.

StarterDto

export class StarterDto {

    @ApiProperty({
        required: true,
    })
    @IsNotEmpty()
    recipientName: string

    @ApiProperty({
        required: false
    })
    recipientPronounce?: string

    @ApiProperty({
        type: 'string',
        format: 'binary',
        required: false,
    })
    recipientNameFile?: any

    @ApiProperty({
        required: true,
    })
    @IsNotEmpty()
    recipientRelationship: string

    @ApiProperty({
        required: true,
    })
    @IsNotEmpty()
    mentionRecipientInSong: boolean

    @ApiProperty({
        required: true,
    })
    @IsNotEmpty()
    occasion: string

    @ApiProperty({
        required: true,
    })
    @IsNotEmpty()
    mentionOccasionInSong: boolean
}

UpdateStarterDto

import { PartialType } from '@nestjs/swagger';

export class UpdateStarterDto extends PartialType(StarterDto) {

    @ApiProperty()
    @IsNotEmpty()
    orderId: string
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants