File tree Expand file tree Collapse file tree 7 files changed +71
-5
lines changed Expand file tree Collapse file tree 7 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ const createEndpoint = (
144144 routePath : string ,
145145 endpointPath : string ,
146146) : Endpoint => {
147- if ( ! isOpenApiPath ( endpointPath ) ) {
147+ if ( ! isOpenapiPath ( endpointPath ) ) {
148148 throw new Error ( `Did not find ${ endpointPath } in OpenAPI spec` )
149149 }
150150 const spec = openapi . paths [ endpointPath ]
@@ -174,7 +174,7 @@ const deriveResource = (
174174 return endpointResources [ endpointPath ] ?? null
175175 }
176176
177- if ( isOpenApiPath ( endpointPath ) ) {
177+ if ( isOpenapiPath ( endpointPath ) ) {
178178 const spec = openapi . paths [ endpointPath ]
179179 const methodKey = method . toLowerCase ( )
180180
@@ -213,7 +213,7 @@ const isEndpointResource = (
213213 key : string ,
214214) : key is keyof typeof endpointResources => key in endpointResources
215215
216- const isOpenApiPath = ( key : string ) : key is keyof typeof openapi . paths =>
216+ const isOpenapiPath = ( key : string ) : key is keyof typeof openapi . paths =>
217217 key in openapi . paths
218218
219219const isEndpointUnderRoute = (
Original file line number Diff line number Diff line change 118118 "eslint-plugin-unused-imports" : " ^3.0.0" ,
119119 "execa" : " ^8.0.1" ,
120120 "landlubber" : " ^1.0.0" ,
121+ "nock" : " ^13.4.0" ,
121122 "node-fetch" : " ^3.3.2" ,
122123 "prettier" : " ^3.0.0" ,
123124 "tsc-alias" : " ^1.8.2" ,
Original file line number Diff line number Diff line change 11export { SeamHttpInvalidTokenError } from './auth.js'
22export * from './error-interceptor.js'
3+ export * from './openapi.js'
34export * from './options.js'
45export {
56 isSeamActionAttemptError ,
Original file line number Diff line number Diff line change 1+ import type { openapi } from '@seamapi/types/connect'
2+
3+ import { createClient } from './client.js'
4+ import { defaultEndpoint , sdkHeaders } from './parse-options.js'
5+
6+ export const getOpenapiSchema = async (
7+ endpoint = defaultEndpoint ,
8+ ) : Promise < typeof openapi > => {
9+ const client = createClient ( {
10+ axiosOptions : {
11+ baseURL : endpoint ,
12+ headers : sdkHeaders ,
13+ } ,
14+ } )
15+ const { data } = await client . get < typeof openapi > ( '/openapi.json' )
16+ return data
17+ }
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ import {
1111 type SeamHttpRequestOptions ,
1212} from './options.js'
1313
14- const defaultEndpoint = 'https://connect.getseam.com'
14+ export const defaultEndpoint = 'https://connect.getseam.com'
1515
16- const sdkHeaders = {
16+ export const sdkHeaders = {
1717 'seam-sdk-name' : 'seamapi/javascript-http' ,
1818 'seam-sdk-version' : version ,
1919}
Original file line number Diff line number Diff line change 1+ import { getOpenapiSchema } from '@seamapi/http/connect'
2+ import { openapi } from '@seamapi/types/connect'
3+ import test from 'ava'
4+ import { getTestServer } from 'fixtures/seam/connect/api.js'
5+ import nock from 'nock'
6+
7+
8+ test ( 'SeamHttp: getOpenapiSchema returns data' , async ( t ) => {
9+ const { endpoint } = await getTestServer ( t )
10+
11+ // UPSTREAM: Must use nock since fake-seam-connect returns 404 for /openapi.json.
12+ // https://github.com/seamapi/fake-seam-connect/issues/132
13+ nock ( endpoint ) . get ( '/openapi.json' ) . reply ( 200 , openapi )
14+
15+ const data = await getOpenapiSchema ( endpoint )
16+ t . truthy ( data . info . title )
17+ } )
You can’t perform that action at this time.
0 commit comments