@ng-openapi/http-resource 0.0.2-pr-9-feature-http-resource-60347e6.0 β 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -162
- package/index.cjs +4 -4
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h1 align="center"><img src="https://raw.githubusercontent.com/ng-openapi/ng-openapi/HEAD/docs/public/ng-openapi-logo.svg" alt="Logo" style="height: 12vh; margin-bottom: 2vh;" width="160"></h1>
|
|
3
|
-
<h1 align="center"><b>
|
|
4
|
-
<p align="center"
|
|
3
|
+
<h1 align="center"><b>HTTP Resource Plugin</b></h1>
|
|
4
|
+
<p align="center">π Angular httpResource integration for ng-openapi</p>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
<p align="center">
|
|
9
8
|
<a href="https://stackblitz.com/@Mr-Jami/collections/ng-openapi-examples">β‘Examples</a>
|
|
10
9
|
<span> β’ </span>
|
|
@@ -14,213 +13,109 @@
|
|
|
14
13
|
</p>
|
|
15
14
|
|
|
16
15
|
<p align="center">
|
|
17
|
-
<a href="https://www.npmjs.com/package
|
|
16
|
+
<a href="https://www.npmjs.com/package/@ng-openapi/http-resource" rel="nofollow"><img src="https://img.shields.io/npm/v/@ng-openapi/http-resource.svg" alt="npm version"></a>
|
|
18
17
|
<a href="https://opensource.org/license/mit" rel="nofollow"><img src="https://img.shields.io/github/license/ng-openapi/ng-openapi" alt="MIT License"></a>
|
|
19
18
|
<a href="https://github.com/ng-openapi/ng-openapi/actions?query=branch%3Amain"><img src="https://img.shields.io/github/last-commit/ng-openapi/ng-openapi" alt="Last commit" /></a>
|
|
20
19
|
<a href="https://github.com/ng-openapi/ng-openapi/actions?query=branch%3Amain"><img src="https://github.com/ng-openapi/ng-openapi/actions/workflows/release.yml/badge.svg?event=push&branch=main" alt="CI status" /></a>
|
|
21
|
-
<a href="https://github.com/ng-openapi/ng-openapi/issues" rel="nofollow"><img src="https://img.shields.io/github/issues/ng-openapi/ng-openapi" alt="Number of open issues"></a>
|
|
22
|
-
<a href="https://ng-openapi.dev/" rel="nofollow"><img src="https://img.shields.io/netlify/cb7a0f09-de25-40bb-960c-d8bc95b34c5e" alt="Netlify"></a>
|
|
23
20
|
</p>
|
|
24
21
|
<br/>
|
|
25
22
|
|
|
23
|
+
## What is HTTP Resource Plugin?
|
|
24
|
+
|
|
25
|
+
The HTTP Resource plugin generates Angular services using the new **experimental** `httpResource` API instead of traditional `HttpClient`. This provides automatic caching, state management, and reactive data loading for your OpenAPI endpoints.
|
|
26
|
+
|
|
27
|
+
> β οΈ **Experimental Feature**: `httpResource` is still experimental in Angular. Use with caution in production.
|
|
28
|
+
|
|
26
29
|
## Installation
|
|
27
30
|
|
|
28
31
|
```bash
|
|
29
|
-
npm install ng-openapi --save-dev
|
|
30
|
-
# or
|
|
31
|
-
yarn add ng-openapi --dev
|
|
32
|
+
npm install @ng-openapi/http-resource ng-openapi --save-dev
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
### Using a Configuration File (Recommended)
|
|
35
|
+
## Quick Start
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
### 1. Configure Plugin
|
|
39
38
|
|
|
40
39
|
```typescript
|
|
40
|
+
// openapi.config.ts
|
|
41
41
|
import { GeneratorConfig } from 'ng-openapi';
|
|
42
|
+
import { HttpResourceGenerator } from '@ng-openapi/http-resource';
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
export default {
|
|
44
45
|
input: './swagger.json',
|
|
45
46
|
output: './src/api',
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
generateEnumBasedOnDescription: true,
|
|
50
|
-
generateServices: true,
|
|
51
|
-
customHeaders: {
|
|
52
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
53
|
-
'Accept': 'application/json'
|
|
54
|
-
},
|
|
55
|
-
responseTypeMapping: {
|
|
56
|
-
'application/pdf': 'blob',
|
|
57
|
-
'application/zip': 'blob',
|
|
58
|
-
'text/csv': 'text'
|
|
59
|
-
},
|
|
60
|
-
customizeMethodName: (operationId) => {
|
|
61
|
-
const parts = operationId.split('_');
|
|
62
|
-
return parts[parts.length - 1] || operationId;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default config;
|
|
47
|
+
clientName: 'NgOpenApi',
|
|
48
|
+
plugins: [HttpResourcePlugin],
|
|
49
|
+
} as GeneratorConfig;
|
|
68
50
|
```
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
### 2. Generate Resources
|
|
71
53
|
|
|
72
54
|
```bash
|
|
73
|
-
# Direct command
|
|
74
55
|
ng-openapi -c openapi.config.ts
|
|
75
|
-
|
|
76
|
-
# Or with the generate subcommand
|
|
77
|
-
ng-openapi generate -c openapi.config.ts
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Using Command Line Options
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
# Generate both types and services
|
|
84
|
-
ng-openapi -i ./swagger.json -o ./src/api
|
|
85
|
-
|
|
86
|
-
# Generate only types
|
|
87
|
-
ng-openapi -i ./swagger.json -o ./src/api --types-only
|
|
88
|
-
|
|
89
|
-
# Specify date type
|
|
90
|
-
ng-openapi -i ./swagger.json -o ./src/api --date-type string
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Command Line Options
|
|
94
|
-
|
|
95
|
-
- `-c, --config <path>` - Path to configuration file
|
|
96
|
-
- `-i, --input <path>` - Path to Swagger/OpenAPI specification file
|
|
97
|
-
- `-o, --output <path>` - Output directory (default: `./src/generated`)
|
|
98
|
-
- `--types-only` - Generate only TypeScript interfaces
|
|
99
|
-
- `--date-type <type>` - Date type to use: `string` or `Date` (default: `Date`)
|
|
100
|
-
|
|
101
|
-
## Configuration Options
|
|
102
|
-
|
|
103
|
-
### Required Fields
|
|
104
|
-
|
|
105
|
-
- `input` - Path to your Swagger/OpenAPI specification file
|
|
106
|
-
- `output` - Output directory for generated files
|
|
107
|
-
|
|
108
|
-
### Optional Fields
|
|
109
|
-
|
|
110
|
-
- `dateType` - How to handle date types: `'string'` or `'Date'` (default: `'Date'`)
|
|
111
|
-
- `enumStyle` - Enum generation style: `'enum'` or `'union'` (default: `'enum'`)
|
|
112
|
-
- `generateEnumBasedOnDescription` - Parse enum values from description field (default: `true`)
|
|
113
|
-
- `generateServices` - Generate Angular services (default: `true`)
|
|
114
|
-
- `customHeaders` - Headers to add to all HTTP requests
|
|
115
|
-
- `responseTypeMapping` - Map content types to Angular HttpClient response types
|
|
116
|
-
- `customizeMethodName` - Function to customize generated method names
|
|
117
|
-
- `compilerOptions` - TypeScript compiler options for code generation
|
|
118
|
-
|
|
119
|
-
## Generated Files Structure
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
output/
|
|
123
|
-
βββ models/
|
|
124
|
-
β βββ index.ts # TypeScript interfaces/types
|
|
125
|
-
βββ services/
|
|
126
|
-
β βββ index.ts # Service exports
|
|
127
|
-
β βββ *.service.ts # Angular services
|
|
128
|
-
βββ tokens/
|
|
129
|
-
β βββ index.ts # Injection tokens
|
|
130
|
-
βββ utils/
|
|
131
|
-
β βββ date-transformer.ts # Date transformation interceptor
|
|
132
|
-
β βββ file-download.ts # File download helpers
|
|
133
|
-
βββ providers.ts # Provider functions for easy setup
|
|
134
|
-
βββ index.ts # Main exports
|
|
135
56
|
```
|
|
136
57
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
### π Easy Setup (Recommended)
|
|
140
|
-
|
|
141
|
-
The simplest way to integrate ng-openapi is using the provider function:
|
|
58
|
+
### 3. Setup Providers
|
|
142
59
|
|
|
143
60
|
```typescript
|
|
144
|
-
//
|
|
61
|
+
// app.config.ts
|
|
145
62
|
import { ApplicationConfig } from '@angular/core';
|
|
146
|
-
import {
|
|
63
|
+
import { provideDefaultClient } from './api/providers';
|
|
147
64
|
|
|
148
65
|
export const appConfig: ApplicationConfig = {
|
|
149
66
|
providers: [
|
|
150
|
-
|
|
151
|
-
provideNgOpenapi({
|
|
67
|
+
provideNgOpenApiClient({
|
|
152
68
|
basePath: 'https://api.example.com'
|
|
153
|
-
})
|
|
154
|
-
// other providers...
|
|
69
|
+
})
|
|
155
70
|
]
|
|
156
71
|
};
|
|
157
72
|
```
|
|
158
73
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
- β
BASE_PATH token
|
|
162
|
-
- β
Date transformation interceptor (if using Date type)
|
|
163
|
-
|
|
164
|
-
### Advanced Provider Options
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
// Disable date transformation
|
|
168
|
-
provideNgOpenapi({
|
|
169
|
-
basePath: 'https://api.example.com',
|
|
170
|
-
enableDateTransform: false
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Async configuration
|
|
174
|
-
provideNgOpenapiAsync({
|
|
175
|
-
basePath: () => import('./config').then(c => c.apiConfig.baseUrl)
|
|
176
|
-
});
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## Using Generated Services
|
|
74
|
+
### 4. Use Generated Resources
|
|
180
75
|
|
|
181
76
|
```typescript
|
|
182
77
|
import { Component, inject } from '@angular/core';
|
|
183
|
-
import {
|
|
184
|
-
import { UserService } from './api/services';
|
|
185
|
-
import { User } from './api/models';
|
|
78
|
+
import { UsersResource } from './api/resources';
|
|
186
79
|
|
|
187
80
|
@Component({
|
|
188
81
|
selector: 'app-users',
|
|
189
|
-
template:
|
|
82
|
+
template: `
|
|
83
|
+
<div>
|
|
84
|
+
@if (users.isLoading()) {
|
|
85
|
+
<p>Loading...</p>
|
|
86
|
+
}
|
|
87
|
+
@if (users.error()) {
|
|
88
|
+
<p>Error: {{ users.error() }}</p>
|
|
89
|
+
}
|
|
90
|
+
@for (user of users.value(); track user.id) {
|
|
91
|
+
<div>{{ user.name }}</div>
|
|
92
|
+
}
|
|
93
|
+
</div>
|
|
94
|
+
`
|
|
190
95
|
})
|
|
191
96
|
export class UsersComponent {
|
|
192
|
-
private readonly
|
|
193
|
-
|
|
97
|
+
private readonly usersResource = inject(UsersResource);
|
|
98
|
+
|
|
99
|
+
// Automatic caching and reactive updates
|
|
100
|
+
readonly users = this.usersResource.getUsers();
|
|
194
101
|
}
|
|
195
102
|
```
|
|
196
103
|
|
|
197
|
-
##
|
|
104
|
+
## Generated Structure
|
|
198
105
|
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
.pipe(
|
|
209
|
-
downloadFileOperator('report.pdf')
|
|
210
|
-
)
|
|
211
|
-
.subscribe();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
106
|
+
```
|
|
107
|
+
src/api/
|
|
108
|
+
βββ models/ # TypeScript interfaces
|
|
109
|
+
βββ resources/ # HTTP Resource services
|
|
110
|
+
β βββ index.ts # Resource exports
|
|
111
|
+
β βββ *.resource.ts # Generated resources
|
|
112
|
+
βββ services/ # Traditional HttpClient services
|
|
113
|
+
βββ providers.ts # Provider functions
|
|
114
|
+
βββ index.ts # Main exports
|
|
214
115
|
```
|
|
215
116
|
|
|
216
|
-
##
|
|
217
|
-
|
|
218
|
-
Add these scripts to your `package.json`:
|
|
117
|
+
## Documentation
|
|
219
118
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"generate:api": "ng-openapi -c openapi.config.ts"
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
```
|
|
119
|
+
- π [Full Documentation](https://ng-openapi.dev/plugins/http-resource)
|
|
120
|
+
- π― [Angular httpResource Guide](https://angular.dev/guide/http/resource)
|
|
121
|
+
- π [Live Examples](https://stackblitz.com/@Mr-Jami/collections/ng-openapi-examples)
|
package/index.cjs
CHANGED
|
@@ -31,11 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
HttpResourceGenerator: () => HttpResourceGenerator,
|
|
35
34
|
HttpResourceIndexGenerator: () => HttpResourceIndexGenerator,
|
|
36
35
|
HttpResourceMethodBodyGenerator: () => HttpResourceMethodBodyGenerator,
|
|
37
36
|
HttpResourceMethodGenerator: () => HttpResourceMethodGenerator,
|
|
38
|
-
HttpResourceMethodParamsGenerator: () => HttpResourceMethodParamsGenerator
|
|
37
|
+
HttpResourceMethodParamsGenerator: () => HttpResourceMethodParamsGenerator,
|
|
38
|
+
HttpResourcePlugin: () => HttpResourceGenerator
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
@@ -3774,11 +3774,11 @@ return context.set(this.clientContextToken, '${this.config.clientName || "defaul
|
|
|
3774
3774
|
};
|
|
3775
3775
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3776
3776
|
0 && (module.exports = {
|
|
3777
|
-
HttpResourceGenerator,
|
|
3778
3777
|
HttpResourceIndexGenerator,
|
|
3779
3778
|
HttpResourceMethodBodyGenerator,
|
|
3780
3779
|
HttpResourceMethodGenerator,
|
|
3781
|
-
HttpResourceMethodParamsGenerator
|
|
3780
|
+
HttpResourceMethodParamsGenerator,
|
|
3781
|
+
HttpResourcePlugin
|
|
3782
3782
|
});
|
|
3783
3783
|
/*! Bundled license information:
|
|
3784
3784
|
|
package/index.d.ts
CHANGED
|
@@ -218,4 +218,4 @@ declare class HttpResourceMethodParamsGenerator {
|
|
|
218
218
|
private getResourceRawDataType;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
export {
|
|
221
|
+
export { HttpResourceIndexGenerator, HttpResourceMethodBodyGenerator, HttpResourceMethodGenerator, HttpResourceMethodParamsGenerator, HttpResourceGenerator as HttpResourcePlugin };
|
package/index.js
CHANGED
|
@@ -3735,11 +3735,11 @@ return context.set(this.clientContextToken, '${this.config.clientName || "defaul
|
|
|
3735
3735
|
}
|
|
3736
3736
|
};
|
|
3737
3737
|
export {
|
|
3738
|
-
HttpResourceGenerator,
|
|
3739
3738
|
HttpResourceIndexGenerator,
|
|
3740
3739
|
HttpResourceMethodBodyGenerator,
|
|
3741
3740
|
HttpResourceMethodGenerator,
|
|
3742
|
-
HttpResourceMethodParamsGenerator
|
|
3741
|
+
HttpResourceMethodParamsGenerator,
|
|
3742
|
+
HttpResourceGenerator as HttpResourcePlugin
|
|
3743
3743
|
};
|
|
3744
3744
|
/*! Bundled license information:
|
|
3745
3745
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-openapi/http-resource",
|
|
3
|
-
"version": "0.0.2
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "HTTP Resource plugin for ng-openapi - Angular HTTP utilities with caching and state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@angular/core": ">=19.2",
|
|
62
62
|
"@angular/common": ">=19.2",
|
|
63
|
-
"ng-openapi": ">=0.
|
|
63
|
+
"ng-openapi": ">=0.1",
|
|
64
64
|
"ts-morph": "*"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|