Skip to content

Angular client #1635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
378 changes: 378 additions & 0 deletions packages/client-angular/CHANGELOG.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions packages/client-angular/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Hey API

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions packages/client-angular/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div align="center">
<img alt="Hey API logo" height="150" src="https://heyapi.dev/images/logo-300w.png" width="150">
<h1 align="center"><b>Fetch API Client</b></h1>
<p align="center">🚀 Fetch API client for `@hey-api/openapi-ts` codegen.</p>
</div>

[Live demo](https://stackblitz.com/edit/hey-api-client-angular-example?file=openapi-ts.config.ts,src%2Fclient%2Fschemas.gen.ts,src%2Fclient%2Fsdk.gen.ts,src%2Fclient%2Ftypes.gen.ts,src%2FApp.tsx)

## Features

- seamless integration with `@hey-api/openapi-ts` ecosystem
- type-safe response data and errors
- response data validation and transformation
- access to the original request and response
- granular request and response customization options
- minimal learning curve thanks to extending the underlying technology
- support bundling inside the generated output
- [platform](https://heyapi.dev/openapi-ts/integrations) for automating codegen builds

## Platform

Our platform for OpenAPI specifications is now available. Automatically update your code when the APIs it depends on change. [Find out more](https://heyapi.dev/openapi-ts/integrations).

## Documentation

Please visit our [website](https://heyapi.dev/) for documentation, guides, migrating, and more.

## Sponsors

Love Hey API? Become our [sponsor](https://github.com/sponsors/hey-api).

<p>
<a href="https://kutt.it/pkEZyc" target="_blank">
<img alt="Stainless logo" height="50" src="https://heyapi.dev/images/stainless-logo-wordmark-480w.jpeg" />
</a>
</p>

## Migration Guides

[OpenAPI Typescript Codegen](https://heyapi.dev/openapi-ts/migrating#openapi-typescript-codegen)
78 changes: 78 additions & 0 deletions packages/client-angular/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@hey-api/client-angular",
"version": "0.0.0",
"description": "🚀 Angular API client for `@hey-api/openapi-ts` codegen.",
"homepage": "https://heyapi.dev/",
"repository": {
"type": "git",
"url": "git+https://github.com/hey-api/openapi-ts.git"
},
"bugs": {
"url": "https://github.com/hey-api/openapi-ts/issues"
},
"license": "MIT",
"author": {
"email": "[email protected]",
"name": "Hey API",
"url": "https://heyapi.dev"
},
"funding": "https://github.com/sponsors/hey-api",
"keywords": [
"client",
"fetch",
"http",
"javascript",
"openapi",
"react",
"rest",
"svelte",
"swagger",
"typescript",
"vue"
],
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"sideEffects": false,
"files": [
"dist",
"LICENSE.md",
"src"
],
"scripts": {
"build": "tsup && rollup -c && pnpm check-exports",
"check-exports": "attw --pack .",
"dev": "tsup --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --coverage",
"test:update": "vitest watch --update",
"test:watch": "vitest watch",
"test": "vitest run",
"typecheck": "vitest --typecheck --watch=false"
},
"devDependencies": {
"@angular/common": "^19.2.0",
"@angular/core": "^19.2.0",
"@hey-api/client-core": "workspace:*",
"rxjs": "~7.8.1"
},
"peerDependencies": {
"@angular/common": "^19.2.0",
"@angular/core": "^19.2.0",
"rxjs": "~7.8.1"
}
}
30 changes: 30 additions & 0 deletions packages/client-angular/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path from 'node:path';

import { defineConfig } from 'rollup';
import dts from 'rollup-plugin-dts';

const files = ['index.d.ts', 'index.d.cts'];

export default files.map((file) =>
defineConfig({
external: (id) => {
const normalizedId = id.split(path.sep).join('/');
if (normalizedId === '@hey-api/client-core') {
return false;
}
return (
!normalizedId.startsWith('/') && !/^[a-zA-Z]:\//.test(normalizedId)
);
},
input: `./dist/${file}`,
output: {
file: `./dist/${file}`,
format: 'es',
},
plugins: [
dts({
respectExternal: true,
}),
],
}),
);
50 changes: 50 additions & 0 deletions packages/client-angular/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it } from 'vitest';

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

describe('buildUrl', () => {
const client = createClient();

const scenarios: {
options: Parameters<typeof client.buildUrl>[0];
url: string;
}[] = [
{
options: {
url: '',
},
url: '/',
},
{
options: {
url: '/foo',
},
url: '/foo',
},
{
options: {
path: {
fooId: 1,
},
url: '/foo/{fooId}',
},
url: '/foo/1',
},
{
options: {
path: {
fooId: 1,
},
query: {
bar: 'baz',
},
url: '/foo/{fooId}',
},
url: '/foo/1?bar=baz',
},
];

it.each(scenarios)('returns $url', ({ options, url }) => {
expect(client.buildUrl(options)).toBe(url);
});
});
Loading
Loading