Skip to content

Commit da64fdd

Browse files
committed
docs(README): usage and compatibility
closes #48 Signed-off-by: Vojtech Masek <[email protected]>
1 parent eca03c3 commit da64fdd

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

README.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@
1111
# api-client-generator
1212
Angular REST API client generator from Swagger YAML or JSON file with camel case settings
1313

14+
Generated files are compatible with Angular 6 (should be compatible with 5 version too). RxJS imports are targeted for version 6.
15+
1416
# Description
1517
This package generates a Angular TypeScript classes from a Swagger v2.0 specification file. The code is generated using Mustache templates.
1618

1719
The generated service class uses new [HttpClient](https://angular.io/guide/http) module of Angular (introduced in version 4.3).
1820

19-
# Installation
21+
# Compatibility
2022

21-
### Global usage:
23+
- **Angular 6** (should also work with 5 and 4.3+)
24+
- **RxJS 6** (Observable imports)
25+
- in case of rxjs <6 update or rewrite the rxjs import to match older version
2226

23-
`[sudo] yarn global add api-client-generator`
27+
# Installation
2428

25-
or
29+
### Global usage:
2630

2731
`[sudo] npm install -g api-client-generator`
2832

@@ -32,11 +36,7 @@ This command will generate API client described in swagger.json file to ./output
3236

3337
### Local usage
3438

35-
`yarn add api-client-generator`
36-
37-
or
38-
39-
`npm install api-client-generator`
39+
`npm install api-client-generator --save-dev`
4040

4141
- for quick usage create run script in your `package.json` scripts
4242
```
@@ -53,36 +53,26 @@ or
5353
- `s` - path to the swagger file (yaml or json)
5454
- `o` - path where the generated files should be emitted
5555

56-
# Generated structure
57-
58-
- if you are interested on how will the generated client with models look like, take a look in a `example/` folder
59-
60-
```
61-
output
62-
├─ models
63-
│ ├─ some.enum.ts
64-
│ ├─ some.model.ts
65-
│ │ ...
66-
│ ├─ another.model.ts
67-
│ └─ index.ts
68-
├─ api-client.service.ts
69-
└─ index.ts
70-
```
71-
7256
# How to use generated client
7357

7458
1. import the `APIClientModule` in your `app.module.ts` (main module)
7559
- domain and configuration should be passed to module imports using `.forRoot` method
7660
- options and domain are optional
7761
- when domain is not passed, host property form swagger file is used as default
7862
- if host property is not defined `window.href` with current port is used instead
63+
7964
```typescript
8065
@NgModule({
8166
imports: [
67+
/* Default configuration and all of it's properties is optional */
8268
APIClientModule.forRoot({
8369
domain: 'https://api.url', // or use value defined in environment `environment.apiUrl`
70+
headers: {myCustomHeader: 'this will appear in every request as one of the headers'},
71+
params: {someParam: 'customParam'},
8472
}),
8573
/* ... other imports */
74+
HttpClientModule, // <<= this is very important import
75+
// API client relies on HttpClient module and will throw and provider error if not there
8676
],
8777
/* ... other stuff */
8878
})
@@ -113,8 +103,52 @@ export class MyComponent {
113103
}
114104
```
115105

106+
# Generated structure
107+
108+
- if you are interested on how will the generated client with models look like, take a look in a `example/` folder
109+
110+
```
111+
output
112+
├─ models
113+
│ ├─ some.enum.ts
114+
│ ├─ some.model.ts
115+
│ │ ...
116+
│ ├─ another.model.ts
117+
│ └─ index.ts
118+
├─ api-client.service.ts
119+
└─ index.ts
120+
```
121+
122+
# Common problems
123+
124+
### HttpClient not provided
125+
126+
This or very similar error means that you forgot to import `HttpClientModule` in your root module
127+
```
128+
StaticInjectorError(AppModule)[APIClient -> HttpClient]:
129+
StaticInjectorError(Platform: core)[APIClient -> HttpClient]:
130+
NullInjectorError: No provider for HttpClient!
131+
```
132+
133+
Fix:
134+
- add `HttpClientModule` to your root module (see NgModule imports in [usage](https://github.com/flowup/api-client-generator#how-to-use-generated-client))
135+
136+
# Problem reporting and contributions
137+
138+
Please report any problems you have and issues you find so they can be resolved.
139+
140+
Feel free to discuss desired improvements or functionality in issues. Afterwards the pull requests are very welcome.
141+
116142
-------
117143

118-
*Inspired by [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen)*
144+
.
145+
146+
.
147+
148+
.
149+
150+
.
151+
152+
<small>*Inspired by [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen)*</small>
119153

120-
*Generator based on [angular4-swagger-client-generator](https://github.com/lotjomik/angular4-swagger-client-generator)*
154+
<small>*Generator based on [angular4-swagger-client-generator](https://github.com/lotjomik/angular4-swagger-client-generator)*</small>

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"rest",
2828
"angular6",
2929
"angular5",
30-
"angular4",
3130
"angular",
3231
"ngx",
3332
"scaffolding",

0 commit comments

Comments
 (0)