-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.yaml
409 lines (394 loc) · 12.2 KB
/
schema.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
version: v1-draft
exports:
reflectJsonObject:
description: |
This function takes a KitchenSinkObject and returns a KitchenSinkObject.
It should come out the same way it came in.
codeSamples:
- lang: typescript
source: |
// pass this through the host function and return it back
return reflectJsonObjectHost(input)
- lang: go
source: |-
reflect, err := ReflectJsonObjectHost(input)
if err != nil {
return input, err
}
return *reflect, err
- lang: csharp
source: |-
return Host.ReflectJsonObjectHost(input);
- lang: zig
source: |
return Host.reflectJsonObjectHost(input);
- lang: rust
source: |
pdk::reflect_json_object_host(_input)
- lang: c++
source: |
return pdk::reflectJsonObjectHost(std::move(input));
- lang: python
source: |
return reflect_json_object_host(input)
input:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
output:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
reflectUtf8String:
description: |
This function takes a string and returns it.
Should come out the same way it came in.
codeSamples:
- lang: typescript
source: |
return reflectUtf8StringHost(input)
- lang: go
source: |-
reflect, err := ReflectUtf8StringHost(input)
if err != nil {
return "", err
}
return *reflect, nil
- lang: csharp
source: |-
return Host.ReflectUtf8StringHost(input);
- lang: zig
source: |
return Host.reflectUtf8StringHost(input);
- lang: rust
source: |
pdk::reflect_utf8_string_host(_input)
- lang: c++
source: |
return pdk::reflectUtf8StringHost(std::move(input));
- lang: python
source: |
return reflect_utf8_string_host(input)
input:
type: string
description: The input string
contentType: text/plain; charset=utf-8
output:
type: string
description: The output string
contentType: text/plain; charset=utf-8
reflectByteBuffer:
description: |
This function takes a byte buffer and returns it.
Should come out the same way it came in.
codeSamples:
- lang: typescript
source: |
return reflectByteBufferHost(input)
- lang: go
source: |-
reflect, err := ReflectByteBufferHost(input)
if err != nil {
return nil, err
}
return reflect, nil
- lang: csharp
source: |-
return Host.ReflectByteBufferHost(input);
- lang: zig
source: |
return Host.reflectByteBufferHost(input);
- lang: rust
source: |
pdk::reflect_byte_buffer_host(_input)
- lang: c++
source: |
return pdk::reflectByteBufferHost(std::move(input));
- lang: python
source: |
return reflect_byte_buffer_host(input)
input:
contentType: application/x-binary
type: buffer
description: The input byte buffer
output:
contentType: application/x-binary
type: buffer
description: The output byte buffer
noInputWithOutput:
description: a function that takes no input, but returns an output
output:
contentType: text/plain; charset=utf-8
type: string
codeSamples:
- lang: typescript
source: |
return noInputWithOutputHost();
- lang: zig
source: |-
return Host.noInputWithOutputHost();
- lang: go
source: |
output, err := NoInputWithOutputHost()
if err != nil {
return *output, err
}
return *output, nil
- lang: rust
source: |
pdk::no_input_with_output_host()
- lang: csharp
source: |-
return Host.NoInputWithOutputHost();
- lang: c++
source: |
return pdk::noInputWithOutputHost();
- lang: python
source: |
return no_input_with_output_host()
withInputNoOutput:
description: a function that takes input, but returns no output
input:
contentType: application/json
type: integer
codeSamples:
- lang: typescript
source: |
return withInputNoOutputHost(input);
- lang: zig
source: |-
return Host.withInputNoOutputHost(input);
- lang: go
source: |
err := WithInputNoOutputHost(input)
if err != nil {
return err
}
return nil
- lang: rust
source: |
pdk::with_input_no_output_host(_input)
- lang: csharp
source: |-
Host.WithInputNoOutputHost(input);
- lang: c++
source: |
return pdk::withInputNoOutputHost(input);
- lang: python
source: |
return with_input_no_output_host(input)
noInputNoOutput:
description: a function that takes no input, and returns no output
codeSamples:
- lang: typescript
source: |-
noInputNoOutputHost();
- lang: zig
source: |-
return Host.noInputNoOutputHost();
- lang: go
source: |
return NoInputNoOutputHost()
- lang: rust
source: |
pdk::no_input_no_output_host()
- lang: csharp
source: |-
Host.NoInputNoOutputHost();
- lang: c++
source: |
pdk::noInputNoOutputHost();
return std::expected<void, pdk::Error>();
- lang: python
source: |
return no_input_no_output_host()
helloToGoodbyeReplacement:
description: a function that should replace `Hello` with `Goodbye` within a byte buffer field on KitchenSinkObject
input:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
output:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
codeSamples:
- lang: typescript
source: |-
const encoder = new TextEncoder()
const oldBytes = encoder.encode("Hello")
const newBytes = encoder.encode("Goodbye")
const bufferView = new Uint8Array(input.aBuffer!)
const newBuffer = new ArrayBuffer(newBytes.length + bufferView.length - oldBytes.length)
const newBufferView = new Uint8Array(newBuffer)
newBufferView.set(newBytes, 0)
newBufferView.set(bufferView.subarray(oldBytes.length), newBytes.length)
input.aBuffer = newBuffer
return input
- lang: go
source: |-
old := []byte("Hello")
new := []byte("Goodbye")
input.ABuffer = append(new, input.ABuffer[len(old):]...)
return input, nil
- lang: csharp
source: |-
var buffer = System.Text.Encoding.UTF8.GetString(input.ABuffer);
buffer = buffer.Replace("Hello", "Goodbye");
input.ABuffer = System.Text.Encoding.UTF8.GetBytes(buffer);
return input;
- lang: rust
source: |-
let mut output = _input;
output.a_buffer = std::str::from_utf8(&output.a_buffer)?.replace("Hello", "Goodbye").as_bytes().to_vec();
Ok(output)
- lang: zig
source: |-
var output = input;
const old = "Hello";
const new = "Goodbye";
var arr = std.ArrayList(u8).init(std.heap.wasm_allocator);
try arr.insertSlice(0, new);
try arr.insertSlice(new.len, input.aBuffer[old.len..]);
output.aBuffer = try arr.toOwnedSlice();
return output;
- lang: c++
source: |-
std::string tomodify = std::string(
reinterpret_cast<char *>(input.aBuffer.data()), input.aBuffer.size());
const std::string search("Hello");
size_t pos = 0;
if ((pos = tomodify.find(search, pos)) != std::string::npos) {
tomodify.replace(pos, search.length(), "Goodbye");
const auto pString = reinterpret_cast<uint8_t *>(tomodify.data());
input.aBuffer = std::vector<uint8_t>(pString, pString + tomodify.size());
}
return std::make_unique<pdk::KitchenSinkObject>(std::move(input));
- lang: python
source: |
input.aBuffer = input.aBuffer.replace(b"Hello", b"Goodbye"); return input
imports:
reflectJsonObjectHost:
description: |
This function takes a KitchenSinkObject and returns a KitchenSinkObject.
It should come out the same way it came in. It's the same as the export.
But the export should call this.
input:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
output:
contentType: application/json
$ref: "#/components/schemas/KitchenSinkObject"
reflectUtf8StringHost:
description: |
This function takes a string and returns it.
Should come out the same way it came in. Same as export.
input:
type: string
description: The input string
contentType: text/plain; charset=utf-8
output:
type: string
description: The output string
contentType: text/plain; charset=utf-8
reflectByteBufferHost:
description: |
This function takes a bugger and returns it.
Should come out the same way it came in. Same as export.
input:
contentType: application/x-binary
type: buffer
description: The input byte buffer
output:
contentType: application/x-binary
type: buffer
description: The output byte buffer
noInputWithOutputHost:
description: a function that takes no input, but returns an output
output:
contentType: text/plain; charset=utf-8
type: string
withInputNoOutputHost:
description: a function that takes input, but returns no output
input:
contentType: application/json
type: integer
noInputNoOutputHost:
description: a function that takes no input, and returns no output
components:
schemas:
EmbeddedObject:
description: An embedded object, has some arrays too
properties:
aBoolArray:
description: an array of bools
type: array
items:
type: boolean
aStringArray:
description: an array of strings
type: array
items:
type: string
anEnumArray:
description: an array of enums
type: array
items:
$ref: "#/components/schemas/AStringEnum"
anIntArray:
description: an array of enums
type: array
items:
type: integer
aDate:
description: a date
type: string
format: date-time
AStringEnum:
description: A string enum
type: string
enum:
- option1
- option2
- option3
KitchenSinkObject:
description: A json object with every type of property
properties:
anOptionalString:
type: string
description: A string but not required
nullable: true
aString:
type: string
description: A String
anInt:
type: integer
description: An Integer
aFloat:
type: number
format: float
description: A Float
aDouble:
type: number
format: double
description: A Double
aBool:
type: boolean
description: A Boolean
anUntypedObject:
type: object
description: An untyped object
anEnum:
description: A string enum (prop comment)
$ref: "#/components/schemas/AStringEnum"
anEmbeddedObject:
description: A embedded object array(prop comment)
$ref: "#/components/schemas/EmbeddedObject"
anEmbeddedObjectArray:
description: A embedded object array (prop comment)
type: array
items:
$ref: "#/components/schemas/EmbeddedObject"
aDate:
description: a date
type: string
format: date-time
aBuffer:
description: a byte buffer
type: buffer