@voxgig/sdkgen 4.37.0 → 4.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/helpers/flowGuard.js +4 -4
- package/dist/helpers/flowGuard.js.map +1 -1
- package/dist/helpers/liveDiscovery.d.ts +7 -0
- package/dist/helpers/liveDiscovery.js +20 -0
- package/dist/helpers/liveDiscovery.js.map +1 -0
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +4 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/pointPath.d.ts +2 -1
- package/dist/helpers/pointPath.js +6 -0
- package/dist/helpers/pointPath.js.map +1 -1
- package/dist/helpers/testPolicy.d.ts +14 -4
- package/dist/helpers/testPolicy.js +152 -54
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/sdkgen.d.ts +8 -6
- package/dist/sdkgen.js +11 -5
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +7 -3
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/TestDirect_c.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestEntity_cpp.ts +33 -10
- package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +12 -12
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +73 -28
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +12 -10
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +67 -23
- package/project/.sdk/src/cmp/java/TestDirect_java.ts +12 -11
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +71 -23
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +13 -12
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +41 -17
- package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +12 -10
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +64 -23
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +9 -5
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +61 -23
- package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -5
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +58 -24
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +9 -5
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +61 -23
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +10 -6
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +59 -27
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -5
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +59 -23
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +9 -8
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +56 -24
- package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +3 -2
- package/project/.sdk/src/cmp/scala/TestEntity_scala.ts +36 -9
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +15 -32
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +41 -17
- package/project/.sdk/tm/c/tests/transport_test.c +33 -0
- package/project/.sdk/tm/c/utility/fetcher.c +151 -2
- package/project/.sdk/tm/c/utility/make_url.c +8 -6
- package/project/.sdk/tm/clojure/src/sdk/core.clj +17 -10
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +38 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +5 -4
- package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +69 -0
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +3 -1
- package/project/.sdk/tm/csharp/utility/MakeUrl.cs +5 -4
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +10 -6
- package/project/.sdk/tm/elixir/test/pipeline_test.exs +61 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +60 -0
- package/project/.sdk/tm/go/utility/fetcher.go +15 -4
- package/project/.sdk/tm/go/utility/make_url.go +4 -3
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +47 -0
- package/project/.sdk/tm/java/utility/MakeUrl.java +5 -4
- package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +5 -3
- package/project/.sdk/tm/js/test/live-runner.js +4 -3
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +40 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +41 -0
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +4 -3
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +61 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +54 -6
- package/project/.sdk/tm/lua/utility/make_url.lua +5 -4
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +5 -5
- package/project/.sdk/tm/perl/t/primary_utility.t +54 -0
- package/project/.sdk/tm/perl/utility/fetcher.pm +65 -11
- package/project/.sdk/tm/perl/utility/make_url.pm +4 -3
- package/project/.sdk/tm/php/test/PipelineTest.php +52 -0
- package/project/.sdk/tm/php/utility/Fetcher.php +81 -15
- package/project/.sdk/tm/php/utility/MakeUrl.php +5 -3
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/make_url.py +5 -4
- package/project/.sdk/tm/py/test/test_primary_utility.py +52 -0
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +46 -0
- package/project/.sdk/tm/rb/utility/fetcher.rb +41 -5
- package/project/.sdk/tm/rb/utility/make_url.rb +5 -3
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +65 -0
- package/project/.sdk/tm/rust/utility/make_url.rs +7 -6
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +47 -1
- package/project/.sdk/tm/scala/utility/Make.scala +8 -6
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +59 -15
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +4 -4
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +72 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/live-runner.ts +4 -3
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +40 -0
- package/project/.sdk/tm/zig/core/utility.zig +5 -5
- package/project/sdkgen-package.json +1 -1
- package/src/helpers/flowGuard.ts +4 -4
- package/src/helpers/liveDiscovery.ts +31 -0
- package/src/helpers/opShape.ts +6 -0
- package/src/helpers/pointPath.ts +8 -0
- package/src/helpers/testPolicy.ts +193 -55
- package/src/sdkgen.ts +13 -3
- package/src/utility.ts +10 -4
|
@@ -27,12 +27,12 @@ import {
|
|
|
27
27
|
isAuthActive,
|
|
28
28
|
serverVarEnv,
|
|
29
29
|
serverVariables,
|
|
30
|
-
entityDataIdField, envName, envToken,
|
|
30
|
+
entityDataIdField, entityRecordIdField, envName, envToken,
|
|
31
31
|
phpEntityAccessor,
|
|
32
32
|
invalidRequest,
|
|
33
33
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
34
34
|
liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
|
|
35
|
-
|
|
35
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
36
36
|
liveEntity,
|
|
37
37
|
} from '@voxgig/sdkgen'
|
|
38
38
|
|
|
@@ -45,6 +45,17 @@ import { formatPhpValue } from './utility_php'
|
|
|
45
45
|
function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: string,
|
|
46
46
|
strict: boolean): string {
|
|
47
47
|
let out = ''
|
|
48
|
+
if (null != needs.examples) {
|
|
49
|
+
out += ` if (!empty($setup["live"])) {
|
|
50
|
+
foreach ([${needs.examples
|
|
51
|
+
.map(([k, ex]: any) => JSON.stringify(k) + ' => ' + formatPhpValue(ex)).join(', ')}] as $_liveKey => $_liveEx) {
|
|
52
|
+
if (!empty($setup["synthetic_only"]) || null === ($setup["idmap"][$_liveKey] ?? null)) {
|
|
53
|
+
$setup["idmap"][$_liveKey] = $_liveEx;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
}
|
|
48
59
|
if (0 < needs.keys.length) {
|
|
49
60
|
out += ` if (!empty($setup["live"])) {
|
|
50
61
|
foreach ([${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}] as $_liveKey) {
|
|
@@ -62,6 +73,13 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: strin
|
|
|
62
73
|
`
|
|
63
74
|
}
|
|
64
75
|
out += ' $client = $setup["client"];\n'
|
|
76
|
+
if (null != needs.record) {
|
|
77
|
+
out += ` if (!empty($setup["live"])) {
|
|
78
|
+
Runner::live_existing($setup, self::LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
79
|
+
fn() => [["id" => $setup["idmap"][${JSON.stringify(needs.record)}] ?? null]]);
|
|
80
|
+
}
|
|
81
|
+
`
|
|
82
|
+
}
|
|
65
83
|
if (null != needs.discover) {
|
|
66
84
|
const match = Object.entries(needs.discover)
|
|
67
85
|
.map(([k, v]: any) => `${JSON.stringify(k)} => $setup["idmap"][${JSON.stringify(v)}] ?? null`)
|
|
@@ -270,19 +288,18 @@ ${failureTests(model, entity, accessor)}${validateListTest(model, entity, access
|
|
|
270
288
|
`)
|
|
271
289
|
}
|
|
272
290
|
|
|
273
|
-
const getOnly
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
${liveExcludedLines(getOnly).map((line) =>
|
|
291
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
292
|
+
Content(` if (!empty($setup["live"])${getOnly ? ` && getenv(${formatPhpValue(LIVE_GETONLY_ENV)}) === "TRUE"` : ''}) {
|
|
293
|
+
${liveExcludedLines(plan).map((line) =>
|
|
277
294
|
' fwrite(STDOUT, ' + formatPhpValue(line) + ' . "\\n");\n').join('')}`)
|
|
278
|
-
if (
|
|
279
|
-
Content(` $this->markTestSkipped(${formatPhpValue(liveExcludedSummary(
|
|
295
|
+
if (!runs) {
|
|
296
|
+
Content(` $this->markTestSkipped(${formatPhpValue(liveExcludedSummary(plan))});
|
|
280
297
|
}
|
|
281
298
|
|
|
282
299
|
`)
|
|
283
300
|
}
|
|
284
301
|
else {
|
|
285
|
-
flowBody(
|
|
302
|
+
flowBody(plan.flow)
|
|
286
303
|
Content(` return;
|
|
287
304
|
}
|
|
288
305
|
|
|
@@ -305,7 +322,7 @@ ${liveExcludedLines(getOnly).map((line) =>
|
|
|
305
322
|
$entity_data_file = __DIR__ . '/../../.sdk/test/entity/${entity.name}/${entity.Name}TestData.json';
|
|
306
323
|
$entity_data_source = file_get_contents($entity_data_file);
|
|
307
324
|
$entity_data = json_decode($entity_data_source, true);
|
|
308
|
-
|
|
325
|
+
${fixtureIdentity(entity)}
|
|
309
326
|
$options = [];
|
|
310
327
|
$options["entity"] = $entity_data["existing"];
|
|
311
328
|
|
|
@@ -438,7 +455,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
438
455
|
$this->assertNotNull($${datavar});
|
|
439
456
|
`)
|
|
440
457
|
if (null != ctx.entity.id) {
|
|
441
|
-
Content(` $this->assertNotNull($${datavar}[
|
|
458
|
+
Content(` $this->assertNotNull($${datavar}[${rid(ctx.entity)}]);
|
|
442
459
|
`)
|
|
443
460
|
}
|
|
444
461
|
}
|
|
@@ -477,7 +494,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
477
494
|
Content(` ];
|
|
478
495
|
`)
|
|
479
496
|
}
|
|
480
|
-
Content(liveFill(entity, step, matchvar))
|
|
497
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
481
498
|
|
|
482
499
|
Content(`
|
|
483
500
|
$${listvar}_result = $${entvar}->list($${matchvar}, null);
|
|
@@ -497,7 +514,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
497
514
|
Content(`
|
|
498
515
|
$found_item = sdk_select(
|
|
499
516
|
Runner::entity_list_to_data($${listvar}_result),
|
|
500
|
-
[
|
|
517
|
+
[${rid(entity)} => $${refDataVar}[${rid(entity)}]]);
|
|
501
518
|
$this->assertNotEmpty($found_item);
|
|
502
519
|
`)
|
|
503
520
|
} else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
|
|
@@ -505,7 +522,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
505
522
|
Content(`
|
|
506
523
|
$not_found_item = sdk_select(
|
|
507
524
|
Runner::entity_list_to_data($${listvar}_result),
|
|
508
|
-
[
|
|
525
|
+
[${rid(entity)} => $${refDataVar}[${rid(entity)}]]);
|
|
509
526
|
$this->assertEmpty($not_found_item);
|
|
510
527
|
`)
|
|
511
528
|
}
|
|
@@ -538,7 +555,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
538
555
|
Content(` $${datavar}_up = [
|
|
539
556
|
`)
|
|
540
557
|
if (hasEntIdU) {
|
|
541
|
-
Content(` "id" => $${srcdatavar}[
|
|
558
|
+
Content(` "id" => $${srcdatavar}[${rid(entity)}],
|
|
542
559
|
`)
|
|
543
560
|
}
|
|
544
561
|
|
|
@@ -573,7 +590,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
573
590
|
$this->assertNotNull($${resdatavar});
|
|
574
591
|
`)
|
|
575
592
|
if (hasEntIdU) {
|
|
576
|
-
Content(` $this->assertEquals($${resdatavar}[
|
|
593
|
+
Content(` $this->assertEquals($${resdatavar}[${rid(entity)}], $${datavar}_up["id"]);
|
|
577
594
|
`)
|
|
578
595
|
}
|
|
579
596
|
|
|
@@ -631,17 +648,17 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
631
648
|
}
|
|
632
649
|
if (hasEntId) {
|
|
633
650
|
Content(` $${matchvar} = [
|
|
634
|
-
"id" => $${srcdatavar}[
|
|
651
|
+
"id" => $${srcdatavar}[${rid(entity)}],
|
|
635
652
|
];
|
|
636
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
|
|
653
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
|
|
637
654
|
$${datavar}_load_result = Helpers::to_map(is_object($${datavar}_loaded) && method_exists($${datavar}_loaded, 'data_get') ? $${datavar}_loaded->data_get() : $${datavar}_loaded);
|
|
638
655
|
$this->assertNotNull($${datavar}_load_result);
|
|
639
|
-
$this->assertEquals($${datavar}_load_result[
|
|
656
|
+
$this->assertEquals($${datavar}_load_result[${rid(entity)}], $${srcdatavar}[${rid(entity)}]);
|
|
640
657
|
`)
|
|
641
658
|
}
|
|
642
659
|
else {
|
|
643
660
|
Content(` $${matchvar} = [];
|
|
644
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
|
|
661
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} $${datavar}_loaded = $${entvar}->load($${matchvar}, null);
|
|
645
662
|
$this->assertNotNull($${datavar}_loaded);
|
|
646
663
|
`)
|
|
647
664
|
}
|
|
@@ -670,7 +687,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
670
687
|
}
|
|
671
688
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
672
689
|
Content(` $${matchvar} = [
|
|
673
|
-
"id" => $${srcdatavar}[
|
|
690
|
+
"id" => $${srcdatavar}[${rid(entity)}],
|
|
674
691
|
];
|
|
675
692
|
${parentMatch(step, matchvar)} $${entvar}->remove($${matchvar}, null);
|
|
676
693
|
`)
|
|
@@ -678,12 +695,33 @@ ${parentMatch(step, matchvar)} $${entvar}->remove($${matchvar}, null);
|
|
|
678
695
|
|
|
679
696
|
|
|
680
697
|
|
|
698
|
+
// The record field the entity's identity is read from, as a PHP string.
|
|
699
|
+
function rid(entity: any): string {
|
|
700
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
705
|
+
// in another field reads the key from there too.
|
|
706
|
+
function fixtureIdentity(entity: any): string {
|
|
707
|
+
const field = entityRecordIdField(entity)
|
|
708
|
+
const name = JSON.stringify(entity.name)
|
|
709
|
+
return 'id' === field ? '' : `
|
|
710
|
+
foreach (($entity_data["existing"][${name}] ?? []) as $rec_key => $rec) {
|
|
711
|
+
if (is_array($rec) && isset($rec["id"])) {
|
|
712
|
+
$entity_data["existing"][${name}][$rec_key][${JSON.stringify(field)}] = $rec["id"];
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
`
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
|
|
681
719
|
// A child's route names its parents, and an entity no earlier step has
|
|
682
720
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
683
721
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
684
722
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
685
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
686
|
-
const fills = liveStepExamples(entity, step)
|
|
723
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
724
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
687
725
|
return 0 === fills.length ? '' : ` if (!empty($setup["live"])) {
|
|
688
726
|
${fills.map(([k, ex]) => ` $${matchvar}[${JSON.stringify(k)}] = ${formatPhpValue(ex)};\n`).join('')} }
|
|
689
727
|
`
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables, envName, envToken,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
liveStrict,
|
|
20
21
|
liveStrictNote,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
liveQueryExamples,
|
|
25
26
|
liveEntity,
|
|
26
27
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
28
|
+
liveDirectDiscovery,
|
|
27
29
|
} from '@voxgig/sdkgen'
|
|
28
30
|
|
|
29
31
|
|
|
@@ -130,7 +132,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
130
132
|
const listOp = entity.op?.list
|
|
131
133
|
|
|
132
134
|
const loadPoint = loadOp?.points?.[0]
|
|
133
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
135
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
134
136
|
const allLoadParams = loadPoint?.g?.params || []
|
|
135
137
|
// Some upstream OpenAPI specs declare a parameter as `in: path` even when
|
|
136
138
|
// that path has no `{name}` placeholder for it. Only path params that
|
|
@@ -150,7 +152,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
150
152
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
151
153
|
|
|
152
154
|
const listPoint = listOp?.points?.[0]
|
|
153
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
155
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
154
156
|
const listParams = listPoint?.g?.params || []
|
|
155
157
|
|
|
156
158
|
const loadLiveQueryLines = liveQueryExamples(loadPoint)
|
|
@@ -261,8 +263,10 @@ ${listLiveQueryLines ? ' if setup["live"]:\n' + listLiveQueryLines : ''}`
|
|
|
261
263
|
`)
|
|
262
264
|
}
|
|
263
265
|
else if (hasLoad && loadPoint) {
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
267
|
+
const discover = null != discovery
|
|
268
|
+
const idParam = discovery?.param
|
|
269
|
+
const idField = discovery?.field
|
|
266
270
|
const loadLiveIdKeys: string[] = loadAllHaveExamples ? [] :
|
|
267
271
|
discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
|
|
268
272
|
loadParams.map(liveKey)
|
|
@@ -295,9 +299,9 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
|
|
|
295
299
|
if 0 == len(records):
|
|
296
300
|
runner.live_empty("The account has no ${entity.name} record to load")
|
|
297
301
|
first = records[0] if isinstance(records[0], dict) else {}
|
|
298
|
-
if first.get("${
|
|
302
|
+
if first.get("${idField}") is None:
|
|
299
303
|
runner.live_miss(LIVE_STRICT, "Live load blocked: discovery returned no usable identity")
|
|
300
|
-
params["${idParam}"] = first.get("${
|
|
304
|
+
params["${idParam}"] = first.get("${idField}")
|
|
301
305
|
`)
|
|
302
306
|
for (const p of loadParams.filter((p: any) => idParam !== p.n)) {
|
|
303
307
|
Content(` params["${p.n}"] = setup["idmap"].get("${liveKey(p)}")
|
|
@@ -27,11 +27,11 @@ import {
|
|
|
27
27
|
isAuthActive,
|
|
28
28
|
serverVarEnv,
|
|
29
29
|
serverVariables,
|
|
30
|
-
entityDataIdField, envName, envToken,
|
|
30
|
+
entityDataIdField, entityRecordIdField, envName, envToken,
|
|
31
31
|
invalidRequest,
|
|
32
32
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
33
33
|
liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
|
|
34
|
-
|
|
34
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
35
35
|
liveEntity,
|
|
36
36
|
} from '@voxgig/sdkgen'
|
|
37
37
|
|
|
@@ -40,6 +40,14 @@ import {
|
|
|
40
40
|
// the ids it binds, and a create-less load reading the first listed record.
|
|
41
41
|
function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
|
|
42
42
|
let out = ''
|
|
43
|
+
if (null != needs.examples) {
|
|
44
|
+
out += ` if setup["live"]:
|
|
45
|
+
for _live_key, _live_ex in {${needs.examples
|
|
46
|
+
.map(([k, ex]: any) => JSON.stringify(k) + ': ' + pyLit(ex)).join(', ')}}.items():
|
|
47
|
+
if setup.get("synthetic_only") or setup["idmap"].get(_live_key) is None:
|
|
48
|
+
setup["idmap"][_live_key] = _live_ex
|
|
49
|
+
`
|
|
50
|
+
}
|
|
43
51
|
if (0 < needs.keys.length) {
|
|
44
52
|
out += ` if setup["live"]:
|
|
45
53
|
for _live_key in [${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')}]:
|
|
@@ -53,6 +61,12 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
|
|
|
53
61
|
`
|
|
54
62
|
}
|
|
55
63
|
out += ' client = setup["client"]\n'
|
|
64
|
+
if (null != needs.record) {
|
|
65
|
+
out += ` if setup["live"]:
|
|
66
|
+
runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)},
|
|
67
|
+
lambda: [{"id": setup["idmap"].get(${JSON.stringify(needs.record)})}])
|
|
68
|
+
`
|
|
69
|
+
}
|
|
56
70
|
if (null != needs.discover) {
|
|
57
71
|
const match = Object.entries(needs.discover)
|
|
58
72
|
.map(([k, v]: any) => `${JSON.stringify(k)}: setup["idmap"].get(${JSON.stringify(v)})`)
|
|
@@ -255,24 +269,24 @@ ${strict ? '' : ` @runner.live_observe("${PROJUPPER}_TEST_LIVE", LIVE_STRICT)
|
|
|
255
269
|
}
|
|
256
270
|
|
|
257
271
|
// A python block cannot hold steps emitted at the method's own indent,
|
|
258
|
-
// so the steps a
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
Content(` if setup["live"] and os.environ.get(${JSON.stringify(LIVE_GETONLY_ENV)}) == "TRUE":
|
|
263
|
-
${liveExcludedLines(
|
|
264
|
-
' return self.
|
|
265
|
-
' pytest.skip(' + pyLit(liveExcludedSummary(
|
|
272
|
+
// so the steps a live run keeps go in a method of their own.
|
|
273
|
+
const gates = liveGates(entity, basicflow)
|
|
274
|
+
const method = (getOnly: boolean) => getOnly ? '_run_get_only_flow' : '_run_live_flow'
|
|
275
|
+
for (const { getOnly, plan, runs } of gates) {
|
|
276
|
+
Content(` if setup["live"]${getOnly ? ` and os.environ.get(${JSON.stringify(LIVE_GETONLY_ENV)}) == "TRUE"` : ''}:
|
|
277
|
+
${liveExcludedLines(plan).map((line) => ' print(' + pyLit(line) + ')\n').join('')}${runs ?
|
|
278
|
+
' return self.' + method(getOnly) + '(setup)\n' :
|
|
279
|
+
' pytest.skip(' + pyLit(liveExcludedSummary(plan)) + ')\n'}
|
|
266
280
|
`)
|
|
267
281
|
}
|
|
268
282
|
|
|
269
283
|
flowBody(basicflow)
|
|
270
284
|
|
|
271
|
-
|
|
285
|
+
for (const { getOnly, plan } of gates.filter((gate) => gate.runs)) {
|
|
272
286
|
Content(`
|
|
273
|
-
def
|
|
287
|
+
def ${method(getOnly)}(self, setup):
|
|
274
288
|
`)
|
|
275
|
-
flowBody(
|
|
289
|
+
flowBody(plan.flow)
|
|
276
290
|
}
|
|
277
291
|
|
|
278
292
|
Content(`
|
|
@@ -285,7 +299,7 @@ def _${entity.name}_basic_setup(extra):
|
|
|
285
299
|
entity_data_source = f.read()
|
|
286
300
|
|
|
287
301
|
entity_data = json.loads(entity_data_source)
|
|
288
|
-
|
|
302
|
+
${fixtureIdentity(entity)}
|
|
289
303
|
options = {}
|
|
290
304
|
options["entity"] = entity_data.get("existing")
|
|
291
305
|
|
|
@@ -410,7 +424,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
410
424
|
assert ${datavar} is not None
|
|
411
425
|
`)
|
|
412
426
|
if (hasEntIdC) {
|
|
413
|
-
Content(` assert ${datavar}[
|
|
427
|
+
Content(` assert ${datavar}[${rid(ctx.entity)}] is not None
|
|
414
428
|
`)
|
|
415
429
|
}
|
|
416
430
|
}
|
|
@@ -449,7 +463,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
449
463
|
Content(` }
|
|
450
464
|
`)
|
|
451
465
|
}
|
|
452
|
-
Content(liveFill(entity, step, matchvar))
|
|
466
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
453
467
|
|
|
454
468
|
Content(`
|
|
455
469
|
${listvar}_result = ${entvar}.list(${matchvar}, None)
|
|
@@ -469,7 +483,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
469
483
|
Content(`
|
|
470
484
|
found_item = vs.select(
|
|
471
485
|
runner.entity_list_to_data(${listvar}_result),
|
|
472
|
-
{
|
|
486
|
+
{${rid(entity)}: ${refDataVar}[${rid(entity)}]})
|
|
473
487
|
assert not vs.isempty(found_item)
|
|
474
488
|
`)
|
|
475
489
|
} else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
|
|
@@ -477,7 +491,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
477
491
|
Content(`
|
|
478
492
|
not_found_item = vs.select(
|
|
479
493
|
runner.entity_list_to_data(${listvar}_result),
|
|
480
|
-
{
|
|
494
|
+
{${rid(entity)}: ${refDataVar}[${rid(entity)}]})
|
|
481
495
|
assert vs.isempty(not_found_item)
|
|
482
496
|
`)
|
|
483
497
|
}
|
|
@@ -510,7 +524,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
510
524
|
Content(` ${datavar}_up = {
|
|
511
525
|
`)
|
|
512
526
|
if (hasEntIdU) {
|
|
513
|
-
Content(` "id": ${srcdatavar}[
|
|
527
|
+
Content(` "id": ${srcdatavar}[${rid(entity)}],
|
|
514
528
|
`)
|
|
515
529
|
}
|
|
516
530
|
|
|
@@ -544,7 +558,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
544
558
|
assert ${resdatavar} is not None
|
|
545
559
|
`)
|
|
546
560
|
if (hasEntIdU) {
|
|
547
|
-
Content(` assert ${resdatavar}[
|
|
561
|
+
Content(` assert ${resdatavar}[${rid(entity)}] == ${datavar}_up["id"]
|
|
548
562
|
`)
|
|
549
563
|
}
|
|
550
564
|
|
|
@@ -601,17 +615,17 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
601
615
|
}
|
|
602
616
|
if (hasEntId) {
|
|
603
617
|
Content(` ${matchvar} = {
|
|
604
|
-
"id": ${srcdatavar}[
|
|
618
|
+
"id": ${srcdatavar}[${rid(entity)}],
|
|
605
619
|
}
|
|
606
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
|
|
620
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
|
|
607
621
|
${datavar}_load_result = helpers.to_map(runner.entity_data(${datavar}_loaded))
|
|
608
622
|
assert ${datavar}_load_result is not None
|
|
609
|
-
assert ${datavar}_load_result[
|
|
623
|
+
assert ${datavar}_load_result[${rid(entity)}] == ${srcdatavar}[${rid(entity)}]
|
|
610
624
|
`)
|
|
611
625
|
}
|
|
612
626
|
else {
|
|
613
627
|
Content(` ${matchvar} = {}
|
|
614
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
|
|
628
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
|
|
615
629
|
assert ${datavar}_loaded is not None
|
|
616
630
|
`)
|
|
617
631
|
}
|
|
@@ -640,7 +654,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
640
654
|
}
|
|
641
655
|
// Always match the prior-created entity by id to avoid mock-order flakes.
|
|
642
656
|
Content(` ${matchvar} = {
|
|
643
|
-
"id": ${srcdatavar}[
|
|
657
|
+
"id": ${srcdatavar}[${rid(entity)}],
|
|
644
658
|
}
|
|
645
659
|
${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, None)
|
|
646
660
|
`)
|
|
@@ -648,12 +662,30 @@ ${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, None)
|
|
|
648
662
|
|
|
649
663
|
|
|
650
664
|
|
|
665
|
+
// The record field the entity's identity is read from, as a Python string.
|
|
666
|
+
function rid(entity: any): string {
|
|
667
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
672
|
+
// in another field reads the key from there too.
|
|
673
|
+
function fixtureIdentity(entity: any): string {
|
|
674
|
+
const field = entityRecordIdField(entity)
|
|
675
|
+
return 'id' === field ? '' : `
|
|
676
|
+
for rec in ((entity_data.get("existing") or {}).get(${JSON.stringify(entity.name)}) or {}).values():
|
|
677
|
+
if isinstance(rec, dict) and rec.get("id") is not None:
|
|
678
|
+
rec[${JSON.stringify(field)}] = rec["id"]
|
|
679
|
+
`
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
|
|
651
683
|
// A child's route names its parents, and an entity no earlier step has
|
|
652
684
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
653
685
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
654
686
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
655
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
656
|
-
const fills = liveStepExamples(entity, step)
|
|
687
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
688
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
657
689
|
return 0 === fills.length ? '' : ` if setup["live"]:
|
|
658
690
|
${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${pyLit(ex)}\n`).join('')}`
|
|
659
691
|
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
liveStrict,
|
|
20
21
|
liveStrictNote,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
liveQueryExamples,
|
|
25
26
|
liveEntity,
|
|
26
27
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
28
|
+
liveDirectDiscovery,
|
|
27
29
|
} from '@voxgig/sdkgen'
|
|
28
30
|
|
|
29
31
|
import { formatRubyValue } from './utility_rb'
|
|
@@ -133,7 +135,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
133
135
|
const listOp = entity.op?.list
|
|
134
136
|
|
|
135
137
|
const loadPoint = loadOp?.points?.[0]
|
|
136
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
138
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
137
139
|
const allLoadParams = loadPoint?.g?.params || []
|
|
138
140
|
// Some upstream OpenAPI specs declare a parameter as `in: path` even when
|
|
139
141
|
// that path has no `{name}` placeholder for it. Only path params that
|
|
@@ -153,7 +155,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
153
155
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
154
156
|
|
|
155
157
|
const listPoint = listOp?.points?.[0]
|
|
156
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
158
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
157
159
|
const listParams = listPoint?.g?.params || []
|
|
158
160
|
|
|
159
161
|
// Required query params with spec-provided examples — needed in live mode.
|
|
@@ -261,8 +263,10 @@ ${listLiveQueryLines ? ' if setup[:live]\n' + listLiveQueryLines + ' end\n
|
|
|
261
263
|
`)
|
|
262
264
|
}
|
|
263
265
|
else if (hasLoad && loadPoint) {
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
267
|
+
const discover = null != discovery
|
|
268
|
+
const idParam = discovery?.param
|
|
269
|
+
const idField = discovery?.field
|
|
266
270
|
const loadLiveIdKeys: string[] = loadAllHaveExamples ? [] :
|
|
267
271
|
discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
|
|
268
272
|
loadParams.map(liveKey)
|
|
@@ -299,7 +303,7 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
|
|
|
299
303
|
Runner.live_empty("The account has no ${entity.name} record to load")
|
|
300
304
|
end
|
|
301
305
|
first = records[0].is_a?(Hash) ? records[0] : {}
|
|
302
|
-
found = first
|
|
306
|
+
found = first["${idField}"]
|
|
303
307
|
if found.nil?
|
|
304
308
|
Runner.live_miss(LIVE_STRICT, "Live load blocked: discovery returned no usable identity")
|
|
305
309
|
end
|