ferdikoomen / openapi-typescript-codegen

NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
MIT License
2.86k stars 516 forks source link

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

Open makerForAll opened 1 month ago

makerForAll commented 1 month ago

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. ------

mrlubos commented 1 month ago

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