Skip to content

Commit

Permalink
fix(openapi): remove additional properties (#331)
Browse files Browse the repository at this point in the history
* fix(openapi): remove additional properties

* refactor: add unevaluatedProperties

* chore(open-payments): add changeset

* fix: additional properties on list incoming payment

* fix(openapi): create middleware test

* fix: update changeset description
  • Loading branch information
BlairCurrey authored Oct 17, 2023
1 parent 8396a57 commit b80f231
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-feet-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@interledger/open-payments': patch
---

moves additionalProperties: false from incoming-payment type to GET /incoming-payments response
2 changes: 1 addition & 1 deletion openapi/resource-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ paths:
type: array
items:
$ref: '#/components/schemas/incoming-payment'
additionalProperties: false
examples:
forward pagination:
value:
Expand Down Expand Up @@ -904,7 +905,6 @@ components:
expiresAt: '2022-04-12T23:20:50.52Z'
createdAt: '2022-03-12T23:20:50.52Z'
updatedAt: '2022-03-12T23:20:50.52Z'
additionalProperties: false
properties:
id:
type: string
Expand Down
42 changes: 41 additions & 1 deletion packages/openapi/src/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ describe('OpenAPI Validator', (): void => {
expect(next).toHaveBeenCalled()
})

test('returns 500 with additional properties', async (): Promise<void> => {
const ctx = createContext(
{
headers: { Accept: 'application/json' }
},
{}
)
addTestSignatureHeaders(ctx)
ctx.request.query = { 'wallet-address': WALLET_ADDRESS }

const next = jest.fn().mockImplementation(() => {
ctx.response.body = {
pagination: { hasNextPage: false, hasPreviousPage: false },
result: [
{
id: uuid(),
walletAddress: WALLET_ADDRESS,
completed: false,
receivedAmount: { value: '0', assetCode: 'USD', assetScale: 2 },
createdAt: '2022-03-12T23:20:50.52Z',
updatedAt: '2022-04-01T10:24:36.11Z',
additionalProp: 'disallowed'
}
]
}
})
await expect(validateListMiddleware(ctx, next)).rejects.toMatchObject({
status: 500,
message:
'response.result.0 must NOT have additional properties: additionalProp'
})
expect(next).toHaveBeenCalled()
})

const body = {
id: `https://${accountId}/incoming-payments/${uuid()}`,
walletAddress: 'https://openpayments.guide/alice',
Expand All @@ -185,13 +219,19 @@ describe('OpenAPI Validator', (): void => {
assetCode: 'USD',
assetScale: 2
},
methods: [
{
type: 'ilp',
ilpAddress: 'g.ilp.iwuyge987y.98y08y',
sharedSecret: '1c7eaXa4rd2fFOBl1iydvCT1tV5TbM3RW1WLCafu_JA'
}
],
createdAt: '2022-03-12T23:20:50.52Z',
updatedAt: '2022-04-01T10:24:36.11Z'
}
test.each`
status | body | message | description
${202} | ${{}} | ${'An unknown status code was used and no default was provided.'} | ${'status code'}
${201} | ${{ ...body, invalid: 'field' }} | ${'response must NOT have additional properties: invalid'} | ${'body with additional property'}
${201} | ${{ ...body, receivedAmount: { ...body.receivedAmount, value: '-1' } }} | ${'response.receivedAmount.value must match format "uint64"'} | ${'body with invalid type'}
`(
'returns 500 on invalid response $description',
Expand Down

0 comments on commit b80f231

Please sign in to comment.