Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TYPESCRIPT][v3.0.2] Incorrect imports generated with backslash (windows 10) #8930

Closed
vtecnica opened this issue Nov 19, 2018 · 6 comments · Fixed by swagger-api/swagger-codegen-generators#372

Comments

@vtecnica
Copy link

Description

When generating typescript-angular, the import for api and modules are generated with backslash:
E.g.

import { ApiResponse } from '../model\apiResponse';
Swagger-codegen version

v.3.0.2

Swagger declaration file content or url

http://petstore.swagger.io/v2/swagger.json

Command line used for generation

java -jar swagger-codegen-cli-3.0.2.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular

Steps to reproduce

Download or generate swagger-codegen-cli-3.0.2.jar

java -jar swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular

@Maxim-Mazurok
Copy link

I confirm, getting import { SomeDto } from '../model\someDto'; on Windows 10 with swagger-codegen-cli-3.0.0-20180717.153005-90.jar

@dbusacca
Copy link

Still open in 3.0.4 ...

@xarling
Copy link

xarling commented Feb 18, 2019

In https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java the following lines:

supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts"));
supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts"));

replace the '.' character by the File.seperatorChar. The seperatorChar is the system-dependent default name-separator character, which is / for Unix and \ for Windows.

Shouldn't it just be / independent of the system?

@RaduFurnea
Copy link

RaduFurnea commented Apr 11, 2019

Managed to generate a correct typescript-angular client with this generator, give it a try.

@paulbors
Copy link

paulbors commented Apr 26, 2019

In case you don't want to change the generator and can't wait till this bug is fixed, here's a quick dirty patch for maven you could invoke post code generation and before you start building the generated code:

<plugin>
    <!-- Hook into Maven's build life cycles and execute custom build that's outside of Maven convention
            See https://maven.apache.org/plugins/maven-antrun-plugin/
    -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>${maven-antrun-plugin.version}</version>
    <dependencies>
        <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>${ant-contrib.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <!-- Default lifecycle -->
        <execution>
            <id>npm-install</id>
            <phase>process-resources</phase>
            <goals><goal>run</goal></goals>
            <configuration>
                <tasks>
                    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
                    <condition property="isWindows"><os family="windows" /></condition>
                    <if>
                        <equals arg1="${isWindows}" arg2="true" />
                        <then>
                            <property name="npm.bin" value="npm.cmd" />
                            <!-- FIXME: Remove once issue 8930 is fixed -->
                            <echo message="Patching Swagger's default service on Windows only!" level="info" />
                            <echo message=" Remove once below bug has been fixed:" level="info" />
                            <echo message=" https://github.com/swagger-api/swagger-codegen/issues/8930" level="info" />
<!-- Patch this bug by replacing the path separator with the system independent one... -->
                            <replace file="${project.basedir}/.../generated/swagger-api/api/default.service.ts" token="\" value="/"/>
                        </then>
                        <else><property name="npm.bin" value="npm" /></else>
                    </if>
                    <available file="${ng-app.node_modules}" type="dir" property="skipNpmInstall"/>
                    <if>
                        <equals arg1="${skipNpmInstall}" arg2="true" />
                        <then>
                            <echo message="WARNING: ${ng-app.node_modules} exists, skipping npm install!" level="warning" />
                        </then>
                        <else>
                            <exec executable="${npm.bin}" dir="${ng-app.root}" failonerror="true">mvn
                                <arg value="install"/>
                            </exec>
                        </else>
                    </if>
                </tasks>
            </configuration>
        </execution>
...

@HugoMario
Copy link
Contributor

hey @vtecnica @Maxim-Mazurok @dbusacca @xarling , i added a PR solving this issue. can you please check this when you have a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants