Skip to content
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

feat: Upgrade to latest openapi-fetch #46

Merged
merged 10 commits into from
Dec 23, 2024
Merged
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"javascriptreact",
"typescript",
"typescriptreact"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
41 changes: 25 additions & 16 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@octokit/rest": "^20.0.2",
"@opensdks/fetch-links": "0.0.13",
"@opensdks/runtime": "0.0.14",
"@opensdks/runtime": "^0.0.20",
"@opensdks/sdk-apollo": "0.0.14",
"@opensdks/sdk-discord": "0.0.14",
"@opensdks/sdk-github": "0.0.14",
Expand All @@ -22,7 +22,8 @@
"@opensdks/sdk-salesloft": "0.0.15",
"@opensdks/sdk-slack": "0.0.14",
"@opensdks/sdk-twilio": "0.0.14",
"openapi-fetch": "^0.8.2",
"@opensdks/sdk-openint": "0.1.1",
"openapi-fetch": "^0.13.3",
"remark-toc": "^9.0.0",
"twilio": "^4.19.3"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/test.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const {initSDK} = require('@opensdks/runtime')
const {veniceSdkDef} = require('@opensdks/sdk-venice')
const {openintSdkDef} = require('@opensdks/sdk-openint')

const venice = initSDK(veniceSdkDef)
const openint = initSDK(openintSdkDef)

void venice.GET('/health').then((r) => {
void openint.GET('/health').then((r) => {
console.log(r.data)
})
6 changes: 3 additions & 3 deletions examples/test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {initSDK} from '@opensdks/runtime'
import {veniceSdkDef} from '@opensdks/sdk-venice'
import {openintSdkDef} from '@opensdks/sdk-openint'

const venice = initSDK(veniceSdkDef)
const openint = initSDK(openintSdkDef)

const res = await venice.GET('/health')
const res = await openint.GET('/health')

console.log(res.data)
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"change-case": "^5.4.4",
"fast-xml-parser": "^4.4.0",
"openapi-typescript": "^6.7.3",
"openapi-typescript": "^7.4.4",
"prettier": "^3.1.0",
"remeda": "^1.31.0",
"yaml": "^2.3.4"
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as fs from 'node:fs'
import type {OpenAPI3} from 'openapi-typescript'
import openapiTS from 'openapi-typescript'
import openapiTS, {astToString} from 'openapi-typescript'
import prettier from 'prettier'
import R from 'remeda'
import yaml from 'yaml'
Expand Down Expand Up @@ -49,7 +49,8 @@ export async function generateTypes(
oas: OpenAPISpec,
opts: {exportDefault?: boolean} = {},
) {
const types = await openapiTS(oas as OpenAPI3)
const nodes = await openapiTS(oas as OpenAPI3)
const types = astToString(nodes)

return `${types}

Expand Down
23 changes: 14 additions & 9 deletions packages/fetch-links/link.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
export type HTTPMethod =
| 'GET'
| 'PUT'
| 'POST'
| 'DELETE'
| 'OPTIONS'
| 'HEAD'
| 'PATCH'
| 'TRACE'
import type {HttpMethod} from 'openapi-typescript-helpers'

export const HTTP_METHODS = [
'GET',
'PUT',
'POST',
'DELETE',
'OPTIONS',
'HEAD',
'PATCH',
'TRACE',
] satisfies ReadonlyArray<Uppercase<HttpMethod>>

export type HTTPMethod = (typeof HTTP_METHODS)[number]

/**
* The BetterRequest object is an extension of the native [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)
Expand Down
1 change: 1 addition & 0 deletions packages/fetch-links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"axios": "^1.6.2",
"concurrently": "^8.2.2",
"openapi-typescript-helpers": "^0.0.15",
"type-fest": "^4.28.0"
},
"publishConfig": {
Expand Down
17 changes: 11 additions & 6 deletions packages/runtime/HTTPError.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type {FetchResponse} from 'openapi-fetch'
import type {HTTPMethod} from '@opensdks/fetch-links'
import type {HttpMethod, MediaType} from 'openapi-typescript-helpers'

export class HTTPError<T> extends Error {
export class HTTPError<T extends Record<string | number, any>> extends Error {
override name = 'HTTPError'
readonly method: HTTPMethod
readonly error: Extract<FetchResponse<T>, {error: unknown}>['error']
readonly response: FetchResponse<T>['response']
readonly method: Uppercase<HttpMethod>
readonly error: Extract<
FetchResponse<T, {}, MediaType>,
{error: unknown}
>['error']
readonly response: FetchResponse<T, {}, MediaType>['response']

get code() {
return this.response?.status
Expand All @@ -15,7 +18,9 @@ export class HTTPError<T> extends Error {
method,
error,
response: r,
}: Extract<FetchResponse<T>, {error: unknown}> & {method: HTTPMethod}) {
}: Extract<FetchResponse<T, {}, MediaType>, {error: unknown}> & {
method: Uppercase<HttpMethod>
}) {
super(
[
`[${r.status} ${r.statusText}] ${method.toUpperCase()} ${r.url}`,
Expand Down
Loading
Loading