You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generates OpenAPI client for TypeScript. Extremely configurable.
3
+
A powerful, highly customizable TypeScript client generator for OpenAPI specifications. Build type-safe API clients for any environment with unprecedented control over generated code.
4
4
5
5
## Features
6
6
7
-
1. Generates TypeScript models for all the schemas in the OpenAPI document in a form of interfaces and type aliases.
8
-
2. Generates TypeScript services for all the operations in the OpenAPI document.
9
-
3. Generates a client class that combines all the services.
10
-
4. Uses `fetch` API for making HTTP requests by default, but can be configured to use any other HTTP client.
11
-
5. May generate validation for the API responses if configured.
7
+
-**Fully-typed**: Generates TypeScript models for all schemas and operations
8
+
-**Environment-agnostic**: Generated clients work everywhere - browsers, Node.js, Sandbox environments, and more
9
+
-**Validation support**: Optional runtime validation for requests and responses
10
+
-**Highly customizable**: Control everything from naming conventions to file structure
11
+
-**Production-ready**: Used to build enterprise-grade API clients for Atlassian products
12
+
-**Flexible schema loading**: Load schemas from YAML or JSON, locally or remotely
13
+
-**Modern specification support**: Full support for OpenAPI 3.0 and 3.1
14
+
15
+
## Real-world Examples
16
+
17
+
Built by the team behind production API clients:
18
+
-`@resolution/jira-api-client` - Fully-typed Jira API client
19
+
-`@resolution/confluence-api-client` - Fully-typed Confluence API client
20
+
21
+
These clients support multiple environments (Atlassian Connect Server/Client, Atlassian Forge Backend/Frontend) from a single codebase - showcasing the flexibility of this generator.
const result =awaitclient.pet.getPetById({petId: '123'});
154
+
// In case of validation error, the error will be sent to Sentry, and the execution will continue.
107
155
```
108
156
109
-
##What is configurable?
157
+
### Custom HTTP Client
110
158
111
-
1. Validation of the API responses. See [validation](docs/interfaces/openapi_client.OpenApiClientGeneratorConfig.md#validation).
112
-
2. Default base URL for the API. See [client.baseUrl](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigClient.md#baseUrl).
113
-
3. Leading and trailing comments for the files. See [comments](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigComments.md).
114
-
4. File naming conventions. I.e. [models.filenameFormat](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigModels.md#filenameFormat).
115
-
5. Output directory structure. I.e. [models.relativeDirPath](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigModels.md#relativeDirPath).
116
-
6. JSDoc generation. I.e. [models.generateJsDoc](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigModels.md#generateJsDoc).
117
-
7. Many more. See the documentation below.
159
+
```ts
160
+
const client =newPetStoreApiClient({
161
+
fetch: customFetchImplementation,
162
+
baseUrl: 'https://custom-petstore.example.com',
163
+
middlewares: [
164
+
request=> {
165
+
request.headers['X-Custom-Header'] ='value';
166
+
returnrequest;
167
+
}
168
+
]
169
+
});
170
+
```
171
+
172
+
### Retry Logic
173
+
174
+
You can implement custom retry logic for your API client. This is useful for handling transient errors or rate limiting.
175
+
176
+
```ts
177
+
const client =newPetStoreApiClient({
178
+
shouldRetryOnError: (error, attempt) => {
179
+
if (error.status>=500&&attempt<3) {
180
+
returnnewPromise((resolve) => {
181
+
setTimeout(() =>resolve(true), 100*attempt);
182
+
});
183
+
}
184
+
returnfalse;
185
+
}
186
+
});
187
+
```
188
+
189
+
### Deprecated API Operations
190
+
191
+
In case if an operation is marked as deprecated in OpenAPI spec, the generator will add a `@deprecated` tag to the generated method.
192
+
When calling a deprecated method, a warning will be logged to the console.
193
+
You can customize the logging behavior by providing a custom `logDeprecationWarning` function in the client configuration.
194
+
195
+
```ts
196
+
const client =newPetStoreApiClient({
197
+
logDeprecationWarning: ({
198
+
operationName,
199
+
path,
200
+
method
201
+
}) => {
202
+
Sentry.captureMessage(`Deprecated API call: ${operationName} (${method.toUpperCase()} ${path})`);
203
+
}
204
+
});
205
+
```
206
+
207
+
## Customization Options
208
+
209
+
The generator offers unmatched customization:
210
+
211
+
1.**File Structure Control**
212
+
- Custom directory structure
213
+
- Configurable file naming patterns
214
+
- Grouped or flat output
215
+
216
+
2.**Naming Conventions**
217
+
- Model/interface naming patterns
218
+
- Property naming transformation
219
+
- Service method naming
220
+
221
+
3.**Documentation**
222
+
- JSDoc generation with wordwrap control
223
+
- Custom section ordering
224
+
- Description formatting
225
+
- Custom tags and annotations
226
+
227
+
4.**Client Features**
228
+
- Response validation
229
+
- Error handling strategies
230
+
- Binary data processing
231
+
- Custom fetch implementation
232
+
- Custom request/response interceptors
233
+
- Custom retry logic
118
234
119
235
## Documentation
120
236
121
-
The most important interface for now would be the [OpenApiClientGeneratorConfig](docs/interfaces/openapi_client.OpenApiClientGeneratorConfig.md) interface. It contains all the configuration options for the OpenAPI Client Generator.
237
+
For full configuration options, see:
238
+
239
+
-[OpenApiClientGeneratorConfig](docs/interfaces/openapi_client.OpenApiClientGeneratorConfig.md) - Main configuration interface
240
+
-[Models Configuration](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigModels.md) - Model generation options
241
+
-[Services Configuration](docs/interfaces/openapi_client.OpenApiClientGeneratorConfigServices.md) - Service generation options
Types are exported as part of three modules, depending on the area of application:
244
+
## Modules
124
245
125
-
1.[`api-typescript-generator`](docs/modules/index.md) - The main module that exports the common API Generator Configuration types.
126
-
2.[`api-typescript-generator/openapi-client`](docs/modules/openapi_client.md) - The module that exports the OpenAPI Client Generator Configuration types.
127
-
3.[`api-typescript-generator/openapi`](docs/modules/openapi.md) - The module that exports the OpenAPI Document types.
246
+
Types are exported from three modules:
128
247
129
-
At the moment only types are exported to be used with CLI. Callable API is planned for the future.
248
+
1.[`api-typescript-generator`](docs/modules/index.md) - Common API Generator types
0 commit comments