-
Notifications
You must be signed in to change notification settings - Fork 89
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
663/mk/open payments validate #679
Conversation
@@ -0,0 +1,37 @@ | |||
/* eslint-disable @typescript-eslint/no-empty-function */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how important these tests in particular are, but I thought it was worth making sure we are adding the correct path for the response validator
import { components } from './generated/types' | ||
import { components, paths as Paths } from './generated/types' | ||
|
||
export const getPath = <P extends keyof Paths>(path: P): string => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function gives autocomplete functionality to all of the possible (generated) Open payments API paths we have
args?: CreateOpenPaymentClientArgs | ||
): Promise<OpenPaymentsClient> => { | ||
const axios = createAxiosInstance(args) | ||
const openApi = await createOpenAPI(config.OPEN_PAYMENTS_OPEN_API_URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the same version to validate the Open API as was used for generating the types in the first place
return get( | ||
axios, | ||
args, | ||
openApi.createResponseValidator({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response validator library uses Ajv, which recommends instantiating once at initialization (vs once per request here)
https://github.com/kogosoftwarellc/open-api/blob/9b58193f17f69a3f6b018a17c79a8c938b7628a2/packages/openapi-response-validator/index.ts#L79-L85
https://ajv.js.org/guide/managing-schemas.html#compiling-during-initialization
(We should probably document this in our openapi
library...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, updated to create the validators just once. Will also update the docs.
console.log(errorMessage, { | ||
url, | ||
data: JSON.stringify(data) | ||
}) | ||
|
||
throw new Error(errorMessage) | ||
} | ||
|
||
return data | ||
} catch (error) { | ||
console.log('Error when making Open Payments GET request', { | ||
errorMessage: error?.message, | ||
url | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this either not log or should open-payments
support a configurable logger like pino
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, added pino support. wanted to do it as a follow up but it's not too big
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to merge/rebase on main
to resolve backend build failure
* feat(open-payments-client): initial POC of open-payments-client * feat(open-payments-client): cleanup * feat(open-payments): remove open-payments-client folder * feat(open-payments): make open-payments folder and use script for type generation * feat(open-payments): fix rootDir * feat(open-payments): downgrading generation lib, updating how script is ran * feat(open-payments): update default config usage * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): adding tests * feat(open-payments): update pnpm-lock.yaml * feat(open-payments): simplify test * feat(open-payments): updating workflows * feat(open-payments): pin the open api spec to the most recent commit * feat(open-payments): adding openapi validation * feat(open-payments): adding openapi validation * feat(open-payments): adding tests * feat(open-payments): correcting test * feat(open-payments): use updated RS spec * feat(open-payments): build open api package on build step * feat(open-payments): building open-api package during workflow * Revert "feat(open-payments): building open-api package during workflow" This reverts commit e11ec65. * feat(open-payments): building open-api package during workflow * feat(open-payments): update naming * feat(open-payments): instantiate validator functions once * chore(openapi): add docs for usage * chore(openapi): update docs * chore(openapi): prettify docs * chore(openapi): update docs * feat(open-payments): adding logger as dependency * feat(open-payments): updating logging & error logic * feat(open-payments): remove unnecessary imports * feat(open-payments): update error handling & test
Changes proposed in this pull request
open-api
package)Context
The related issues are #663, and #662 and the parent roadmap item is interledger/roadmap#20.
Checklist
fixes #number