[BUG][Typescript] Import path is invalid in windows.
Created by: masmgr
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
In windows, I generated typescript client source code by OpenAPI generator. But, generated source has invalid import path in types folder's files. I cannot compile this typescript code.
Expected Code
import { Pet } from '../models/Pet';
Actual Code
import { Pet } from '..\models\Pet';
openapi-generator version
Current master branch (5bbcf30c).
OpenAPI declaration file content or url
I found this bug in petstore.yaml.
Generation Details
Steps to reproduce
Generate source code for typescript. Execute this command.
java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g javascript -o c:\temp\javascript_api_client
Related issues/PRs
There is no similar issue/PR.
Suggest a fix
Use /
instead of File.Separator
. File.Separator
is /
in Windows.
A target method is postProcessOperationsWithModels
of openapi-generator\modules\openapi-generator\src\main\java\org\openapitools\codegen\languages\TypeScriptClientCodegen.java.
Before
im.put("filename", ((String) im.get("import")).replace(".", File.Separator));
After
im.put("filename", ((String) im.get("import")).replace(".", "/"));