OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.17k stars 6.42k forks source link

[BUG] TS generator adds `http` tools imports generating ONLY models #13528

Open andrescevp opened 1 year ago

andrescevp commented 1 year ago

Bug Report Checklist

Description

I am generating the TS only models, i get the models but wrong imports.

openapi-generator version

2.5.2 - Installed by yarn in WSL ubuntu 20.04 with openjdk 11.0.16 2022-07-19

OpenAPI declaration file content or url

Not relevante here

Generation Details

Only models are required.

TS_POST_PROCESS_FILE='prettier --write --config .prettierrc && eslint --fix' openapi-generator-cli generate -s -i http://0.0.0.0:8080/swagger.json --global-property models -g typescript -o ./src/@custom_types

... other imports import { HttpFile } from '../http/http';


##### Steps to reproduce

TS_POST_PROCESS_FILE='prettier --write --config .prettierrc && eslint --fix' openapi-generator-cli generate -s -i http://0.0.0.0:8080/swagger.json --global-property models -g typescript -o ./src/@custom_types


output:
```js
/**
 * Survey Integration Service API
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * OpenAPI spec version: v1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

... other imports
import { HttpFile } from '../http/http';

The last import is wrong, do not exists.

Related issues/PRs
Suggest a fix
ctataryn commented 3 months ago

Just wanted to post a workaround:

Download the typescript templates

openapi-generator-cli author template -g typescript -o ./templates/typescript

Modify the template Remove the HttpFile import from ./templates/typescript/model/model.mustache

Use the custom templates Use the custom templates by adding -t ./templates/typescript to your openapi-generator-cli command.