-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Add support for Angular v14 #12901
Merged
macjohnny
merged 8 commits into
OpenAPITools:master
from
marinus-suniram:fix_issue_12593
Aug 17, 2022
Merged
Add support for Angular v14 #12901
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3c6063
Add support for Angular v14
marinus-suniram 6398daf
Review comments
marinus-suniram f9c42eb
Update samples/client/petstore/typescript-angular-v14-provided-in-roo…
macjohnny a51ca84
Update samples/client/petstore/typescript-angular-v14-provided-in-roo…
macjohnny c50ce4c
Update samples/client/petstore/typescript-angular-v14-provided-in-roo…
macjohnny 6dd5e4f
Review comments
marinus-suniram 7529cfe
Merge remote-tracking branch 'origin' into fix_issue_12593
macjohnny 000d1b2
update samples
macjohnny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
generatorName: typescript-angular | ||
outputDir: samples/client/petstore/typescript-angular-v14-oneOf/builds/default | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOfArrayMapImport.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-angular | ||
additionalProperties: | ||
ngVersion: 14.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
generatorName: typescript-angular | ||
outputDir: samples/client/petstore/typescript-angular-v14-provided-in-any/builds/default | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-angular | ||
additionalProperties: | ||
ngVersion: 14.0.5 | ||
providedIn: any |
11 changes: 11 additions & 0 deletions
11
bin/configs/typescript-angular-v14-provided-in-root-with-npm.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: typescript-angular | ||
outputDir: samples/client/petstore/typescript-angular-v14-provided-in-root/builds/with-npm | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-angular | ||
additionalProperties: | ||
ngVersion: 14.0.5 | ||
npmVersion: 1.0.0 | ||
npmName: '@openapitools/typescript-angular-petstore' | ||
npmRepository: https://skimdb.npmjs.com/registry | ||
snapshot: false | ||
supportsES6: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
generatorName: typescript-angular | ||
outputDir: samples/client/petstore/typescript-angular-v14-provided-in-root/builds/default | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-angular | ||
additionalProperties: | ||
ngVersion: 14.0.5 | ||
supportsES6: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
samples/client/petstore/typescript-angular-v14-oneOf/builds/default/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings | ||
dist |
203 changes: 203 additions & 0 deletions
203
samples/client/petstore/typescript-angular-v14-oneOf/builds/default/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
## @ | ||
|
||
### Building | ||
|
||
To install the required dependencies and to build the typescript sources run: | ||
``` | ||
npm install | ||
npm run build | ||
``` | ||
|
||
### publishing | ||
|
||
First build the package then run ```npm publish dist``` (don't forget to specify the `dist` folder!) | ||
|
||
### consuming | ||
|
||
Navigate to the folder of your consuming project and run one of next commands. | ||
|
||
_published:_ | ||
|
||
``` | ||
npm install @ --save | ||
``` | ||
|
||
_without publishing (not recommended):_ | ||
|
||
``` | ||
npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save | ||
``` | ||
|
||
_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ | ||
|
||
_using `npm link`:_ | ||
|
||
In PATH_TO_GENERATED_PACKAGE/dist: | ||
``` | ||
npm link | ||
``` | ||
|
||
In your project: | ||
``` | ||
npm link | ||
``` | ||
|
||
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. | ||
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround. | ||
Published packages are not effected by this issue. | ||
|
||
|
||
#### General usage | ||
|
||
In your Angular project: | ||
|
||
|
||
``` | ||
// without configuring providers | ||
import { ApiModule } from ''; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
ApiModule, | ||
// make sure to import the HttpClientModule in the AppModule only, | ||
// see https://github.com/angular/angular/issues/20575 | ||
HttpClientModule | ||
], | ||
declarations: [ AppComponent ], | ||
providers: [], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
``` | ||
// configuring providers | ||
import { ApiModule, Configuration, ConfigurationParameters } from ''; | ||
|
||
export function apiConfigFactory (): Configuration { | ||
const params: ConfigurationParameters = { | ||
// set configuration parameters here. | ||
} | ||
return new Configuration(params); | ||
} | ||
|
||
@NgModule({ | ||
imports: [ ApiModule.forRoot(apiConfigFactory) ], | ||
declarations: [ AppComponent ], | ||
providers: [], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
``` | ||
// configuring providers with an authentication service that manages your access tokens | ||
import { ApiModule, Configuration } from ''; | ||
|
||
@NgModule({ | ||
imports: [ ApiModule ], | ||
declarations: [ AppComponent ], | ||
providers: [ | ||
{ | ||
provide: Configuration, | ||
useFactory: (authService: AuthService) => new Configuration( | ||
{ | ||
basePath: environment.apiUrl, | ||
accessToken: authService.getAccessToken.bind(authService) | ||
} | ||
), | ||
deps: [AuthService], | ||
multi: false | ||
} | ||
], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
``` | ||
import { DefaultApi } from ''; | ||
|
||
export class AppComponent { | ||
constructor(private apiGateway: DefaultApi) { } | ||
} | ||
``` | ||
|
||
Note: The ApiModule is restricted to being instantiated once app wide. | ||
This is to ensure that all services are treated as singletons. | ||
|
||
#### Using multiple OpenAPI files / APIs / ApiModules | ||
In order to use multiple `ApiModules` generated from different OpenAPI files, | ||
you can create an alias name when importing the modules | ||
in order to avoid naming conflicts: | ||
``` | ||
import { ApiModule } from 'my-api-path'; | ||
import { ApiModule as OtherApiModule } from 'my-other-api-path'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
ApiModule, | ||
OtherApiModule, | ||
// make sure to import the HttpClientModule in the AppModule only, | ||
// see https://github.com/angular/angular/issues/20575 | ||
HttpClientModule | ||
] | ||
}) | ||
export class AppModule { | ||
|
||
} | ||
``` | ||
|
||
|
||
### Set service base path | ||
If different than the generated base path, during app bootstrap, you can provide the base path to your service. | ||
|
||
``` | ||
import { BASE_PATH } from ''; | ||
|
||
bootstrap(AppComponent, [ | ||
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' }, | ||
]); | ||
``` | ||
or | ||
|
||
``` | ||
import { BASE_PATH } from ''; | ||
|
||
@NgModule({ | ||
imports: [], | ||
declarations: [ AppComponent ], | ||
providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
|
||
#### Using @angular/cli | ||
First extend your `src/environments/*.ts` files by adding the corresponding base path: | ||
|
||
``` | ||
export const environment = { | ||
production: false, | ||
API_BASE_PATH: 'http://127.0.0.1:8080' | ||
}; | ||
``` | ||
|
||
In the src/app/app.module.ts: | ||
``` | ||
import { BASE_PATH } from ''; | ||
import { environment } from '../environments/environment'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ ], | ||
providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule { } | ||
``` |
31 changes: 31 additions & 0 deletions
31
samples/client/petstore/typescript-angular-v14-oneOf/builds/default/api.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core'; | ||
import { Configuration } from './configuration'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
import { DefaultService } from './api/default.service'; | ||
|
||
@NgModule({ | ||
imports: [], | ||
declarations: [], | ||
exports: [], | ||
providers: [] | ||
}) | ||
export class ApiModule { | ||
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<ApiModule> { | ||
return { | ||
ngModule: ApiModule, | ||
providers: [ { provide: Configuration, useFactory: configurationFactory } ] | ||
}; | ||
} | ||
|
||
constructor( @Optional() @SkipSelf() parentModule: ApiModule, | ||
@Optional() http: HttpClient) { | ||
if (parentModule) { | ||
throw new Error('ApiModule is already loaded. Import in your base AppModule only.'); | ||
} | ||
if (!http) { | ||
throw new Error('You need to import the HttpClientModule in your AppModule! \n' + | ||
'See also https://github.com/angular/angular/issues/20575'); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
samples/client/petstore/typescript-angular-v14-oneOf/builds/default/api/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './default.service'; | ||
import { DefaultService } from './default.service'; | ||
export const APIS = [DefaultService]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to keep only this one, and remove the other configs, since nothing related to oneof or provided-in changes in angular 14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for the feedback. I'm happy to remove the test config, but is this not part of Angular 14 regression tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can keep it and delete it for older angular versions if you want. this way, we have less code to review when something changes. and these type of variations are not version-specific.
to enable the build/test to be run as part of the CI, you need to add it here:
openapi-generator/pom.xml
Line 1212 in 186ad25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have removed
bin/configs/typescript-angular-v14-oneOf.yaml
bin/configs/typescript-angular-v14-provided-in-any.yaml
bin/configs/typescript-angular-v14-provided-in-root-with-npm.yaml