openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Issues with Generated Files in Front-End after Using Commands Following the Definition of DTO Generics in Back-End

Open makerForAll opened this issue 1 year ago • 1 comments

My back-end uses the NestJS framework. When I configured the DTO...

import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, IsString } from 'class-validator';

export class ResultType<T> {
  @ApiProperty({ description: '数据数组', isArray: true })
  data: T[];

  @ApiProperty({ description: '总数', required: false })
  total?: number;
}

export class ResponseType<T> {
  @ApiProperty({ description: '返回code' })
  @IsNumber()
  code: number;

  @ApiProperty({ description: '返回提示信息' })
  @IsString()
  message: string;

  @ApiProperty({ description: '返回结果' })
  results: ResultType<T>;
}

next-------controller.ts------- begin use it ----------------------

@ApiOperation({ summary: 'create client' })
 @ApiResponse({ type: ResponseType<CreateClientDTO> })
 @Post()
 @UsePipes(new ValidationPipe({ transform: true }))
 async create(@Body() client: CreateClientDTO): Promise<ResultType<CreateClientDTO>> {
   return this.clientService.create(client);
 };

next------ frontend --------- I started using commands to generate API client files.---------------------------- openapi --input http://localhost:3000/api-json --output ./src/api --client axios --request ./src/api/custom-request.ts --name APIforBackEnd --useOptions

next------- frontend ------- open generate file about the ResultType -------

Describe the bug


export type ResultType = {
    /**
     * 数据数组
     */
    data: Array<any[]>;
    /**
     * 总数
     */
    total?: number;
};

-------------- is error------------------ data: Array<any[]>;

--------------the right ------------------ data: Array<any>;

-------- Generics are also not supported. ------

makerForAll avatar Jul 14 '24 01:07 makerForAll

Hey @makerForAll, this package is no longer maintained. Please check if the problem exists in https://github.com/hey-api/openapi-ts and open an issue there if you'd like it resolved

mrlubos avatar Jul 14 '24 13:07 mrlubos