Skip to content

Commit

Permalink
feat(middleware): switch to v3 api
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 31, 2024
1 parent f1fbb29 commit b0015c0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 30 deletions.
6 changes: 3 additions & 3 deletions test/integration/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Middleware API', () => {
payload: {
blockHash: 'mh_28wMvNExkFqRSGc2KchZzQWr9QrNiHCFD3sBeMNCM5shK9iqXw',
blockHeight: 3,
encoded_tx: 'tx_+KULAfhCuEDWbZq1WeArvSAaNYZWvXvTwRPiiakFeSJ1XGavpe/A47SNYu6wKSdeChh3IZtTMJIblgbluqE0eCrW0tXfv+4GuF34WyACoQGlDe8oTWOIBGKIUgMgu3jBZWwwfAJEB/vhPQUWEAbEqgKkOWJLazQxMHJ0NFpFblBablh5RkoyS292c0lBenptLmNoYWluAIcBxr9SY0AAhg9Vhk+YAAZA2OYv',
encodedTx: 'tx_+KULAfhCuEDWbZq1WeArvSAaNYZWvXvTwRPiiakFeSJ1XGavpe/A47SNYu6wKSdeChh3IZtTMJIblgbluqE0eCrW0tXfv+4GuF34WyACoQGlDe8oTWOIBGKIUgMgu3jBZWwwfAJEB/vhPQUWEAbEqgKkOWJLazQxMHJ0NFpFblBablh5RkoyS292c0lBenptLmNoYWluAIcBxr9SY0AAhg9Vhk+YAAZA2OYv',
hash: 'th_Wt9hi3oaWpr5mfR2zJHPJg7bAWkYbPwajoS361NVVHmeQ3Wmx',
microIndex: 0,
microTime: 1721213472190,
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Middleware API', () => {
payload: {
blockHash: 'mh_Regp5RaGeK2mxpQmifSgbrF4DwXiQNkkt8VjFnkNB4NK5v3St',
blockHeight: 2,
encoded_tx: 'tx_+PcLAfhCuEB+Tq5sUOIMedGLODH48nG1b7KNt4Dre9vyXC3eH2EjFe2EkVGpx4QN/eQU2OLHXJgg1/7uFO5S3pMlI+jqv78FuK/4rSoBoQGlDe8oTWOIBGKIUgMgu3jBZWwwfAJEB/vhPQUWEAbEqgG4avhoRgOg2qvS0QZEjddEG/XeWW7yVgfv7YPK4+Tsp1rY/AENke3AuDue/kTWRB8ANwA3ABoOgj8BAz/+gHggkgA3AQcHAQEAmC8CEUTWRB8RaW5pdBGAeCCSGWdldEFyZ4IvAIU4LjAuMACDCAADhkdlNJ1oAAUAAEyEO5rKAIcrEUTWRB8/Bmn2yg==',
encodedTx: 'tx_+PcLAfhCuEB+Tq5sUOIMedGLODH48nG1b7KNt4Dre9vyXC3eH2EjFe2EkVGpx4QN/eQU2OLHXJgg1/7uFO5S3pMlI+jqv78FuK/4rSoBoQGlDe8oTWOIBGKIUgMgu3jBZWwwfAJEB/vhPQUWEAbEqgG4avhoRgOg2qvS0QZEjddEG/XeWW7yVgfv7YPK4+Tsp1rY/AENke3AuDue/kTWRB8ANwA3ABoOgj8BAz/+gHggkgA3AQcHAQEAmC8CEUTWRB8RaW5pdBGAeCCSGWdldEFyZ4IvAIU4LjAuMACDCAADhkdlNJ1oAAUAAEyEO5rKAIcrEUTWRB8/Bmn2yg==',
hash: 'th_2JMR7C1DjrGeZWyyLMkccRLga1Lct8Syy9hcZKD9PEZkN5JvSD',
microIndex: 0,
microTime: 1721213472106,
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('Middleware API', () => {
payload: {
blockHash: 'mh_2Wcpmr8PBEjj7qc78Y1dusvAKsQNuYhgoQNPsx3XdHtphvw8mT',
blockHeight: 1,
encoded_tx: 'tx_+KMLAfhCuEDgjc7zMPb+xRW+pI0L5OqwjI+OBF0ee1zgmlkXsavoYXHZw7vTx6vxaAZxxs4ts/eZhAmqVGg3EmTsRAtccKMDuFv4WQwBoQGEDJdLlxZHdkVLoRnYTtxNYFio3skrbtxXirLTC0xCAKEBpQ3vKE1jiARiiFIDILt4wWVsMHwCRAf74T0FFhAGxKqIDeC2s6dkAACGD0w2IAgABAGAJs2FDw==',
encodedTx: 'tx_+KMLAfhCuEDgjc7zMPb+xRW+pI0L5OqwjI+OBF0ee1zgmlkXsavoYXHZw7vTx6vxaAZxxs4ts/eZhAmqVGg3EmTsRAtccKMDuFv4WQwBoQGEDJdLlxZHdkVLoRnYTtxNYFio3skrbtxXirLTC0xCAKEBpQ3vKE1jiARiiFIDILt4wWVsMHwCRAf74T0FFhAGxKqIDeC2s6dkAACGD0w2IAgABAGAJs2FDw==',
hash: 'th_U26TdBBNT56HFXWAb4ktFyWBTuCAnwdajecTL4ss2BhciRviG',
microIndex: 0,
microTime: 1721213471890,
Expand Down
4 changes: 2 additions & 2 deletions tooling/autorest/middleware-prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const run = (getOutput, command, ...args) => {
};

const name = './tooling/autorest/middleware-openapi.yaml';
const hash = 'kc8BgsSJdSmzj7y33IOBVT0wlcWy4gsG49fFMVUyZ08Alhee9LhCC98HaCYNIft95ZzFYVwNY+x++acnZMK0gw==';
const hash = 'wDJxbpq5cVHFbcb8+KhLu0Hut6nU2bItGmjPZmyO/lm5Wipb+DMZOrfrp20HkLEhl2SPz1TxBy/mKFLZZ0xDag==';

await restoreFile(name, hash, () => {
const version = '1.81.0';
const id = run(true, 'docker', 'create', `aeternity/ae_mdw:${version}`);
const openapi = `/home/aeternity/node/lib/ae_mdw-${version}/priv/static/swagger/swagger_v2.json`;
const openapi = `/home/aeternity/node/lib/ae_mdw-${version}/priv/static/swagger/swagger_v3.json`;
run(false, 'docker', 'cp', `${id}:${openapi}`, name);
run(false, 'docker', 'rm', '-v', id);
});
97 changes: 72 additions & 25 deletions tooling/autorest/middleware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ directive:
throw errors even for explained response with not 200 code
https://github.com/Azure/autorest.typescript/issues/463#issuecomment-524203041
- from: openapi-document
where: $.components.schemas.Activity.properties.payload.oneOf
transform: return $.filter((el) => !el.$ref.includes('Aex141TransferEvent'))
reason: >
Ref '#/components/schemas/Aex141TransferEvent' is not referencing a valid location.
components,schemas,Activity,properties,payload,enum,2
https://github.com/aeternity/ae_mdw/issues/1344
- from: openapi-document
where: $.components.schemas.Activity.properties.payload
transform: >
Expand All @@ -43,44 +35,99 @@ directive:
https://github.com/Azure/autorest/issues/4118
- from: openapi-document
where: $.paths./names/search.get.responses.200.content.application/json.schema.allOf[0].properties.data.items.allOf^
transform: $.type ??= 'object'
reason: >
The schema 'get-200-application-json-allOf-properties-itemsItem' with an undefined type and
'allOf'/'anyOf'/'oneOf' is a bit ambiguous. This has been auto-corrected to 'type:object'
https://github.com/Azure/autorest/issues/4118
- from: openapi-document
where: $.paths.*.get.parameters.*.schema.oneOf^
where: $.paths.*.get.parameters.0.schema.oneOf^
transform: $.type ??= 'string'
reason: >
The schema 'paths·u0n47u·v2-keyblocks-hash_orkbi·get·parameters·0·schema' with an undefined
'paths·1159w94·v3-keyblocks-hash_or_kbi·get·responses·200·content·application-json·schema'
'paths·1159w94·v3-keyblocks-hash_or_kbi-microblocks·get·responses·200·content·application-json·schema'
The schema <path> with an undefined
type and 'allOf'/'anyOf'/'oneOf' is a bit ambiguous. This has been auto-corrected
to 'type:object'
https://github.com/Azure/autorest/issues/4118
- from: openapi-document
where: $.paths.*.get
transform: $.operationId = $.operationId.replace(/(_[a-z])/g, (group) => group[1].toUpperCase())
where: $.paths['/aex141/{contractId}/transfers'].get.parameters.3.in
set: query
reason: >
Schema violation: must be equal to one of the allowed values
(paths > /v3/aex141/{contractId}/transfers > get > parameters > 3 > required)
allowedValues: true
https://github.com/aeternity/ae_mdw/pull/1844
- from: openapi-document
where: $.paths['/aex141/{contractId}/transfers'].get.parameters.4.in
set: query
reason: >
Schema violation: must be equal to one of the allowed values
(paths > /v3/aex141/{contractId}/transfers > get > parameters > 4 > required)
allowedValues: true
https://github.com/aeternity/ae_mdw/pull/1844
- from: openapi-document
where: $.paths['/dex/{contract_id}/swaps'].get.parameters.1
transform: >
$.schema = { type: $.type, example: $.example };
delete $.type;
delete $.example;
reason: >
Schema violation: must NOT have additional properties
(paths > /v3/dex/{contract_id}/swaps > get > parameters > 1)
additionalProperty: type
https://github.com/aeternity/ae_mdw/pull/1844
- from: openapi-document
where: $.paths['/accounts/{account_id}/dex/swaps'].get.parameters.1
transform: >
$.schema = { type: $.type, example: $.example };
delete $.type;
delete $.example;
reason: >
Schema violation: must NOT have additional properties
(paths > /v3/accounts/{account_id}/dex/swaps > get > parameters > 1)
additionalProperty: type
https://github.com/aeternity/ae_mdw/pull/1844
- from: openapi-document
where: $.components.schemas.NameTx
transform: $.type = 'object'
reason: >
The schema 'NameTx' with an undefined type and declared properties is a bit ambiguous. This
has been auto-corrected to 'type:object'
https://github.com/aeternity/ae_mdw/pull/1849
- from: openapi-document
where: $.components.schemas.OracleTx
transform: $.type = 'object'
reason: >
The schema 'OracleTx' with an undefined type and declared properties is a bit ambiguous. This
has been auto-corrected to 'type:object'
https://github.com/aeternity/ae_mdw/pull/1849
- from: openapi-document
where: $.components.schemas.Name.properties.revoke
transform: delete $.example
reason: >
Otherwise autorest groups operations by 'get' prefix
https://github.com/aeternity/ae_mdw/issues/1357
Semantic violation: Sibling values alongside $ref will be ignored. See
https://github.com/Azure/autorest/blob/main/docs/openapi/howto/$ref-siblings.md for allowed
values (components > schemas > Name > properties > revoke)
keys: [ 'example' ]
https://github.com/aeternity/ae_mdw/pull/1849
- from: openapi-document
where: $.servers
transform: $ = []
reason: remove a server with /mdw/v2 url
reason: remove a server with /mdw/v3 url

- from: openapi-document
where: $.paths
transform: >
if ($doc.info.title === 'middleware') return $;
const apiPrefix = '/v2';
const apiPrefix = '/v3';
Object.keys($).forEach(key => {
$[apiPrefix + key] = $[key];
delete $[key];
});
reason: to don't add /v2 prefix to $host parameter
reason: to don't add /v3 prefix to $host parameter

- from: openapi-document
where: $.info.title
Expand Down

0 comments on commit b0015c0

Please sign in to comment.