-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(open-payments): export OpenAPI specs * chore: add changelog * chore: fix generate types command * chore: add jsdoc
- Loading branch information
Showing
20 changed files
with
169 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@interledger/open-payments': minor | ||
--- | ||
|
||
Add and export functions that allow fetching the OpenAPI objects for the Open Payments specs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
getResourceServerOpenAPI, | ||
getAuthServerOpenAPI, | ||
getWalletAddressServerOpenAPI | ||
} from '.' | ||
|
||
describe('OpenAPI', (): void => { | ||
describe('getResourceServerOpenAPI', () => { | ||
test('properly generates API paths', async () => { | ||
const openApi = await getResourceServerOpenAPI() | ||
|
||
expect(openApi).toBeDefined() | ||
expect(Object.keys(openApi.paths)).toEqual( | ||
expect.arrayContaining([ | ||
'/incoming-payments', | ||
'/outgoing-payments', | ||
'/quotes', | ||
'/incoming-payments/{id}', | ||
'/incoming-payments/{id}/complete', | ||
'/outgoing-payments/{id}', | ||
'/quotes/{id}' | ||
]) | ||
) | ||
}) | ||
|
||
test('properly references $ref to external ./schemas.yaml', async () => { | ||
const openApi = await getResourceServerOpenAPI() | ||
|
||
expect( | ||
Object.keys( | ||
openApi.paths?.['/incoming-payments']?.['post']?.['requestBody']?.[ | ||
'content' | ||
]['application/json']['schema']['properties']['incomingAmount'][ | ||
'properties' | ||
] | ||
).sort() | ||
).toEqual(['assetCode', 'assetScale', 'value'].sort()) | ||
}) | ||
}) | ||
|
||
describe('getAuthServerOpenAPI', () => { | ||
test('properly generates API paths', async () => { | ||
const openApi = await getAuthServerOpenAPI() | ||
|
||
expect(openApi).toBeDefined() | ||
expect(Object.keys(openApi.paths)).toEqual( | ||
expect.arrayContaining(['/', '/continue/{id}', '/token/{id}']) | ||
) | ||
}) | ||
|
||
test('properly references $ref to external ./schemas.yaml', async () => { | ||
const openApi = await getAuthServerOpenAPI() | ||
|
||
expect( | ||
Object.keys( | ||
openApi.paths?.['/']?.['post']?.['requestBody']?.['content'][ | ||
'application/json' | ||
]['schema']['properties']['access_token']['properties']['access'][ | ||
'items' | ||
]['oneOf'][1]['properties']['limits']['properties']['debitAmount'][ | ||
'properties' | ||
] | ||
).sort() | ||
).toEqual(['assetCode', 'assetScale', 'value'].sort()) | ||
}) | ||
}) | ||
|
||
describe('getWalletAddressServerOpenAPI', () => { | ||
test('properly generates API paths', async () => { | ||
const openApi = await getWalletAddressServerOpenAPI() | ||
|
||
expect(openApi).toBeDefined() | ||
expect(Object.keys(openApi.paths)).toEqual( | ||
expect.arrayContaining(['/', '/jwks.json', '/did.json']) | ||
) | ||
}) | ||
|
||
test('properly references $ref to external ./schemas.yaml', async () => { | ||
const openApi = await getWalletAddressServerOpenAPI() | ||
|
||
const getWalletAddressResponse = | ||
openApi.paths?.['/']?.['get']?.['responses']['200']['content'][ | ||
'application/json' | ||
]['schema']['properties'] | ||
|
||
expect(getWalletAddressResponse['assetCode'].type).toBe('string') | ||
expect(getWalletAddressResponse['assetScale'].type).toBe('integer') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createOpenAPI } from '@interledger/openapi' | ||
import path from 'path' | ||
|
||
/** | ||
* Returns the OpenAPI object for the Open Payments Resource Server OpenAPI spec. | ||
* This object allows validating requests and responses against the spec. | ||
* See more: https://github.com/interledger/open-payments/blob/main/packages/openapi/README.md | ||
*/ | ||
export async function getResourceServerOpenAPI() { | ||
return createOpenAPI(path.resolve(__dirname, './specs/resource-server.yaml')) | ||
} | ||
|
||
/** | ||
* Returns the OpenAPI object for the Open Payments Wallet Address Server OpenAPI spec. | ||
* This object allows validating requests and responses against the spec. | ||
* See more: https://github.com/interledger/open-payments/blob/main/packages/openapi/README.md | ||
*/ | ||
export async function getWalletAddressServerOpenAPI() { | ||
return createOpenAPI( | ||
path.resolve(__dirname, './specs/wallet-address-server.yaml') | ||
) | ||
} | ||
|
||
/** | ||
* Returns the OpenAPI object for the Open Payments Auth Server OpenAPI spec. | ||
* This object allows validating requests and responses against the spec. | ||
* See more: https://github.com/interledger/open-payments/blob/main/packages/openapi/README.md | ||
*/ | ||
export async function getAuthServerOpenAPI() { | ||
return createOpenAPI(path.resolve(__dirname, './specs/auth-server.yaml')) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../openapi/auth-server.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../openapi/resource-server.yaml |
Oops, something went wrong.