Skip to content

Commit 1da6263

Browse files
authored
feat: make operationParameter optional within endpoint parameters (#1888)
* Bump @api3/ois to v2.2.0 and zod to v3.22.2 * Bump oisFormat in configs and test files * feat: make operationParameter optional within endpoint parameters
1 parent c0ad71f commit 1da6263

39 files changed

Lines changed: 86 additions & 47 deletions

File tree

.changeset/hungry-clouds-grow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@api3/airnode-validator': minor
3+
'@api3/airnode-deployer': minor
4+
'@api3/airnode-examples': minor
5+
'@api3/airnode-adapter': minor
6+
'@api3/airnode-node': minor
7+
---
8+
9+
Bump OIS to v2.2.0 and make operationParameter optional within endpoint parameters

packages/airnode-adapter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:watch": "yarn test:ts --watch"
2020
},
2121
"dependencies": {
22-
"@api3/ois": "2.1.0",
22+
"@api3/ois": "2.2.0",
2323
"@api3/promise-utils": "^0.4.0",
2424
"axios": "^1.5.0",
2525
"bignumber.js": "^9.1.2",

packages/airnode-adapter/src/request-building/parameters.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ describe('fixed parameters', () => {
8181
headers: {},
8282
});
8383
});
84+
85+
it('ignores parameters without operationParameter', () => {
86+
const ois = fixtures.buildOIS();
87+
ois.apiSpecifications.paths['/convert'].get!.parameters.push({ in: 'query', name: 'noOperationParameter' });
88+
const options = fixtures.buildCacheRequestOptions({
89+
ois,
90+
parameters: { f: 'ETH', amount: '1', no_op: 'myValue' },
91+
});
92+
options.endpoint.parameters.push({
93+
name: 'no_op',
94+
// operationParameter is absent
95+
});
96+
options.operation.parameters.push({ name: 'noOperationParameter', in: 'query' });
97+
const res = parameters.buildParameters(options);
98+
expect(res).toEqual({
99+
paths: {},
100+
query: {
101+
// Expectedly absent:
102+
// noOperationParameter: 'myValue',
103+
access_key: 'super-secret-key',
104+
amount: '1',
105+
from: 'ETH',
106+
to: 'USD',
107+
},
108+
headers: {},
109+
});
110+
});
84111
});
85112

86113
describe('user parameters', () => {

packages/airnode-adapter/src/request-building/parameters.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as authentication from './authentication';
33
import * as cookies from './cookies';
44
import { BuilderParameters, CachedBuildRequestOptions, RequestParameters } from '../types';
55

6-
function initalParameters(): BuilderParameters {
6+
function initialParameters(): BuilderParameters {
77
return {
88
paths: {},
99
query: {},
@@ -49,7 +49,7 @@ function buildFixedParameters(options: CachedBuildRequestOptions): BuilderParame
4949
}
5050

5151
return appendParameter(acc, target, name, parameter.value);
52-
}, initalParameters());
52+
}, initialParameters());
5353
}
5454

5555
function buildUserParameters(options: CachedBuildRequestOptions): BuilderParameters {
@@ -66,16 +66,19 @@ function buildUserParameters(options: CachedBuildRequestOptions): BuilderParamet
6666

6767
// Double check that the parameter exists in the API specification
6868
const apiParameter = operation.parameters.find(
69-
(p) => p.name === parameter.operationParameter.name && p.in === parameter.operationParameter.in
69+
(p) =>
70+
parameter.operationParameter &&
71+
p.name === parameter.operationParameter.name &&
72+
p.in === parameter.operationParameter.in
7073
);
71-
if (!apiParameter) {
74+
if (!apiParameter || !parameter.operationParameter) {
7275
return acc;
7376
}
7477

7578
const { name, in: target } = parameter.operationParameter;
7679

7780
return appendParameter(acc, target, name, parameters[key]);
78-
}, initalParameters());
81+
}, initialParameters());
7982
}
8083

8184
export function buildParameters(options: CachedBuildRequestOptions): RequestParameters {

packages/airnode-adapter/test/fixtures/ois.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { OIS } from '@api3/ois';
22

33
export function buildOIS(overrides?: Partial<OIS>): OIS {
44
return {
5-
oisFormat: '2.1.0',
5+
oisFormat: '2.2.0',
66
version: '1.2.3',
77
title: 'Currency Converter API',
88
apiSpecifications: {

packages/airnode-deployer/config/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"templates": [],
9595
"ois": [
9696
{
97-
"oisFormat": "2.1.0",
97+
"oisFormat": "2.2.0",
9898
"title": "CoinGecko basic request",
9999
"version": "1.0.0",
100100
"apiSpecifications": {

packages/airnode-deployer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lodash": "^4.17.21",
4444
"ora": "^5.4.1",
4545
"yargs": "^17.7.2",
46-
"zod": "^3.21.4"
46+
"zod": "^3.22.2"
4747
},
4848
"devDependencies": {
4949
"@aws-sdk/util-stream-node": "^3.370.0",

packages/airnode-deployer/test/fixtures/config.aws.valid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"templates": [],
9696
"ois": [
9797
{
98-
"oisFormat": "2.1.0",
98+
"oisFormat": "2.2.0",
9999
"title": "CoinGecko basic request",
100100
"version": "1.0.0",
101101
"apiSpecifications": {

packages/airnode-deployer/test/fixtures/config.gcp.valid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"templates": [],
9494
"ois": [
9595
{
96-
"oisFormat": "2.1.0",
96+
"oisFormat": "2.2.0",
9797
"title": "CoinGecko basic request",
9898
"version": "1.0.0",
9999
"apiSpecifications": {

packages/airnode-examples/integrations/authenticated-coinmarketcap/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"templates": [],
8484
"ois": [
8585
{
86-
"oisFormat": "2.1.0",
86+
"oisFormat": "2.2.0",
8787
"title": "CoinMarketCap Basic Authenticated Request",
8888
"version": "1.0.0",
8989
"apiSpecifications": {

0 commit comments

Comments
 (0)