diff --git a/runner/src/index.ts b/runner/src/index.ts index e9c56fc..5021a64 100644 --- a/runner/src/index.ts +++ b/runner/src/index.ts @@ -6,6 +6,11 @@ const EmbeddedObject = { anEnumArray: ["option1", "option2", "option3"], anIntArray: [1, 2, 3], aDate: "2024-07-23T16:03:34.000Z", + aDateArray: [ + "2024-07-23T16:03:34.000Z", + "2024-08-23T16:03:35.000Z", + "2024-09-23T16:03:36.000Z", + ] }; const inputBufferString = "Hello 🌍 World!🌍"; @@ -81,6 +86,30 @@ export function test() { } }); + Test.group("schema v1-draft mutating object", () => { + let input = JSON.stringify(EmbeddedObject); + let output: typeof EmbeddedObject = Test.call("mutateObject", input).json(); + Test.assertEqual('has bools', output.aBoolArray.length, 3) + output.aBoolArray.forEach((b, i) => { + Test.assertEqual(`inverted ${b}`, b, !EmbeddedObject.aBoolArray[i]) + }) + + Test.assertEqual('has strings', output.aStringArray.length, 3) + output.aStringArray.forEach((b, i) => { + Test.assertEqual(`mutated ${b}`, b, `hello ${EmbeddedObject.aStringArray[i]}`) + }) + + Test.assertEqual('has ints', output.anIntArray.length, 3) + output.anIntArray.forEach((b, i) => { + Test.assertEqual(`mutated ${b}`, b, EmbeddedObject.anIntArray[i] + 1) + }) + + Test.assertEqual('has dates', output.aDateArray.length, 3) + output.aDateArray.forEach((b, i) => { + Test.assertEqual(`one second added ${b}`, b, new Date((new Date(EmbeddedObject.aDateArray[i]).getTime() + 1000)).toISOString()) + }) + }); + Test.group("check signature and type variations", () => { // should call a the `noInputWithOutputHost` host function passing it // a string "noInputWithOutputHost" which it should return diff --git a/schema.yaml b/schema.yaml index 1fd9f6f..3ca1e2e 100644 --- a/schema.yaml +++ b/schema.yaml @@ -275,6 +275,24 @@ exports: source: | input.aBuffer = input.aBuffer.replace(b"Hello", b"Goodbye"); return input + mutateObject: + description: | + This function takes an EmbeddedObject and mutates it. It tests that + types are properly cast to their language equivalents + codeSamples: + - lang: typescript + source: | + input.aBoolArray = input.aBoolArray.map(v => !v) + input.aStringArray = input.aStringArray.map(v => `hello ${v}`) + input.anIntArray = input.anIntArray.map(v => v + 1) + input.aDateArray = input.aDateArray.map(v => new Date(v.getTime() + 1000)) // add one second + return input + input: + contentType: application/json + $ref: "#/components/schemas/EmbeddedObject" + output: + contentType: application/json + $ref: "#/components/schemas/EmbeddedObject" imports: reflectJsonObjectHost: description: | @@ -352,6 +370,12 @@ components: type: array items: type: integer + aDateArray: + description: a date array + type: array + items: + type: string + format: date-time aDate: description: a date type: string