@distilled.cloud/core 1.0.0-rc.14 → 1.0.0-rc.16
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/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +341 -0
- package/lib/schema-lite-impl.js.map +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +27 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/lib/codegen/openapi.js
CHANGED
|
@@ -1,81 +1,82 @@
|
|
|
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
|
-
|
|
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
|
+
import { ADDITIONAL_PROPERTIES_TRAIT } from "./members.js";
|
|
46
47
|
import { isMechanicalOperationId, isVerbatimRouteId, pathToVerbNoun, RENAME_METADATA_KEY, renameShapes, resolveOperationName, toVerbNoun, } from "./rewrite-operation-ids.js";
|
|
47
48
|
// ============================================================================
|
|
48
49
|
// Trait ids (the `com.distilled.openapi` vocabulary)
|
|
49
50
|
// ============================================================================
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
export const NULLABLE_TRAIT = "com.distilled.openapi#nullable";
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
58
59
|
export const RAW_RESPONSE_TRAIT = "com.distilled.openapi#rawResponse";
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
64
65
|
export const ERROR_MATCHERS_TRAIT = "com.distilled.openapi#errorMatchers";
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
72
73
|
export const CONTENT_TYPE_TRAIT = "com.distilled.openapi#contentType";
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
79
80
|
export const API_VERSION_TRAIT = "com.distilled.openapi#apiVersion";
|
|
80
81
|
// ============================================================================
|
|
81
82
|
// Sensitive-field name patterns (distilled v0's SENSITIVE_FIELD_PATTERNS)
|
|
@@ -113,7 +114,7 @@ const PRELUDE = {
|
|
|
113
114
|
Integer: "smithy.api#Integer",
|
|
114
115
|
Document: "smithy.api#Document",
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
+
|
|
117
118
|
const pascal = (s) => {
|
|
118
119
|
const parts = s.split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
119
120
|
let out = parts.map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
@@ -123,18 +124,18 @@ const pascal = (s) => {
|
|
|
123
124
|
out = `_${out}`;
|
|
124
125
|
return out;
|
|
125
126
|
};
|
|
126
|
-
|
|
127
|
+
|
|
127
128
|
const memberIdent = (name) => {
|
|
128
129
|
let out = name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
129
130
|
if (/^[0-9]/.test(out))
|
|
130
131
|
out = `_${out}`;
|
|
131
132
|
return out || "_";
|
|
132
133
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
138
139
|
const headerMemberName = (name) => {
|
|
139
140
|
const parts = name.split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
140
141
|
if (parts.length === 0)
|
|
@@ -183,7 +184,7 @@ const detectVersion = (spec) => {
|
|
|
183
184
|
return "3.0";
|
|
184
185
|
throw new Error(`Unsupported OpenAPI version (swagger=${spec?.swagger}, openapi=${spec?.openapi})`);
|
|
185
186
|
};
|
|
186
|
-
|
|
187
|
+
|
|
187
188
|
const resolvePointer = (spec, ref) => {
|
|
188
189
|
if (typeof ref !== "string" || !ref.startsWith("#/"))
|
|
189
190
|
return undefined;
|
|
@@ -196,7 +197,7 @@ const resolvePointer = (spec, ref) => {
|
|
|
196
197
|
}
|
|
197
198
|
return cur;
|
|
198
199
|
};
|
|
199
|
-
|
|
200
|
+
|
|
200
201
|
const deref = (ctx, def) => {
|
|
201
202
|
let cur = def;
|
|
202
203
|
for (let i = 0; i < 16 && cur && typeof cur === "object" && cur.$ref; i++) {
|
|
@@ -204,14 +205,14 @@ const deref = (ctx, def) => {
|
|
|
204
205
|
}
|
|
205
206
|
return cur;
|
|
206
207
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
215
216
|
const flattenObject = (ctx, def, depth = 0) => {
|
|
216
217
|
const out = {
|
|
217
218
|
properties: {},
|
|
@@ -270,7 +271,7 @@ const flattenObject = (ctx, def, depth = 0) => {
|
|
|
270
271
|
visit(def, depth, false, false);
|
|
271
272
|
return out;
|
|
272
273
|
};
|
|
273
|
-
|
|
274
|
+
|
|
274
275
|
const isNullBranch = (ctx, branch) => {
|
|
275
276
|
const r = deref(ctx, branch);
|
|
276
277
|
if (!r || typeof r !== "object")
|
|
@@ -285,7 +286,7 @@ const isNullBranch = (ctx, branch) => {
|
|
|
285
286
|
}
|
|
286
287
|
return false;
|
|
287
288
|
};
|
|
288
|
-
|
|
289
|
+
|
|
289
290
|
const ownNullable = (ctx, def) => {
|
|
290
291
|
if (!def || typeof def !== "object")
|
|
291
292
|
return false;
|
|
@@ -300,12 +301,12 @@ const ownNullable = (ctx, def) => {
|
|
|
300
301
|
return true;
|
|
301
302
|
return false;
|
|
302
303
|
};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
309
310
|
const dirExcluded = (ctx, prop, dir) => {
|
|
310
311
|
const flag = dir === "in" ? "readOnly" : "writeOnly";
|
|
311
312
|
if (prop && typeof prop === "object" && prop[flag] === true)
|
|
@@ -313,7 +314,7 @@ const dirExcluded = (ctx, prop, dir) => {
|
|
|
313
314
|
const r = deref(ctx, prop);
|
|
314
315
|
return !!r && typeof r === "object" && r[flag] === true;
|
|
315
316
|
};
|
|
316
|
-
|
|
317
|
+
|
|
317
318
|
const schemaChildren = (d) => [
|
|
318
319
|
...(Array.isArray(d.allOf) ? d.allOf : []),
|
|
319
320
|
...(Array.isArray(d.oneOf) ? d.oneOf : []),
|
|
@@ -324,11 +325,11 @@ const schemaChildren = (d) => [
|
|
|
324
325
|
? [d.additionalProperties]
|
|
325
326
|
: []),
|
|
326
327
|
];
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
332
333
|
const scanInlineForFlag = (d, flag, refs) => {
|
|
333
334
|
if (!d || typeof d !== "object")
|
|
334
335
|
return false;
|
|
@@ -344,17 +345,17 @@ const scanInlineForFlag = (d, flag, refs) => {
|
|
|
344
345
|
}
|
|
345
346
|
return false;
|
|
346
347
|
};
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
358
359
|
const buildDirSensitiveRefs = (ctx, dir) => {
|
|
359
360
|
const flag = dir === "in" ? "readOnly" : "writeOnly";
|
|
360
361
|
// Every distinct `$ref` pointer in the document.
|
|
@@ -403,13 +404,13 @@ const buildDirSensitiveRefs = (ctx, dir) => {
|
|
|
403
404
|
}
|
|
404
405
|
return sensitive;
|
|
405
406
|
};
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
413
414
|
const dirSensitive = (ctx, def, dir) => {
|
|
414
415
|
let sensitiveRefs = ctx.dirSensitiveRefs.get(dir);
|
|
415
416
|
if (sensitiveRefs === undefined) {
|
|
@@ -422,7 +423,7 @@ const dirSensitive = (ctx, def, dir) => {
|
|
|
422
423
|
}
|
|
423
424
|
return refs.some((ref) => sensitiveRefs.has(ref));
|
|
424
425
|
};
|
|
425
|
-
|
|
426
|
+
|
|
426
427
|
const typeOf = (def) => {
|
|
427
428
|
const t = def?.type;
|
|
428
429
|
if (typeof t === "string")
|
|
@@ -437,11 +438,11 @@ const typeOf = (def) => {
|
|
|
437
438
|
// ============================================================================
|
|
438
439
|
// Schema conversion
|
|
439
440
|
// ============================================================================
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
445
446
|
const isNameable = (ctx, def) => {
|
|
446
447
|
if (!def || typeof def !== "object")
|
|
447
448
|
return false;
|
|
@@ -466,13 +467,13 @@ const isNameable = (ctx, def) => {
|
|
|
466
467
|
return true;
|
|
467
468
|
return false;
|
|
468
469
|
};
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
476
477
|
const convertSchema = (ctx, def, hint, depth, dir, reservedId) => {
|
|
477
478
|
const emit = (shapeDef, base) => {
|
|
478
479
|
if (reservedId !== undefined) {
|
|
@@ -599,7 +600,7 @@ const convertSchema = (ctx, def, hint, depth, dir, reservedId) => {
|
|
|
599
600
|
}
|
|
600
601
|
const members = buildMembers(ctx, flat.properties, flat.required, hint, depth + 1, dir);
|
|
601
602
|
return {
|
|
602
|
-
target: emit({ type: "structure", members, traits: docTraits }, hint),
|
|
603
|
+
target: emit({ type: "structure", members, traits: structTraits(docTraits, flat.additionalProperties) }, hint),
|
|
603
604
|
nullable,
|
|
604
605
|
};
|
|
605
606
|
}
|
|
@@ -677,7 +678,11 @@ const convertSchema = (ctx, def, hint, depth, dir, reservedId) => {
|
|
|
677
678
|
const required = new Set(Array.isArray(def.required) ? def.required : []);
|
|
678
679
|
const members = buildMembers(ctx, def.properties, required, hint, depth + 1, dir);
|
|
679
680
|
return {
|
|
680
|
-
target: emit({
|
|
681
|
+
target: emit({
|
|
682
|
+
type: "structure",
|
|
683
|
+
members,
|
|
684
|
+
traits: structTraits(docTraits, def.additionalProperties),
|
|
685
|
+
}, hint),
|
|
681
686
|
nullable,
|
|
682
687
|
};
|
|
683
688
|
}
|
|
@@ -717,7 +722,16 @@ const convertSchema = (ctx, def, hint, depth, dir, reservedId) => {
|
|
|
717
722
|
return inline(PRELUDE.Document, nullable);
|
|
718
723
|
}
|
|
719
724
|
};
|
|
720
|
-
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
const structTraits = (docTraits, ap) => ap !== undefined && ap !== false
|
|
732
|
+
? { ...docTraits, [ADDITIONAL_PROPERTIES_TRAIT]: {} }
|
|
733
|
+
: docTraits;
|
|
734
|
+
|
|
721
735
|
const isSensitiveProperty = (ctx, name, def) => {
|
|
722
736
|
const r = deref(ctx, def);
|
|
723
737
|
if (!r || typeof r !== "object")
|
|
@@ -729,11 +743,11 @@ const isSensitiveProperty = (ctx, name, def) => {
|
|
|
729
743
|
return true;
|
|
730
744
|
return ctx.sensitivePatterns.some((p) => p.test(name));
|
|
731
745
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
737
751
|
const buildMembers = (ctx, properties, required, hint, depth, dir) => {
|
|
738
752
|
const members = {};
|
|
739
753
|
for (const [name, prop] of Object.entries(properties)) {
|
|
@@ -766,7 +780,7 @@ const buildMembers = (ctx, properties, required, hint, depth, dir) => {
|
|
|
766
780
|
}
|
|
767
781
|
return members;
|
|
768
782
|
};
|
|
769
|
-
|
|
783
|
+
|
|
770
784
|
const normalizeParam = (ctx, raw) => {
|
|
771
785
|
const p = raw?.$ref ? resolvePointer(ctx.spec, raw.$ref) : raw;
|
|
772
786
|
if (!p || typeof p !== "object" || typeof p.name !== "string") {
|
|
@@ -794,12 +808,12 @@ const normalizeParam = (ctx, raw) => {
|
|
|
794
808
|
schema,
|
|
795
809
|
};
|
|
796
810
|
};
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
803
817
|
const collectParams = (ctx, pathItem, op) => {
|
|
804
818
|
const byKey = new Map();
|
|
805
819
|
for (const raw of [
|
|
@@ -813,11 +827,11 @@ const collectParams = (ctx, pathItem, op) => {
|
|
|
813
827
|
}
|
|
814
828
|
return [...byKey.values()].filter((p) => p.in === "path" || p.in === "query" || p.in === "body" || p.in === "header");
|
|
815
829
|
};
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
821
835
|
const labelTarget = (ctx, schema, hint) => {
|
|
822
836
|
const r = deref(ctx, schema);
|
|
823
837
|
if (Array.isArray(r?.enum) &&
|
|
@@ -839,10 +853,10 @@ const labelTarget = (ctx, schema, hint) => {
|
|
|
839
853
|
// ============================================================================
|
|
840
854
|
// Docs
|
|
841
855
|
// ============================================================================
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
846
860
|
const trimDescription = (desc) => {
|
|
847
861
|
if (typeof desc !== "string" || !desc)
|
|
848
862
|
return undefined;
|
|
@@ -866,7 +880,60 @@ const opDoc = (op) => {
|
|
|
866
880
|
// ============================================================================
|
|
867
881
|
// Responses
|
|
868
882
|
// ============================================================================
|
|
869
|
-
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
const successHeaders = (ctx, responses, allowed) => {
|
|
889
|
+
const out = [];
|
|
890
|
+
const seen = new Set();
|
|
891
|
+
for (const code of Object.keys(responses ?? {}).sort()) {
|
|
892
|
+
if (!/^2\d\d$/.test(code))
|
|
893
|
+
continue;
|
|
894
|
+
const raw = responses[code];
|
|
895
|
+
const resp = raw?.$ref ? resolvePointer(ctx.spec, raw.$ref) : raw;
|
|
896
|
+
for (const [name, rawHeader] of Object.entries(resp?.headers ?? {})) {
|
|
897
|
+
const lower = name.toLowerCase();
|
|
898
|
+
if (!allowed.has(lower) || seen.has(lower))
|
|
899
|
+
continue;
|
|
900
|
+
seen.add(lower);
|
|
901
|
+
const header = rawHeader?.$ref ? resolvePointer(ctx.spec, rawHeader.$ref) : rawHeader;
|
|
902
|
+
if (!header || typeof header !== "object")
|
|
903
|
+
continue;
|
|
904
|
+
out.push({
|
|
905
|
+
name,
|
|
906
|
+
schema: ctx.version === "2.0" ? header : (header.schema ?? {}),
|
|
907
|
+
...(typeof header.description === "string" ? { description: header.description } : {}),
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return out;
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
const targetCounts = (shapes) => {
|
|
915
|
+
const counts = new Map();
|
|
916
|
+
const visit = (node) => {
|
|
917
|
+
if (node === null || typeof node !== "object")
|
|
918
|
+
return;
|
|
919
|
+
if (Array.isArray(node)) {
|
|
920
|
+
for (const item of node)
|
|
921
|
+
visit(item);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (typeof node.target === "string") {
|
|
925
|
+
counts.set(node.target, (counts.get(node.target) ?? 0) + 1);
|
|
926
|
+
}
|
|
927
|
+
for (const [key, value] of Object.entries(node)) {
|
|
928
|
+
if (key !== "traits")
|
|
929
|
+
visit(value);
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
for (const shape of Object.values(shapes))
|
|
933
|
+
visit(shape);
|
|
934
|
+
return counts;
|
|
935
|
+
};
|
|
936
|
+
|
|
870
937
|
const successSchema = (ctx, responses, order) => {
|
|
871
938
|
for (const code of order) {
|
|
872
939
|
const raw = responses?.[code];
|
|
@@ -886,11 +953,11 @@ const successSchema = (ctx, responses, order) => {
|
|
|
886
953
|
}
|
|
887
954
|
return { schema: undefined };
|
|
888
955
|
};
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
894
961
|
const responseIsCollection = (ctx, responses, order) => {
|
|
895
962
|
const { schema } = successSchema(ctx, responses, order);
|
|
896
963
|
if (!schema)
|
|
@@ -983,12 +1050,12 @@ const detectPagination = (ctx, params, responseSchema) => {
|
|
|
983
1050
|
// Main conversion
|
|
984
1051
|
// ============================================================================
|
|
985
1052
|
const HTTP_METHODS = ["get", "post", "put", "patch", "delete"];
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
992
1059
|
const OPTIONAL_HTTP_METHODS = ["head", "options"];
|
|
993
1060
|
const DEFAULT_STATUS_TO_ERROR_CLASS = {
|
|
994
1061
|
"400": "BadRequest",
|
|
@@ -1063,6 +1130,8 @@ const convertOnce = (spec, options) => {
|
|
|
1063
1130
|
const serviceName = uniqueName(ctx, options.serviceName);
|
|
1064
1131
|
const usedErrors = new Map(); // class name → first status
|
|
1065
1132
|
const serviceOps = [];
|
|
1133
|
+
const componentHeaders = [];
|
|
1134
|
+
const allowedResponseHeaders = new Set((options.responseHeaders ?? []).map((name) => name.toLowerCase()));
|
|
1066
1135
|
for (const [rawPath, pathItem] of Object.entries(doc.paths ?? {})) {
|
|
1067
1136
|
if (!pathItem || typeof pathItem !== "object")
|
|
1068
1137
|
continue;
|
|
@@ -1189,7 +1258,9 @@ const convertOnce = (spec, options) => {
|
|
|
1189
1258
|
bodyRequired = bodyParam?.required === true;
|
|
1190
1259
|
}
|
|
1191
1260
|
else if (op.requestBody) {
|
|
1192
|
-
|
|
1261
|
+
// A components/requestBodies entry can itself be a $ref to another
|
|
1262
|
+
// (1Password Events: AuditEventsRequest → CursorRequest).
|
|
1263
|
+
const rb = deref(ctx, op.requestBody);
|
|
1193
1264
|
bodyRequired = rb?.required === true;
|
|
1194
1265
|
const content = rb?.content ?? {};
|
|
1195
1266
|
if (content["application/json"]) {
|
|
@@ -1297,6 +1368,51 @@ const convertOnce = (spec, options) => {
|
|
|
1297
1368
|
}
|
|
1298
1369
|
}
|
|
1299
1370
|
}
|
|
1371
|
+
// ---- Response headers (opt-in) ----
|
|
1372
|
+
let pendingHeaders;
|
|
1373
|
+
if (allowedResponseHeaders.size > 0 && method !== "head") {
|
|
1374
|
+
const headers = successHeaders(ctx, op.responses, allowedResponseHeaders);
|
|
1375
|
+
const current = outputTarget === PRELUDE.Unit ? undefined : ctx.shapes[outputTarget];
|
|
1376
|
+
// A raw-root wrapper collapses to its payload, so it has nowhere to
|
|
1377
|
+
// carry headers.
|
|
1378
|
+
const rawRoot = Object.values(current?.members ?? {}).some((m) => m?.traits?.[RAW_RESPONSE_TRAIT] !== undefined);
|
|
1379
|
+
if (headers.length > 0 &&
|
|
1380
|
+
(current === undefined || current.type === "structure") &&
|
|
1381
|
+
!rawRoot) {
|
|
1382
|
+
const taken = new Set(Object.keys(current?.members ?? {}));
|
|
1383
|
+
const members = {};
|
|
1384
|
+
for (const header of headers) {
|
|
1385
|
+
let name = headerMemberName(header.name);
|
|
1386
|
+
if (taken.has(name))
|
|
1387
|
+
name = `${name}Header`;
|
|
1388
|
+
if (taken.has(name))
|
|
1389
|
+
continue;
|
|
1390
|
+
taken.add(name);
|
|
1391
|
+
members[name] = {
|
|
1392
|
+
target: convertSchema(ctx, header.schema, `${opName}Response${pascal(header.name)}`, 0, "out").target,
|
|
1393
|
+
traits: {
|
|
1394
|
+
"smithy.api#httpHeader": header.name,
|
|
1395
|
+
...(header.description ? { "smithy.api#documentation": header.description } : {}),
|
|
1396
|
+
},
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
if (current === undefined) {
|
|
1400
|
+
outputTarget = addShape(ctx, `${opName}Response`, {
|
|
1401
|
+
type: "structure",
|
|
1402
|
+
members,
|
|
1403
|
+
traits: { "smithy.api#output": {} },
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
else if (current.traits?.["smithy.api#output"] !== undefined) {
|
|
1407
|
+
current.members = { ...current.members, ...members };
|
|
1408
|
+
}
|
|
1409
|
+
else {
|
|
1410
|
+
// A named component: whether it can take the headers itself
|
|
1411
|
+
// depends on what else uses it, known once every op is converted.
|
|
1412
|
+
pendingHeaders = members;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1300
1416
|
// ---- Errors ----
|
|
1301
1417
|
const errors = [];
|
|
1302
1418
|
for (const status of Object.keys(op.responses ?? {})) {
|
|
@@ -1342,6 +1458,44 @@ const convertOnce = (spec, options) => {
|
|
|
1342
1458
|
traits,
|
|
1343
1459
|
});
|
|
1344
1460
|
serviceOps.push({ target: opId });
|
|
1461
|
+
if (pendingHeaders !== undefined) {
|
|
1462
|
+
componentHeaders.push({ opId, opName, members: pendingHeaders });
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
// ---- Response headers on named components ----
|
|
1467
|
+
// A component returned only by ops that declare headers takes them itself
|
|
1468
|
+
// (all optional) and keeps its name. A component that other shapes, or ops
|
|
1469
|
+
// without those headers, also use is copied into an op-specific output, so
|
|
1470
|
+
// the headers never leak into them.
|
|
1471
|
+
if (componentHeaders.length > 0) {
|
|
1472
|
+
const uses = targetCounts(ctx.shapes);
|
|
1473
|
+
const outputs = new Map();
|
|
1474
|
+
for (const { opId } of componentHeaders) {
|
|
1475
|
+
const id = ctx.shapes[opId].output.target;
|
|
1476
|
+
outputs.set(id, (outputs.get(id) ?? 0) + 1);
|
|
1477
|
+
}
|
|
1478
|
+
for (const { opId, opName, members } of componentHeaders) {
|
|
1479
|
+
const opShape = ctx.shapes[opId];
|
|
1480
|
+
const componentId = opShape.output.target;
|
|
1481
|
+
const component = ctx.shapes[componentId];
|
|
1482
|
+
if (uses.get(componentId) === outputs.get(componentId)) {
|
|
1483
|
+
component.members = { ...component.members, ...members };
|
|
1484
|
+
}
|
|
1485
|
+
else {
|
|
1486
|
+
opShape.output.target = addShape(ctx, `${opName}Response`, {
|
|
1487
|
+
type: "structure",
|
|
1488
|
+
members: { ...component.members, ...members },
|
|
1489
|
+
traits: {
|
|
1490
|
+
...(component.traits?.["smithy.api#documentation"]
|
|
1491
|
+
? {
|
|
1492
|
+
"smithy.api#documentation": component.traits["smithy.api#documentation"],
|
|
1493
|
+
}
|
|
1494
|
+
: {}),
|
|
1495
|
+
"smithy.api#output": {},
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1345
1499
|
}
|
|
1346
1500
|
}
|
|
1347
1501
|
// ---- Error shapes (one per used class) ----
|