Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-news-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

feat(plugin): add `@angular/common` plugin
2 changes: 1 addition & 1 deletion docs/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default defineConfig({
},
{
link: '/openapi-ts/clients/angular',
text: 'Angular <span data-soon>soon</span>',
text: 'Angular',
},
{
link: '/openapi-ts/clients/effect',
Expand Down
139 changes: 135 additions & 4 deletions docs/openapi-ts/clients/angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,143 @@ title: Angular client
description: Angular client for Hey API. Compatible with all our features.
---

# Angular <span data-soon>soon</span>
<script setup lang="ts">
import { embedProject } from '../../embed'
</script>

<FeatureStatus issueNumber=1072 name="Angular" />
<Heading>
<h1>Angular</h1>
<VersionLabel value="v1" />
<ExperimentalLabel />
</Heading>

### About

[Angular](https://angular.dev/) is a web framework that empowers developers to build fast, reliable applications.
[Angular](https://angular.dev/) is a web framework for building fast, reliable applications.

<!--@include: ../../partials/sponsors.md-->
::: warning Requirements
**Angular 19+** is required for full feature support, including the experimental `httpResource` API.
:::

::: tip First Release
Angular client support is in its first release. Share your feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues).
:::

## Features

- Modern Angular patterns with signals and reactive programming
- Dependency injection with `@Injectable()` decorators
- Type-safe response data and errors
- Experimental **httpResource** support (Angular 19+)

## Usage

Add `@hey-api/client-angular` to your plugins:

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
'@hey-api/client-angular', // [!code ++]
],
};
```

After generating the client, integrate it with Angular's `HttpClient` by adding `provideHeyApiClient` to your app configuration:

```ts
import { provideHttpClient, withFetch } from '@angular/common/http';
import { provideHeyApiClient, client } from './client/client.gen';

export const appConfig = {
providers: [
provideHttpClient(withFetch()),
provideHeyApiClient(client), // [!code ++]
],
};
```

## Configuration

### Injectable Classes Configuration

You can configure the SDK to generate injectable classes by setting the `asClass` option to `true` in your plugin configuration. This will generate Angular services with `@Injectable()` decorators, making them available for dependency injection.

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
'@hey-api/client-angular',
{
name: '@hey-api/sdk',
asClass: true, // [!code ++]
},
],
};
```

::: warning
While this feature is available, it is **discouraged** as it can negatively impact tree shaking, leading to larger bundle sizes. Consider using other configuration options for better optimization.
:::

### Angular Providers

Use `provideHeyApiClient` to integrate the generated client with Angular's `HttpClient`:

```ts
import { provideHttpClient, withFetch } from '@angular/common/http';
import { provideHeyApiClient, client } from './client/client.gen';

export const appConfig = {
providers: [provideHttpClient(withFetch()), provideHeyApiClient(client)],
};
```

### `createClient()`

Manually create a client instance for custom configurations:

```ts
import { createClient } from './client/client';

const myClient = createClient({
baseUrl: 'https://example.com',
});
```

## Plugin Configuration

The `@hey-api/client-angular` plugin supports options like `throwOnError` for error handling:

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
{
name: '@hey-api/client-angular',
throwOnError: false,
},
],
};
```

## httpResource

Angular 19 introduces a experimental api &ndash; `httpResource`, a reactive approach to data loading. Enable it with:

```js
export default {
plugins: [
{
name: '@angular/common',
httpResource: {
enabled: true,
asClass: true,
},
},
],
};
```
17 changes: 17 additions & 0 deletions examples/openapi-ts-angular-resource/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single
ij_typescript_use_double_quotes = false

[*.md]
max_line_length = off
trim_trailing_whitespace = false
42 changes: 42 additions & 0 deletions examples/openapi-ts-angular-resource/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
4 changes: 4 additions & 0 deletions examples/openapi-ts-angular-resource/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}
20 changes: 20 additions & 0 deletions examples/openapi-ts-angular-resource/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}
42 changes: 42 additions & 0 deletions examples/openapi-ts-angular-resource/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}
59 changes: 59 additions & 0 deletions examples/openapi-ts-angular-resource/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Angular

This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.15.

## Development server

To start a local development server, run:

```bash
ng serve
```

Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.

## Code scaffolding

Angular CLI includes powerful code scaffolding tools. To generate a new component, run:

```bash
ng generate component component-name
```

For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:

```bash
ng generate --help
```

## Building

To build the project run:

```bash
ng build
```

This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.

## Running unit tests

To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:

```bash
ng test
```

## Running end-to-end tests

For end-to-end (e2e) testing, run:

```bash
ng e2e
```

Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.

## Additional Resources

For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
Loading
Loading