Skip to content

Commit 3ca8e94

Browse files
committed
docs: update
1 parent 7f76e4b commit 3ca8e94

File tree

3 files changed

+19
-54
lines changed

3 files changed

+19
-54
lines changed

docs/openapi-fetch/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ await client.PUT("/blogposts", {
4444

4545
:::
4646

47-
`data` and `error` are typechecked and expose their shapes to Intellisence in VS Code (and any other IDE with TypeScript support). Likewise, the request `body` will also typecheck its fields, erring if any required params are missing, or if there’s a type mismatch.
47+
`data` and `error` are typechecked and expose their shapes to Intellisense in VS Code (and any other IDE with TypeScript support). Likewise, the request `body` will also typecheck its fields, erring if any required params are missing, or if there’s a type mismatch.
4848

4949
`GET()`, `PUT()`, `POST()`, etc. are thin wrappers around the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (which you can [swap for any call](/openapi-fetch/api#create-client)).
5050

packages/openapi-fetch/README.md

+8-46
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _\* [Benchmarks are approximate](https://github.com/openapi-ts/openapi-typescrip
1414

1515
The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 5 kb package.
1616

17-
```ts [src/my-project.ts]
17+
```ts
1818
import createClient from "openapi-fetch";
1919
import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript
2020

@@ -36,9 +36,9 @@ await client.PUT("/blogposts", {
3636
});
3737
```
3838

39-
`data` and `error` are typechecked and expose their shapes to Intellisence in VS Code (and any other IDE with TypeScript support). Likewise, the request `body` will also typecheck its fields, erring if any required params are missing, or if there’s a type mismatch.
39+
`data` and `error` are typechecked and expose their shapes to Intellisense in VS Code (and any other IDE with TypeScript support). Likewise, the request `body` will also typecheck its fields, erring if any required params are missing, or if there’s a type mismatch.
4040

41-
`GET()`, `PUT()`, `POST()`, etc. are thin wrappers around the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (which you can [swap for any call](/openapi-fetch/api#create-client)).
41+
`GET()`, `PUT()`, `POST()`, etc. are thin wrappers around the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (which you can [swap for any call](https://openapi-ts.dev/openapi-fetch/api/#create-client)).
4242

4343
Notice there are no generics, and no manual typing. Your endpoint’s request and response were inferred automatically. This is a huge improvement in the type safety of your endpoints because **every manual assertion could lead to a bug**! This eliminates all of the following:
4444

@@ -51,14 +51,13 @@ Notice there are no generics, and no manual typing. Your endpoint’s request an
5151

5252
## Setup
5353

54-
Install this library along with [openapi-typescript](/introduction):
54+
Install this library along with [openapi-typescript](../openapi-typescript):
5555

5656
```bash
5757
npm i openapi-fetch
5858
npm i -D openapi-typescript typescript
5959
```
6060

61-
> **TIP:**
6261
> **Highly recommended**
6362
>
6463
> Enable [noUncheckedIndexedAccess](https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess) in your `tsconfig.json` ([docs](/advanced#enable-nouncheckedindexaccess-in-your-tsconfigjson))
@@ -71,7 +70,7 @@ npx openapi-typescript ./path/to/api/v1.yaml -o ./src/lib/api/v1.d.ts
7170

7271
Lastly, be sure to **run typechecking** in your project. This can be done by adding `tsc --noEmit` to your [npm scripts](https://docs.npmjs.com/cli/v9/using-npm/scripts) like so:
7372

74-
```json [package.json]
73+
```json
7574
{
7675
"scripts": {
7776
"test:ts": "tsc --noEmit"
@@ -91,7 +90,7 @@ The best part about using openapi-fetch over oldschool codegen is no documentati
9190

9291
![OpenAPI schema example](../../docs/public/assets/openapi-schema.png)
9392

94-
```ts [src/my-project.ts]
93+
```ts
9594
import createClient from "openapi-fetch";
9695
import type { paths } from "./my-openapi-3-schema"; // generated by openapi-typescript
9796

@@ -117,43 +116,6 @@ const { data, error } = await client.PUT("/blogposts", {
117116
2. You pass in your desired `path` to `GET()`, `PUT()`, etc.
118117
3. TypeScript takes over the rest and returns helpful errors for anything missing or invalid
119118

120-
### Pathname
121-
122-
The pathname of `GET()`, `PUT()`, `POST()`, etc. **must match your schema literally.** Note in the example, the URL is `/blogposts/{post_id}`. This library will quickly replace all `path` params for you (so they can be typechecked).
123-
124-
125-
> **TIP:**
126-
>
127-
> openapi-fetch infers types from the URL. Prefer static string values over dynamic runtime values, e.g.:
128-
> - ✅ `"/blogposts/{post_id}"`
129-
> - ❌ `[...pathParts].join("/") + "{post_id}"`
130-
131-
This library also supports the **label** and **matrix** serialization styles as well ([docs](https://swagger.io/docs/specification/serialization/#path)) automatically.
132-
133-
### Request
134-
135-
The `GET()` request shown needed the `params` object that groups [parameters by type](https://spec.openapis.org/oas/latest.html#parameter-object) (`path` or `query`). If a required param is missing, or the wrong type, a type error will be thrown.
136-
137-
The `POST()` request required a `body` object that provided all necessary [requestBody](https://spec.openapis.org/oas/latest.html#request-body-object) data.
138-
139-
### Response
140-
141-
All methods return an object with **data**, **error**, and **response**.
142-
143-
```ts
144-
const { data, error, response } = await client.GET("/url");
145-
```
146-
147-
| Object | Response |
148-
| :--------- | :-------------------------------------------------------------------------------------------------------------------------- |
149-
| `data` | `2xx` response if OK; otherwise `undefined` |
150-
| `error` | `5xx`, `4xx`, or `default` response if not OK; otherwise `undefined` |
151-
| `response` | [The original Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) which contains `status`, `headers`, etc. |
152-
153-
## Support
119+
## 📓 Docs
154120

155-
| Platform | Support |
156-
| :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
157-
| **Browsers** | [See fetch API support](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility) (widely-available in all major browsers) |
158-
| **Node** | >= 18.0.0 |
159-
| **TypeScript** | >= 4.7 (>= 5.0 recommended) |
121+
[View Docs](https://openapi-ts.dev/openapi-fetch/)

packages/openapi-typescript/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
openapi-typescript turns [OpenAPI 3.0 & 3.1](https://spec.openapis.org/oas/latest.html) schemas into TypeScript quickly using Node.js. No Java/node-gyp/running OpenAPI servers necessary.
44

5-
The code is [MIT-licensed](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE") and free for use.
5+
The code is [MIT-licensed](./LICENSE) and free for use.
66

77
> **Tip:**
88
> New to OpenAPI? Speakeasy’s [Intro to OpenAPI](https://www.speakeasyapi.dev/openapi) is an accessible guide to newcomers that explains the “why” and “how” of OpenAPI.
@@ -18,7 +18,7 @@ _Note: OpenAPI 2.x is supported with versions `5.x` and previous_
1818

1919
## Examples
2020

21-
👀 [See examples](https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/examples/)
21+
👀 [See examples](./examples/)
2222

2323
## Setup
2424

@@ -30,7 +30,7 @@ npm i -D openapi-typescript typescript
3030

3131
And in your `tsconfig.json`, to load the types properly:
3232

33-
```diff [tsconfig.json]
33+
```diff
3434
{
3535
"compilerOptions": {
3636
+ "module": "ESNext", // or "NodeNext"
@@ -39,11 +39,10 @@ And in your `tsconfig.json`, to load the types properly:
3939
}
4040
```
4141

42-
> **Tip:**
4342
> **Highly recommended**
4443
>
4544
> Also adding the following can boost type safety:
46-
> ```diff [tsconfig.json]
45+
> ```diff
4746
> {
4847
> "compilerOptions": {
4948
> + "noUncheckedIndexedAccess": true
@@ -67,7 +66,7 @@ npx openapi-typescript https://myapi.dev/api/v1/openapi.yaml -o ./path/to/my/sch
6766
6867
Then in your TypeScript project, import types where needed:
6968

70-
```ts [src/my-project.ts]
69+
```ts
7170
import type { paths, components } from "./my-openapi-3-schema"; // generated by openapi-typescript
7271

7372
// Schema Obj
@@ -85,8 +84,12 @@ type ErrorResponse =
8584

8685
From here, you can use these types for any of the following (but not limited to):
8786

88-
- Using an OpenAPI-supported fetch client (like [openapi-fetch](/openapi-fetch/))
87+
- Using an OpenAPI-supported fetch client (like [openapi-fetch](https://openapi-ts.dev/openapi-fetch/))
8988
- Asserting types for other API requestBodies and responses
9089
- Building core business logic based on API types
9190
- Validating mock test data is up-to-date with the current schema
9291
- Packaging API types into any npm packages you publish (such as client SDKs, etc.)
92+
93+
## 📓 Docs
94+
95+
[View Docs](https://openapi-ts.dev/)

0 commit comments

Comments
 (0)