Skip to content

Commit

Permalink
feat: make operationParameter optional within endpoint parameters (#1888
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
dcroote authored and Ashar2shahid committed Jan 18, 2024
1 parent 283e2b3 commit b335b35
Show file tree
Hide file tree
Showing 39 changed files with 86 additions and 47 deletions.
9 changes: 9 additions & 0 deletions .changeset/hungry-clouds-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@api3/airnode-validator': minor
'@api3/airnode-deployer': minor
'@api3/airnode-examples': minor
'@api3/airnode-adapter': minor
'@api3/airnode-node': minor
---

Bump OIS to v2.2.0 and make operationParameter optional within endpoint parameters
2 changes: 1 addition & 1 deletion packages/airnode-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:watch": "yarn test:ts --watch"
},
"dependencies": {
"@api3/ois": "2.1.0",
"@api3/ois": "2.2.0",
"@api3/promise-utils": "^0.4.0",
"axios": "^1.5.0",
"bignumber.js": "^9.1.2",
Expand Down
27 changes: 27 additions & 0 deletions packages/airnode-adapter/src/request-building/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ describe('fixed parameters', () => {
headers: {},
});
});

it('ignores parameters without operationParameter', () => {
const ois = fixtures.buildOIS();
ois.apiSpecifications.paths['/convert'].get!.parameters.push({ in: 'query', name: 'noOperationParameter' });
const options = fixtures.buildCacheRequestOptions({
ois,
parameters: { f: 'ETH', amount: '1', no_op: 'myValue' },
});
options.endpoint.parameters.push({
name: 'no_op',
// operationParameter is absent
});
options.operation.parameters.push({ name: 'noOperationParameter', in: 'query' });
const res = parameters.buildParameters(options);
expect(res).toEqual({
paths: {},
query: {
// Expectedly absent:
// noOperationParameter: 'myValue',
access_key: 'super-secret-key',
amount: '1',
from: 'ETH',
to: 'USD',
},
headers: {},
});
});
});

describe('user parameters', () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/airnode-adapter/src/request-building/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as authentication from './authentication';
import * as cookies from './cookies';
import { BuilderParameters, CachedBuildRequestOptions, RequestParameters } from '../types';

function initalParameters(): BuilderParameters {
function initialParameters(): BuilderParameters {
return {
paths: {},
query: {},
Expand Down Expand Up @@ -49,7 +49,7 @@ function buildFixedParameters(options: CachedBuildRequestOptions): BuilderParame
}

return appendParameter(acc, target, name, parameter.value);
}, initalParameters());
}, initialParameters());
}

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

// Double check that the parameter exists in the API specification
const apiParameter = operation.parameters.find(
(p) => p.name === parameter.operationParameter.name && p.in === parameter.operationParameter.in
(p) =>
parameter.operationParameter &&
p.name === parameter.operationParameter.name &&
p.in === parameter.operationParameter.in
);
if (!apiParameter) {
if (!apiParameter || !parameter.operationParameter) {
return acc;
}

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

return appendParameter(acc, target, name, parameters[key]);
}, initalParameters());
}, initialParameters());
}

export function buildParameters(options: CachedBuildRequestOptions): RequestParameters {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-adapter/test/fixtures/ois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OIS } from '@api3/ois';

export function buildOIS(overrides?: Partial<OIS>): OIS {
return {
oisFormat: '2.1.0',
oisFormat: '2.2.0',
version: '1.2.3',
title: 'Currency Converter API',
apiSpecifications: {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-deployer/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lodash": "^4.17.21",
"ora": "^5.4.1",
"yargs": "^17.7.2",
"zod": "^3.21.4"
"zod": "^3.22.2"
},
"devDependencies": {
"@aws-sdk/util-stream-node": "^3.370.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinMarketCap Basic Authenticated Request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinMarketCap Basic Authenticated Request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko coins markets request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko coins markets request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko history data request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko history data request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'CoinGecko basic request',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "Failure Example",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'Failure Example',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "Relay Security Schemes via httpbin",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'Relay Security Schemes via httpbin',
version: '1.0.0',
apiSpecifications: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "OpenWeather Multiple Encoded Values",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
templates: [],
ois: [
{
oisFormat: '2.1.0',
oisFormat: '2.2.0',
title: 'OpenWeather Multiple Encoded Values',
version: '1.0.0',
apiSpecifications: {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"version": "1.2.3",
"title": "Currency Converter API",
"apiSpecifications": {
Expand Down
4 changes: 2 additions & 2 deletions packages/airnode-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@api3/airnode-protocol": "^0.12.0",
"@api3/airnode-utilities": "^0.12.0",
"@api3/airnode-validator": "^0.12.0",
"@api3/ois": "2.1.0",
"@api3/ois": "2.2.0",
"@api3/promise-utils": "^0.4.0",
"@aws-sdk/client-lambda": "^3.418.0",
"date-fns": "^2.30.0",
Expand All @@ -39,7 +39,7 @@
"google-auth-library": "^9.0.0",
"lodash": "^4.17.21",
"yargs": "^17.7.2",
"zod": "^3.21.4"
"zod": "^3.22.2"
},
"devDependencies": {
"@api3/airnode-operation": "^0.12.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/test/fixtures/config/ois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OIS } from '@api3/ois';

export function buildOIS(ois?: Partial<OIS>): OIS {
return {
oisFormat: '2.1.0',
oisFormat: '2.2.0',
version: '1.2.3',
title: 'Currency Converter API',
apiSpecifications: {
Expand Down
4 changes: 2 additions & 2 deletions packages/airnode-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
},
"dependencies": {
"@api3/airnode-protocol": "^0.12.0",
"@api3/ois": "2.1.0",
"@api3/ois": "2.2.0",
"@api3/promise-utils": "^0.4.0",
"dotenv": "^16.3.1",
"ethers": "^5.7.2",
"lodash": "^4.17.21",
"ora": "^5.4.1",
"yargs": "^17.7.2",
"zod": "^3.21.4"
"zod": "^3.22.2"
},
"devDependencies": {
"@types/yargs": "^17.0.25",
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-validator/test/fixtures/config.valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"templates": [],
"ois": [
{
"oisFormat": "2.1.0",
"oisFormat": "2.2.0",
"title": "CoinGecko basic request",
"version": "1.0.0",
"apiSpecifications": {
Expand Down
Loading

0 comments on commit b335b35

Please sign in to comment.