ng-openapi 0.2.22 → 0.3.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.
- package/README.md +41 -17
- package/cli.cjs +1199 -857
- package/index.d.ts +529 -83
- package/index.js +1265 -906
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,20 +101,24 @@ ng-openapi -i ./swagger.json -o ./src/api --date-type string
|
|
|
101
101
|
|
|
102
102
|
### Required Fields
|
|
103
103
|
|
|
104
|
-
- `input` - Path to your Swagger/OpenAPI specification
|
|
104
|
+
- `input` - Path or URL to your Swagger/OpenAPI specification (`.json`, `.yaml`, `.yml`)
|
|
105
105
|
- `output` - Output directory for generated files
|
|
106
|
+
- `options.dateType` - How to handle date types: `'string'` or `'Date'`
|
|
107
|
+
- `options.enumStyle` - Enum generation style: `'enum'` or `'union'`
|
|
106
108
|
|
|
107
109
|
### Optional Fields
|
|
108
110
|
|
|
109
|
-
- `
|
|
110
|
-
- `
|
|
111
|
-
- `
|
|
112
|
-
- `generateServices` - Generate Angular services (default: `true`)
|
|
113
|
-
- `customHeaders` - Headers to add to all HTTP requests
|
|
114
|
-
- `responseTypeMapping` - Map content types to Angular HttpClient response types
|
|
115
|
-
- `customizeMethodName` - Function to customize generated method names
|
|
116
|
-
- `useSingleRequestParameter` - Generate one request object parameter per method instead of positional parameters (default: `false`)
|
|
111
|
+
- `clientName` - Unique identifier for this client; names the generated provider function and tokens (default: `'default'`)
|
|
112
|
+
- `validateInput` - Custom acceptance check `(spec) => boolean`; returning `false` aborts generation
|
|
113
|
+
- `plugins` - Plugin generator classes (e.g. `HttpResourcePlugin`, `ZodPlugin`), run after core generation
|
|
117
114
|
- `compilerOptions` - TypeScript compiler options for code generation
|
|
115
|
+
- `options.generateServices` - Generate Angular services (default: `true`)
|
|
116
|
+
- `options.generateEnumBasedOnDescription` - Parse enum values from description field (default: `false`)
|
|
117
|
+
- `options.validation` - `{ response?: boolean }`; adds a `parse` hook to generated methods for response validation
|
|
118
|
+
- `options.customHeaders` - Headers to add to all HTTP requests
|
|
119
|
+
- `options.responseTypeMapping` - Map content types to Angular HttpClient response types
|
|
120
|
+
- `options.customizeMethodName` - Function to customize generated method names
|
|
121
|
+
- `options.useSingleRequestParameter` - Generate one request object parameter per method instead of positional parameters (default: `false`)
|
|
118
122
|
|
|
119
123
|
## Generated Files Structure
|
|
120
124
|
|
|
@@ -128,12 +132,16 @@ output/
|
|
|
128
132
|
├── tokens/
|
|
129
133
|
│ └── index.ts # Injection tokens
|
|
130
134
|
├── utils/
|
|
131
|
-
│ ├──
|
|
132
|
-
│
|
|
135
|
+
│ ├── base-interceptor.ts # Client-scoped interceptor routing
|
|
136
|
+
│ ├── date-transformer.ts # Date interceptor (dateType: "Date" only)
|
|
137
|
+
│ ├── file-download.ts # File download helpers
|
|
138
|
+
│ └── http-params-builder.ts # Query-param serialization
|
|
133
139
|
├── providers.ts # Provider functions for easy setup
|
|
134
140
|
└── index.ts # Main exports
|
|
135
141
|
```
|
|
136
142
|
|
|
143
|
+
See [Generated Output](https://ng-openapi.dev/guide/generated-code) for what every file does.
|
|
144
|
+
|
|
137
145
|
## Angular Integration
|
|
138
146
|
|
|
139
147
|
### 🚀 Easy Setup (Recommended)
|
|
@@ -143,12 +151,12 @@ The simplest way to integrate ng-openapi is using the provider function:
|
|
|
143
151
|
```typescript
|
|
144
152
|
// In your app.config.ts
|
|
145
153
|
import { ApplicationConfig } from "@angular/core";
|
|
146
|
-
import {
|
|
154
|
+
import { provideDefaultClient } from "./api/providers";
|
|
147
155
|
|
|
148
156
|
export const appConfig: ApplicationConfig = {
|
|
149
157
|
providers: [
|
|
150
158
|
// One-line setup with automatic interceptor configuration
|
|
151
|
-
|
|
159
|
+
provideDefaultClient({
|
|
152
160
|
basePath: "https://api.example.com",
|
|
153
161
|
}),
|
|
154
162
|
// other providers...
|
|
@@ -156,6 +164,8 @@ export const appConfig: ApplicationConfig = {
|
|
|
156
164
|
};
|
|
157
165
|
```
|
|
158
166
|
|
|
167
|
+
> The provider function is named after your `clientName` (e.g. `clientName: "PetStore"` → `providePetStoreClient`); without a `clientName` it is `provideDefaultClient`.
|
|
168
|
+
|
|
159
169
|
That's it! This automatically configures:
|
|
160
170
|
|
|
161
171
|
- ✅ BASE_PATH token
|
|
@@ -165,14 +175,15 @@ That's it! This automatically configures:
|
|
|
165
175
|
|
|
166
176
|
```typescript
|
|
167
177
|
// Disable date transformation
|
|
168
|
-
|
|
178
|
+
provideDefaultClient({
|
|
169
179
|
basePath: "https://api.example.com",
|
|
170
180
|
enableDateTransform: false,
|
|
171
181
|
});
|
|
172
182
|
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
basePath:
|
|
183
|
+
// Client-specific interceptors (classes, not instances)
|
|
184
|
+
provideDefaultClient({
|
|
185
|
+
basePath: "https://api.example.com",
|
|
186
|
+
interceptors: [AuthInterceptor, LoggingInterceptor],
|
|
176
187
|
});
|
|
177
188
|
```
|
|
178
189
|
|
|
@@ -220,3 +231,16 @@ Add these scripts to your `package.json`:
|
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
233
|
```
|
|
234
|
+
|
|
235
|
+
## Using AI Assistants?
|
|
236
|
+
|
|
237
|
+
Point your AI coding assistant (Claude Code, Cursor, Copilot, …) at
|
|
238
|
+
<https://ng-openapi.dev/llms.txt> — it contains usage rules that prevent the
|
|
239
|
+
most common integration mistakes, plus links into the full documentation
|
|
240
|
+
(<https://ng-openapi.dev/llms-full.txt> for everything in one file).
|
|
241
|
+
|
|
242
|
+
## Contributing
|
|
243
|
+
|
|
244
|
+
Contributions are welcome — see [CONTRIBUTING.md](https://github.com/ng-openapi/ng-openapi/blob/main/CONTRIBUTING.md)
|
|
245
|
+
for setup and test workflows, and [ARCHITECTURE.md](https://github.com/ng-openapi/ng-openapi/blob/main/ARCHITECTURE.md)
|
|
246
|
+
for how the generation pipeline is structured and where new code should go.
|