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-angular] upgrade to support angular v6 (breaking changes due to rxjs v6) #8179

Closed
crhistianramirez opened this issue May 12, 2018 · 8 comments

Comments

@crhistianramirez
Copy link

crhistianramirez commented May 12, 2018

Description

Angular v6 just released which has a dependency on rxjs v6. Specifically, imports for Observables have changed: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md

It looks like we'll need to update:
import { Observable } from 'rxjs/Observable';

to:

import { Observable } from 'rxjs'

Suggest a fix/enhancement

I propose we add an additional property useRxjsVersion6Imports that is true if ngVersion is greater than 6.0.0 to determine which import to display. I'd also be willing to take a shot at this if approved.

@macjohnny
Copy link
Contributor

this has already been implemented by @akehir in #8155, so this issue can be closed.

@pegaltier
Copy link

The issue is always present when i use typescript-angular api : https://generator.swagger.io/api/gen/clients/typescript-angular

@macjohnny
Copy link
Contributor

macjohnny commented Jun 12, 2018

@pegaltier this is because generator.swagger.io uses version 2.3.1, and the fix is in the current master branch. however, there is a current release of OpenAPI Generator that fully supports angular 6 and rxjs v6. see https://github.com/openapitools/openapi-generator

@akehir
Copy link
Contributor

akehir commented Jun 12, 2018

@pegaltier if you need to use swagger-generator, you can use the following 2 mustache files from swagger master, if you just override the default mustache files with these 2:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular/apiInterface.mustache

For example in your pom:

<groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>swagger-wallet-api-codegen</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.build.directory}/swagger/wallet/meta/swagger.json</inputSpec>
                            <language>typescript-angular</language>
                            <output>src/generated/wallet-api</output>
                            <templateDirectory>../_mustache</templateDirectory>
                            <configOptions>
                                <ngVersion>6.0</ngVersion>

                            </configOptions>
                        </configuration>
                    </execution>

@fizxmike
Copy link

SNAPSHOT builds of master do not work for me due to at least one open issue and unmerged PR. So, is the answer "use openapi-generator instead"?

@fizxmike
Copy link

Bad News

openapi-generator has issues with my JSON Schema files (you'd think they'd honor the spec)... no go.

Good News

For released version 2.3.1 of swagger-codgen, doing npm install rxjs@6 and rxjs-compat@6 before you build the client worked.

#BeerMe

@sefasenturk95
Copy link

sefasenturk95 commented Jul 4, 2018

@fizxmike Could you explain a little bit more on how you got swagger-codegen working so it can be used with angular 6?

@fizxmike
Copy link

fizxmike commented Jul 5, 2018

The main issue is that with the current "release" of swagger-codegen (v2.3.1), the typescript-angular client for version 6 uses the wrong version of rxjs, so build of client will fail. The "workaround" is to install the right version of rxjs (version 6) AND rxjs-compat (version 6). So do this in client folder (after codegen):

npm install
npm install rxjs@6 rxjs-compat@6
npm build

Of course, when you codegen, use the "ngVersion":"6" option in your config.json

{
    "npmName":"my-swagger-package",
    "npmVersion":"0.0.1",
    "ngVersion":"6"
}

Summary

java -jar swagger-codegen-cli-2.3.1.jar -l typescript-angular -c config.json -i swagger.yml -o angular6clinet
cd angular6client
npm install
npm install rxjs@6 rxjs-compat@6
npm build

To make the fix "stick" add this line to your angular6clinet/.swagger-codegen-ignore file:

# keep package.json frozen since it has fix (https://github.com/swagger-api/swagger-codegen/issues/8179#issuecomment-401208765)
package.json

This way you can update your swagger.yml and rebuild the client without clobbering the fix.

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

No branches or pull requests

6 participants