[BUG][typescript][regression] Invalid path separator for imports on Windows
Created by: adamstoffel
Description
Typescript clients generated on Windows have invalid import paths due to the wrong path separator being used.
Expected Code
import { Pet } from '../models/Pet';
Actual Code
import { Pet } from '..\models\Pet';
openapi-generator version
Any version >= 6.1.0
OpenAPI declaration file content or url
Command line used for generation
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 typescript -o c:\temp\typescript_client
Steps to reproduce
Just generate source code for typescript.
Related issues/PRs
This was previously fixed (issue #7174 (closed), pull #7175) but regressed in pull #12957.
Suggest a fix/enhancement
Use /
instead of File.Separator
. File.Separator
is \
in Windows, which is invalid Typescript.
Method to fix is toModelImport
in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java
:
Current code:
public String toModelImport(String name) {
return ".." + File.separator + modelPackage() + File.separator + toModelName(name);
}
Corrected code:
public String toModelImport(String name) {
// Use `/` instead of `File.Separator`. `File.Separator` is `\` in Windows, which is invalid Typescript.
return "../" modelPackage() + "/" + toModelName(name);
}