Skip to content

Commit 8665dcd

Browse files
authored
feat: Upgrade to latest openapi-fetch (#46)
* feat: Upgrade to latest openapi-fetch * refactor: httpMethod * feat: pathBasedClient * add integration for react-query and swr * fix: build * chore: Update to use v7 ast based generator * fix: tests * fix: tests * fix: tests * fix: typing too complex
1 parent cc8ffa9 commit 8665dcd

File tree

60 files changed

+3546
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3546
-627
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"javascriptreact",
1313
"typescript",
1414
"typescriptreact"
15-
]
15+
],
16+
"typescript.tsdk": "node_modules/typescript/lib"
1617
}

examples/package-lock.json

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"@octokit/rest": "^20.0.2",
1111
"@opensdks/fetch-links": "0.0.13",
12-
"@opensdks/runtime": "0.0.14",
12+
"@opensdks/runtime": "^0.0.20",
1313
"@opensdks/sdk-apollo": "0.0.14",
1414
"@opensdks/sdk-discord": "0.0.14",
1515
"@opensdks/sdk-github": "0.0.14",
@@ -22,7 +22,8 @@
2222
"@opensdks/sdk-salesloft": "0.0.15",
2323
"@opensdks/sdk-slack": "0.0.14",
2424
"@opensdks/sdk-twilio": "0.0.14",
25-
"openapi-fetch": "^0.8.2",
25+
"@opensdks/sdk-openint": "0.1.1",
26+
"openapi-fetch": "^0.13.3",
2627
"remark-toc": "^9.0.0",
2728
"twilio": "^4.19.3"
2829
},

examples/test.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const {initSDK} = require('@opensdks/runtime')
2-
const {veniceSdkDef} = require('@opensdks/sdk-venice')
2+
const {openintSdkDef} = require('@opensdks/sdk-openint')
33

4-
const venice = initSDK(veniceSdkDef)
4+
const openint = initSDK(openintSdkDef)
55

6-
void venice.GET('/health').then((r) => {
6+
void openint.GET('/health').then((r) => {
77
console.log(r.data)
88
})

examples/test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {initSDK} from '@opensdks/runtime'
2-
import {veniceSdkDef} from '@opensdks/sdk-venice'
2+
import {openintSdkDef} from '@opensdks/sdk-openint'
33

4-
const venice = initSDK(veniceSdkDef)
4+
const openint = initSDK(openintSdkDef)
55

6-
const res = await venice.GET('/health')
6+
const res = await openint.GET('/health')
77

88
console.log(res.data)

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dependencies": {
4444
"change-case": "^5.4.4",
4545
"fast-xml-parser": "^4.4.0",
46-
"openapi-typescript": "^6.7.3",
46+
"openapi-typescript": "^7.4.4",
4747
"prettier": "^3.1.0",
4848
"remeda": "^1.31.0",
4949
"yaml": "^2.3.4"

packages/cli/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as fs from 'node:fs'
55
import type {OpenAPI3} from 'openapi-typescript'
6-
import openapiTS from 'openapi-typescript'
6+
import openapiTS, {astToString} from 'openapi-typescript'
77
import prettier from 'prettier'
88
import R from 'remeda'
99
import yaml from 'yaml'
@@ -49,7 +49,8 @@ export async function generateTypes(
4949
oas: OpenAPISpec,
5050
opts: {exportDefault?: boolean} = {},
5151
) {
52-
const types = await openapiTS(oas as OpenAPI3)
52+
const nodes = await openapiTS(oas as OpenAPI3)
53+
const types = astToString(nodes)
5354

5455
return `${types}
5556

packages/fetch-links/link.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
export type HTTPMethod =
2-
| 'GET'
3-
| 'PUT'
4-
| 'POST'
5-
| 'DELETE'
6-
| 'OPTIONS'
7-
| 'HEAD'
8-
| 'PATCH'
9-
| 'TRACE'
1+
import type {HttpMethod} from 'openapi-typescript-helpers'
2+
3+
export const HTTP_METHODS = [
4+
'GET',
5+
'PUT',
6+
'POST',
7+
'DELETE',
8+
'OPTIONS',
9+
'HEAD',
10+
'PATCH',
11+
'TRACE',
12+
] satisfies ReadonlyArray<Uppercase<HttpMethod>>
13+
14+
export type HTTPMethod = (typeof HTTP_METHODS)[number]
1015

1116
/**
1217
* The BetterRequest object is an extension of the native [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)

packages/fetch-links/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"devDependencies": {
4444
"axios": "^1.6.2",
4545
"concurrently": "^8.2.2",
46+
"openapi-typescript-helpers": "^0.0.15",
4647
"type-fest": "^4.28.0"
4748
},
4849
"publishConfig": {

packages/runtime/HTTPError.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type {FetchResponse} from 'openapi-fetch'
2-
import type {HTTPMethod} from '@opensdks/fetch-links'
2+
import type {HttpMethod, MediaType} from 'openapi-typescript-helpers'
33

4-
export class HTTPError<T> extends Error {
4+
export class HTTPError<T extends Record<string | number, any>> extends Error {
55
override name = 'HTTPError'
6-
readonly method: HTTPMethod
7-
readonly error: Extract<FetchResponse<T>, {error: unknown}>['error']
8-
readonly response: FetchResponse<T>['response']
6+
readonly method: Uppercase<HttpMethod>
7+
readonly error: Extract<
8+
FetchResponse<T, {}, MediaType>,
9+
{error: unknown}
10+
>['error']
11+
readonly response: FetchResponse<T, {}, MediaType>['response']
912

1013
get code() {
1114
return this.response?.status
@@ -15,7 +18,9 @@ export class HTTPError<T> extends Error {
1518
method,
1619
error,
1720
response: r,
18-
}: Extract<FetchResponse<T>, {error: unknown}> & {method: HTTPMethod}) {
21+
}: Extract<FetchResponse<T, {}, MediaType>, {error: unknown}> & {
22+
method: Uppercase<HttpMethod>
23+
}) {
1924
super(
2025
[
2126
`[${r.status} ${r.statusText}] ${method.toUpperCase()} ${r.url}`,

0 commit comments

Comments
 (0)