From 7a5bda377bf6d13aa077b2da5d6b99c5bd05c8ee Mon Sep 17 00:00:00 2001 From: Kevin Pearson Date: Mon, 6 Nov 2023 13:35:01 -0800 Subject: [PATCH 1/4] fix: Provider openrpc response and error methods have a wrapper object --- src/macrofier/engine.mjs | 4 ++-- src/shared/modules.mjs | 45 +++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 73a805fd..8e14b263 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1070,7 +1070,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) } const method = { name: methodObj.name, - params: methodObj.params.map(p => p.name).join(', '), + params: methodObj.params.map(p => p.name).join(''), transforms: null, alternative: null, deprecated: isDeprecatedMethod(methodObj), @@ -1093,7 +1093,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) } } - const paramDelimiter = config.operators ? config.operators.paramDelimiter : ', ' + const paramDelimiter = config.operators ? config.operators.paramDelimiter : '' const temporalItemName = isTemporalSetMethod(methodObj) ? methodObj.result.schema.items && methodObj.result.schema.items.title || 'Item' : '' const temporalAddName = isTemporalSetMethod(methodObj) ? `on${temporalItemName}Available` : '' diff --git a/src/shared/modules.mjs b/src/shared/modules.mjs index 927092c2..f1efc1bc 100644 --- a/src/shared/modules.mjs +++ b/src/shared/modules.mjs @@ -625,21 +625,16 @@ const createResponseFromProvider = (provider, type, json) => { if (provider.tags.find(t => t[`x-${type.toLowerCase()}`])) { response.params = [ { - name: type.toLowerCase(), - required: true, + name: "correlationId", schema: { - allOf: [ - { - "$ref": "https://meta.comcast.com/firebolt/types#/definitions/ProviderResponse" // use this schema for both Errors and Results - }, - { - "type": "object", - "properties": { - "result": provider.tags.find(t => t[`x-${type.toLowerCase()}`])[`x-${type.toLowerCase()}`] - } - } - ] - } + type: "string" + }, + required: true + }, + { + name: type === 'Error' ? 'error' : "result", + schema: provider.tags.find(t => t[`x-${type.toLowerCase()}`])[`x-${type.toLowerCase()}`], + required: true } ] @@ -680,11 +675,12 @@ const createResponseFromProvider = (provider, type, json) => { name: schema.examples.length === 1 ? "Example" : `Example #${n++}`, params: [ { - name: `${type.toLowerCase()}`, - value: { - correlationId: "123", - result: param - } + name: 'correlationId', + value: '123' + }, + { + name: 'result', + value: param } ], result: { @@ -723,11 +719,12 @@ const createResponseFromProvider = (provider, type, json) => { name: 'Example 1', params: [ { - name: `${type.toLowerCase()}`, - value: { - correlationId: "123", - result: value - } + name: 'correlationId', + value: '123' + }, + { + name: type === 'Error' ? 'error' : 'result', + value } ], result: { From 7e70c0bae25fc48190d44a4ec64529bc049d6209 Mon Sep 17 00:00:00 2001 From: Kevin Pearson Date: Tue, 7 Nov 2023 12:04:57 -0800 Subject: [PATCH 2/4] fix: Provider openrpc response and error methods have a wrapper object --- src/macrofier/engine.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 8e14b263..543e9a57 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1070,7 +1070,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) } const method = { name: methodObj.name, - params: methodObj.params.map(p => p.name).join(''), + params: methodObj.params.map(p => p.name).join(', '), transforms: null, alternative: null, deprecated: isDeprecatedMethod(methodObj), From 4e644b2157a851dfb2c2f3f7e55049981f7aedc2 Mon Sep 17 00:00:00 2001 From: Kevin Pearson Date: Tue, 7 Nov 2023 22:19:35 -0800 Subject: [PATCH 3/4] fix: Provider openrpc response and error methods have a wrapper object --- test/openrpc/simple.json | 55 +++++++++++++++++++++++++++++++++++++++ test/suite/simple.test.js | 42 +++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/test/openrpc/simple.json b/test/openrpc/simple.json index 0d7f41c7..7d009546 100644 --- a/test/openrpc/simple.json +++ b/test/openrpc/simple.json @@ -311,6 +311,61 @@ } } ] + }, + { + "name": "methodWithMultipleParams", + "summary": "A method that takes two parameters", + "description": "A method that takes two parameters", + "tags": [ + { + "name": "capabilities", + "x-uses": ["xrn:firebolt:capability:test:test"] + } + ], + "params": [ + { + "name": "id", + "required": true, + "schema": { + "type": "number" + }, + "summary": "A test number" + }, + { + "name": "title", + "required": true, + "schema": { + "type": "string" + }, + "summary": "A string test parameter." + } + ], + "result": { + "name": "result", + "summary": "A result for testing basic method generation.", + "schema": { + "type": "null" + } + }, + "examples": [ + { + "name": "Default Example", + "params": [ + { + "name": "id", + "value": 42 + }, + { + "name": "title", + "value": "test" + } + ], + "result": { + "name": "Default Result", + "value": null + } + } + ] } ], "components": { diff --git a/test/suite/simple.test.js b/test/suite/simple.test.js index e9ca5fd7..971bc48e 100644 --- a/test/suite/simple.test.js +++ b/test/suite/simple.test.js @@ -17,11 +17,51 @@ */ import { Simple } from '../../build/sdk/javascript/src/sdk.mjs' -import Setup from '../Setup' import { expect } from '@jest/globals'; +let state = { + spy: null, + responder: null +} + +class TransportSpy { + + constructor(spy) { + state.spy = spy + } + + async send(msg) { + let parsed = JSON.parse(msg) + console.log(state.spy) + state.spy(parsed) + this.responder(JSON.stringify({ + jsonrpc: '2.0', + id: parsed.id, + result: {} + })) + } + + receive(callback) { + this.responder = callback + } +} + test('Basic', () => { return Simple.method(true).then(result => { expect(result.foo).toBe("here's foo") }) }); + +test('Multiple Parameters', async () => { + let cb = null; + let promise = new Promise((resolve, reject) => { + cb = resolve + }) + window['__firebolt'].setTransportLayer(new TransportSpy(cb)) + await Simple.methodWithMultipleParams(5, 'foo') + let msg = await promise + expect(msg.method).toBe('simple.methodWithMultipleParams') + expect(msg.params.id).toBe(5) + expect(msg.params.title).toBe('foo') + console.log(JSON.stringify(msg)) +}); From 43a735eb86c1803f5e9156a2f8fab31ce7cdd020 Mon Sep 17 00:00:00 2001 From: Kevin Pearson Date: Tue, 7 Nov 2023 22:22:41 -0800 Subject: [PATCH 4/4] fix: Provider openrpc response and error methods have a wrapper object --- test/suite/simple.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/suite/simple.test.js b/test/suite/simple.test.js index 971bc48e..c969afce 100644 --- a/test/suite/simple.test.js +++ b/test/suite/simple.test.js @@ -19,21 +19,17 @@ import { Simple } from '../../build/sdk/javascript/src/sdk.mjs' import { expect } from '@jest/globals'; -let state = { - spy: null, - responder: null -} class TransportSpy { constructor(spy) { - state.spy = spy + this.spy = spy + this.responder = null } async send(msg) { let parsed = JSON.parse(msg) - console.log(state.spy) - state.spy(parsed) + this.spy(parsed) this.responder(JSON.stringify({ jsonrpc: '2.0', id: parsed.id,