@ng-openapi/http-resource 0.0.2-pr-9-feature-http-resource-e6134bb.0

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.
Files changed (6) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/index.cjs +3788 -0
  4. package/index.d.ts +221 -0
  5. package/index.js +3749 -0
  6. package/package.json +88 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tareq Jami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ <div align="center">
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>Angular OpenAPI Client Generator</b></h1>
4
+ <p align="center">πŸ’ͺ Made with ❀️ by Angular Devs for Angular Devs</p>
5
+ </div>
6
+
7
+
8
+ <p align="center">
9
+ <a href="https://stackblitz.com/@Mr-Jami/collections/ng-openapi-examples">⚑Examples</a>
10
+ <span>&nbsp;β€’&nbsp;</span>
11
+ <a href="https://ng-openapi.dev/">πŸ“Documentation</a>
12
+ <span>&nbsp;β€’&nbsp;</span>
13
+ <a href="https://github.com/ng-openapi/ng-openapi/issues">πŸ›Issues</a>
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://www.npmjs.com/package/ng-openapi" rel="nofollow"><img src="https://img.shields.io/npm/v/ng-openapi.svg" alt="npm version"></a>
18
+ <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
+ <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
+ <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
+ </p>
24
+ <br/>
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install ng-openapi --save-dev
30
+ # or
31
+ yarn add ng-openapi --dev
32
+ ```
33
+
34
+ ## CLI Usage
35
+
36
+ ### Using a Configuration File (Recommended)
37
+
38
+ Create a configuration file (e.g., `openapi.config.ts`):
39
+
40
+ ```typescript
41
+ import { GeneratorConfig } from 'ng-openapi';
42
+
43
+ const config: GeneratorConfig = {
44
+ input: './swagger.json',
45
+ output: './src/api',
46
+ options: {
47
+ dateType: 'Date',
48
+ enumStyle: 'enum',
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;
68
+ ```
69
+
70
+ Then run:
71
+
72
+ ```bash
73
+ # Direct command
74
+ 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
+ ```
136
+
137
+ ## Angular Integration
138
+
139
+ ### πŸš€ Easy Setup (Recommended)
140
+
141
+ The simplest way to integrate ng-openapi is using the provider function:
142
+
143
+ ```typescript
144
+ // In your app.config.ts
145
+ import { ApplicationConfig } from '@angular/core';
146
+ import { provideNgOpenapi } from './api/providers';
147
+
148
+ export const appConfig: ApplicationConfig = {
149
+ providers: [
150
+ // One-line setup with automatic interceptor configuration
151
+ provideNgOpenapi({
152
+ basePath: 'https://api.example.com'
153
+ }),
154
+ // other providers...
155
+ ]
156
+ };
157
+ ```
158
+
159
+ That's it! This automatically configures:
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
180
+
181
+ ```typescript
182
+ import { Component, inject } from '@angular/core';
183
+ import { toSignal } from '@angular/core/rxjs-interop';
184
+ import { UserService } from './api/services';
185
+ import { User } from './api/models';
186
+
187
+ @Component({
188
+ selector: 'app-users',
189
+ template: `...`
190
+ })
191
+ export class UsersComponent {
192
+ private readonly userService = inject(UserService);
193
+ readonly users = toSignal(this.userService.getUsers());
194
+ }
195
+ ```
196
+
197
+ ## File Download Example
198
+
199
+ ```typescript
200
+ import { Component, inject } from '@angular/core';
201
+ import { downloadFileOperator } from './api/utils/file-download';
202
+
203
+ export class ReportComponent {
204
+ private readonly reportService = inject(ReportService);
205
+
206
+ downloadReport() {
207
+ this.reportService.getReport('pdf', { reportId: 123 })
208
+ .pipe(
209
+ downloadFileOperator('report.pdf')
210
+ )
211
+ .subscribe();
212
+ }
213
+ }
214
+ ```
215
+
216
+ ## Package.json Scripts
217
+
218
+ Add these scripts to your `package.json`:
219
+
220
+ ```json
221
+ {
222
+ "scripts": {
223
+ "generate:api": "ng-openapi -c openapi.config.ts"
224
+ }
225
+ }
226
+ ```