@distilled.cloud/core 1.0.0-rc.12 → 1.0.0-rc.14
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 +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts +8 -8
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +83 -30
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +130 -2
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +24 -5
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +69 -80
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.d.ts +2 -0
- package/lib/codegen/generator.test.d.ts.map +1 -0
- package/lib/codegen/generator.test.js +121 -0
- package/lib/codegen/generator.test.js.map +1 -0
- package/lib/codegen/graphql-client.d.ts +7 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +264 -148
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +98 -238
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.d.ts +2 -0
- package/lib/codegen/openapi-binary.test.d.ts.map +1 -0
- package/lib/codegen/openapi-binary.test.js +67 -0
- package/lib/codegen/openapi-binary.test.js.map +1 -0
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +16 -2
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +56 -39
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +75 -11
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +301 -65
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +55 -5
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.d.ts +2 -0
- package/lib/codegen/untagged-unions.test.d.ts.map +1 -0
- package/lib/codegen/untagged-unions.test.js +80 -0
- package/lib/codegen/untagged-unions.test.js.map +1 -0
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +2 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +9 -4
- package/lib/errors.js.map +1 -1
- package/lib/fixtures/xml/upstream-validator.json +397 -0
- package/lib/graphql.d.ts +292 -205
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +945 -636
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +135 -764
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts +10 -0
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js +4 -44
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +27 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -0
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts +2 -1
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +28 -30
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.d.ts +2 -0
- package/lib/pagination.test.d.ts.map +1 -0
- package/lib/pagination.test.js +131 -0
- package/lib/pagination.test.js.map +1 -0
- package/lib/protocol-http.d.ts +30 -16
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +133 -84
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +141 -1
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts +18 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +32 -21
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +27 -0
- package/lib/query.js.map +1 -0
- package/lib/response-validation.d.ts +67 -0
- package/lib/response-validation.d.ts.map +1 -0
- package/lib/response-validation.js +76 -0
- package/lib/response-validation.js.map +1 -0
- package/lib/response-validation.test.d.ts +2 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +72 -0
- package/lib/response-validation.test.js.map +1 -0
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +39 -0
- package/lib/testing.d.ts.map +1 -0
- package/lib/testing.js +41 -0
- package/lib/testing.js.map +1 -0
- package/lib/trait.d.ts +29 -9
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +8 -0
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +44 -0
- package/lib/xml.d.ts.map +1 -0
- package/lib/xml.js +311 -0
- package/lib/xml.js.map +1 -0
- package/lib/xml.test.d.ts +2 -0
- package/lib/xml.test.d.ts.map +1 -0
- package/lib/xml.test.js +210 -0
- package/lib/xml.test.js.map +1 -0
- package/package.json +8 -11
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +148 -17
- package/src/codegen/boolean-string-enums.ts +81 -32
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +137 -0
- package/src/codegen/generator.ts +132 -193
- package/src/codegen/graphql-client.test.ts +100 -297
- package/src/codegen/graphql-client.ts +302 -210
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +91 -0
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +98 -133
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +73 -15
- package/src/codegen/patches.ts +389 -99
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +85 -0
- package/src/error-category.ts +5 -17
- package/src/errors.ts +18 -30
- package/src/fixtures/xml/upstream-validator.json +397 -0
- package/src/graphql.test.ts +173 -949
- package/src/graphql.ts +1468 -1186
- package/src/graphql.types.ts +78 -164
- package/src/index.ts +26 -0
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +169 -0
- package/src/pagination.ts +46 -103
- package/src/protocol-http.test.ts +178 -9
- package/src/protocol-http.ts +174 -163
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +76 -65
- package/src/query.ts +39 -0
- package/src/response-validation.test.ts +89 -0
- package/src/response-validation.ts +107 -0
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +72 -0
- package/src/trait.ts +48 -63
- package/src/xml.test.ts +251 -0
- package/src/xml.ts +323 -0
- package/lib/graphql.fixture.d.ts +0 -249
- package/lib/graphql.fixture.d.ts.map +0 -1
- package/lib/graphql.fixture.js +0 -240
- package/lib/graphql.fixture.js.map +0 -1
- package/src/graphql.fixture.ts +0 -371
package/src/codegen/graphql.ts
CHANGED
|
@@ -104,8 +104,7 @@ export const readIntrospection = (json: unknown): IntrospectionSchema => {
|
|
|
104
104
|
__schema?: IntrospectionSchema;
|
|
105
105
|
types?: unknown;
|
|
106
106
|
};
|
|
107
|
-
const schema =
|
|
108
|
-
j?.data?.__schema ?? j?.__schema ?? (j?.types ? (j as any) : undefined);
|
|
107
|
+
const schema = j?.data?.__schema ?? j?.__schema ?? (j?.types ? (j as any) : undefined);
|
|
109
108
|
if (!schema) {
|
|
110
109
|
throw new Error(
|
|
111
110
|
"introspection JSON has none of `data.__schema`, `__schema`, or a top-level `types`",
|
|
@@ -249,8 +248,7 @@ export interface GraphQLConvertResult {
|
|
|
249
248
|
// Small helpers
|
|
250
249
|
// ============================================================================
|
|
251
250
|
|
|
252
|
-
const capitalize = (s: string): string =>
|
|
253
|
-
s.charAt(0).toUpperCase() + s.slice(1);
|
|
251
|
+
const capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
|
254
252
|
|
|
255
253
|
const toPascalCase = (s: string): string =>
|
|
256
254
|
capitalize(s.replace(/[^a-zA-Z0-9]+(.)/g, (_, c: string) => c.toUpperCase()));
|
|
@@ -325,10 +323,7 @@ interface RelayCtx {
|
|
|
325
323
|
readonly isPageInfo: (name: string | null | undefined) => boolean;
|
|
326
324
|
}
|
|
327
325
|
|
|
328
|
-
const makeRelayCtx = (
|
|
329
|
-
cfg: Relay,
|
|
330
|
-
typeMap: Map<string, IntrospectionType>,
|
|
331
|
-
): RelayCtx => {
|
|
326
|
+
const makeRelayCtx = (cfg: Relay, typeMap: Map<string, IntrospectionType>): RelayCtx => {
|
|
332
327
|
const connections = new Map<string, boolean>();
|
|
333
328
|
const edges = new Set<string>();
|
|
334
329
|
const pageInfos = new Set<string>();
|
|
@@ -354,9 +349,7 @@ const makeRelayCtx = (
|
|
|
354
349
|
|
|
355
350
|
const pageInfoName = namedType(pageInfoField.type).name;
|
|
356
351
|
const pageInfoType = pageInfoName ? typeMap.get(pageInfoName) : undefined;
|
|
357
|
-
const hasCursor = (pageInfoType?.fields ?? []).some(
|
|
358
|
-
(f) => f.name === cfg.endCursor,
|
|
359
|
-
);
|
|
352
|
+
const hasCursor = (pageInfoType?.fields ?? []).some((f) => f.name === cfg.endCursor);
|
|
360
353
|
if (!hasCursor) return false;
|
|
361
354
|
|
|
362
355
|
connections.set(name, true);
|
|
@@ -548,8 +541,7 @@ const collectOperationPaths = (
|
|
|
548
541
|
}
|
|
549
542
|
|
|
550
543
|
const isObject =
|
|
551
|
-
(actualReturn.kind === "OBJECT" || actualReturn.kind === "INTERFACE") &&
|
|
552
|
-
!!actualReturn.name;
|
|
544
|
+
(actualReturn.kind === "OBJECT" || actualReturn.kind === "INTERFACE") && !!actualReturn.name;
|
|
553
545
|
|
|
554
546
|
if (!isObject || chain.length >= maxNamespaceDepth) {
|
|
555
547
|
return [chain];
|
|
@@ -563,15 +555,7 @@ const collectOperationPaths = (
|
|
|
563
555
|
const paths: OperationStep[][] = [];
|
|
564
556
|
for (const subfield of namespaceType.fields) {
|
|
565
557
|
if (skipDeprecated && subfield.isDeprecated) continue;
|
|
566
|
-
paths.push(
|
|
567
|
-
...collectOperationPaths(
|
|
568
|
-
subfield,
|
|
569
|
-
chain,
|
|
570
|
-
ctx,
|
|
571
|
-
maxNamespaceDepth,
|
|
572
|
-
skipDeprecated,
|
|
573
|
-
),
|
|
574
|
-
);
|
|
558
|
+
paths.push(...collectOperationPaths(subfield, chain, ctx, maxNamespaceDepth, skipDeprecated));
|
|
575
559
|
}
|
|
576
560
|
|
|
577
561
|
return paths.length > 0 ? paths : [chain];
|
|
@@ -641,11 +625,7 @@ const buildPathDocument = (
|
|
|
641
625
|
? `${type} ${operationName}(${varDefs.join(", ")})`
|
|
642
626
|
: `${type} ${operationName}`;
|
|
643
627
|
|
|
644
|
-
const renderStep = (
|
|
645
|
-
step: OperationStep,
|
|
646
|
-
inner: string,
|
|
647
|
-
indent: string,
|
|
648
|
-
): string => {
|
|
628
|
+
const renderStep = (step: OperationStep, inner: string, indent: string): string => {
|
|
649
629
|
const argList = step.args
|
|
650
630
|
.map((arg) => {
|
|
651
631
|
const varName = argRenames.get(`${step.name}.${arg.name}`) ?? arg.name;
|
|
@@ -753,9 +733,7 @@ const makeConverter = (
|
|
|
753
733
|
return id;
|
|
754
734
|
};
|
|
755
735
|
|
|
756
|
-
const inputTypeTarget = (
|
|
757
|
-
ref: TypeRef,
|
|
758
|
-
): { target: string; nullable: boolean } => {
|
|
736
|
+
const inputTypeTarget = (ref: TypeRef): { target: string; nullable: boolean } => {
|
|
759
737
|
const { type, nonNull } = unwrapNonNull(ref);
|
|
760
738
|
const nullable = !nonNull;
|
|
761
739
|
if (type.kind === "LIST" && type.ofType) {
|
|
@@ -850,11 +828,7 @@ const buildOutputTarget = (
|
|
|
850
828
|
if (type.kind === "ENUM" && type.name) {
|
|
851
829
|
return { target: conv.enumShape(type.name), nullable };
|
|
852
830
|
}
|
|
853
|
-
if (
|
|
854
|
-
(type.kind === "OBJECT" || type.kind === "INTERFACE") &&
|
|
855
|
-
children &&
|
|
856
|
-
children.length > 0
|
|
857
|
-
) {
|
|
831
|
+
if ((type.kind === "OBJECT" || type.kind === "INTERFACE") && children && children.length > 0) {
|
|
858
832
|
const members = buildSelectionMembers(conv, children, hint);
|
|
859
833
|
const target = addShape(conv.bag, hint, { type: "structure", members });
|
|
860
834
|
return { target, nullable };
|
|
@@ -875,12 +849,7 @@ const buildSelectionMembers = (
|
|
|
875
849
|
): Record<string, any> => {
|
|
876
850
|
const members: Record<string, any> = {};
|
|
877
851
|
for (const f of fields) {
|
|
878
|
-
const sub = buildOutputTarget(
|
|
879
|
-
conv,
|
|
880
|
-
f.type,
|
|
881
|
-
f.children,
|
|
882
|
-
`${hint}${toPascalCase(f.name)}`,
|
|
883
|
-
);
|
|
852
|
+
const sub = buildOutputTarget(conv, f.type, f.children, `${hint}${toPascalCase(f.name)}`);
|
|
884
853
|
const memberTraits: Record<string, any> = { "smithy.api#required": {} };
|
|
885
854
|
if (sub.nullable) memberTraits[conv.traits.nullable] = {};
|
|
886
855
|
members[memberIdent(f.name)] = { target: sub.target, traits: memberTraits };
|
|
@@ -907,9 +876,7 @@ interface PendingOp {
|
|
|
907
876
|
* `POST /graphql` request/response pair, and nothing in the generated SDK
|
|
908
877
|
* could speak them.
|
|
909
878
|
*/
|
|
910
|
-
export const convertGraphQLToSmithy = (
|
|
911
|
-
options: GraphQLConvertOptions,
|
|
912
|
-
): GraphQLConvertResult => {
|
|
879
|
+
export const convertGraphQLToSmithy = (options: GraphQLConvertOptions): GraphQLConvertResult => {
|
|
913
880
|
const {
|
|
914
881
|
schema,
|
|
915
882
|
namespace,
|
|
@@ -931,9 +898,7 @@ export const convertGraphQLToSmithy = (
|
|
|
931
898
|
const typeMap = new Map<string, IntrospectionType>();
|
|
932
899
|
for (const t of schema.types) typeMap.set(t.name, t);
|
|
933
900
|
|
|
934
|
-
const relayCfg: Relay | undefined = relay
|
|
935
|
-
? { ...RELAY_DEFAULTS, ...relay }
|
|
936
|
-
: undefined;
|
|
901
|
+
const relayCfg: Relay | undefined = relay ? { ...RELAY_DEFAULTS, ...relay } : undefined;
|
|
937
902
|
const ctx: SchemaCtx = {
|
|
938
903
|
typeMap,
|
|
939
904
|
relay: relayCfg ? makeRelayCtx(relayCfg, typeMap) : undefined,
|
|
@@ -950,19 +915,10 @@ export const convertGraphQLToSmithy = (
|
|
|
950
915
|
for (const field of rootType.fields) {
|
|
951
916
|
if (skipDeprecated && field.isDeprecated) continue;
|
|
952
917
|
if (skipRootField(field.name)) continue;
|
|
953
|
-
const paths = collectOperationPaths(
|
|
954
|
-
field,
|
|
955
|
-
[],
|
|
956
|
-
ctx,
|
|
957
|
-
maxNamespaceDepth,
|
|
958
|
-
skipDeprecated,
|
|
959
|
-
);
|
|
918
|
+
const paths = collectOperationPaths(field, [], ctx, maxNamespaceDepth, skipDeprecated);
|
|
960
919
|
for (const opPath of paths) {
|
|
961
920
|
const functionName = pathToFunctionName(opPath);
|
|
962
|
-
const sdkName =
|
|
963
|
-
operationNaming === "verbNoun"
|
|
964
|
-
? toVerbNoun(functionName)
|
|
965
|
-
: functionName;
|
|
921
|
+
const sdkName = operationNaming === "verbNoun" ? toVerbNoun(functionName) : functionName;
|
|
966
922
|
if (seenNames.has(sdkName)) {
|
|
967
923
|
// Two schema fields (or the same field under two paths) map to
|
|
968
924
|
// one SDK name; the first wins. Silent drops hide real ops.
|
|
@@ -979,8 +935,7 @@ export const convertGraphQLToSmithy = (
|
|
|
979
935
|
opName: toPascalCase(sdkName),
|
|
980
936
|
type,
|
|
981
937
|
path: opPath,
|
|
982
|
-
description:
|
|
983
|
-
opPath.length === 1 ? oneLineDoc(field.description) : undefined,
|
|
938
|
+
description: opPath.length === 1 ? oneLineDoc(field.description) : undefined,
|
|
984
939
|
});
|
|
985
940
|
}
|
|
986
941
|
}
|
|
@@ -1011,20 +966,8 @@ export const convertGraphQLToSmithy = (
|
|
|
1011
966
|
try {
|
|
1012
967
|
const argRenames = buildArgRenames(op.path);
|
|
1013
968
|
const leaf = op.path[op.path.length - 1]!;
|
|
1014
|
-
const selection = expandSelection(
|
|
1015
|
-
|
|
1016
|
-
ctx,
|
|
1017
|
-
1,
|
|
1018
|
-
maxDepth,
|
|
1019
|
-
new Set(),
|
|
1020
|
-
);
|
|
1021
|
-
const document = buildPathDocument(
|
|
1022
|
-
op.type,
|
|
1023
|
-
op.functionName,
|
|
1024
|
-
op.path,
|
|
1025
|
-
selection,
|
|
1026
|
-
argRenames,
|
|
1027
|
-
);
|
|
969
|
+
const selection = expandSelection(leaf.returnType, ctx, 1, maxDepth, new Set());
|
|
970
|
+
const document = buildPathDocument(op.type, op.functionName, op.path, selection, argRenames);
|
|
1028
971
|
const responsePath = op.path.map((s) => s.name).join(".");
|
|
1029
972
|
|
|
1030
973
|
// ---- Input (the GraphQL variables) ----
|
|
@@ -1041,9 +984,7 @@ export const convertGraphQLToSmithy = (
|
|
|
1041
984
|
if (adoc) memberTraits["smithy.api#documentation"] = adoc;
|
|
1042
985
|
inputMembers[memberIdent(varName)] = {
|
|
1043
986
|
target,
|
|
1044
|
-
...(Object.keys(memberTraits).length
|
|
1045
|
-
? { traits: memberTraits }
|
|
1046
|
-
: {}),
|
|
987
|
+
...(Object.keys(memberTraits).length ? { traits: memberTraits } : {}),
|
|
1047
988
|
};
|
|
1048
989
|
}
|
|
1049
990
|
}
|
|
@@ -1072,11 +1013,7 @@ export const convertGraphQLToSmithy = (
|
|
|
1072
1013
|
// Object result: the response struct's members ARE the selection.
|
|
1073
1014
|
outputId = addExact(bag, `${op.opName}Response`, {
|
|
1074
1015
|
type: "structure",
|
|
1075
|
-
members: buildSelectionMembers(
|
|
1076
|
-
conv,
|
|
1077
|
-
selection!,
|
|
1078
|
-
`${op.opName}Response`,
|
|
1079
|
-
),
|
|
1016
|
+
members: buildSelectionMembers(conv, selection!, `${op.opName}Response`),
|
|
1080
1017
|
traits: {
|
|
1081
1018
|
"smithy.api#output": {},
|
|
1082
1019
|
[traits.responsePath]: responsePath,
|
|
@@ -1087,12 +1024,7 @@ export const convertGraphQLToSmithy = (
|
|
|
1087
1024
|
// List/scalar/enum/opaque result: a sole `result` member carries the
|
|
1088
1025
|
// whole value; the payload trait makes the generated response type
|
|
1089
1026
|
// the value itself.
|
|
1090
|
-
const inner = buildOutputTarget(
|
|
1091
|
-
conv,
|
|
1092
|
-
leaf.returnType,
|
|
1093
|
-
selection,
|
|
1094
|
-
`${op.opName}Result`,
|
|
1095
|
-
);
|
|
1027
|
+
const inner = buildOutputTarget(conv, leaf.returnType, selection, `${op.opName}Result`);
|
|
1096
1028
|
outputId = addExact(bag, `${op.opName}Response`, {
|
|
1097
1029
|
type: "structure",
|
|
1098
1030
|
members: {
|
|
@@ -1127,9 +1059,7 @@ export const convertGraphQLToSmithy = (
|
|
|
1127
1059
|
// list, a connection reached through a namespace hop whose leaf we
|
|
1128
1060
|
// didn't select) stays a one-shot call.
|
|
1129
1061
|
const pg =
|
|
1130
|
-
relayCfg && isBareObject
|
|
1131
|
-
? relayPaginatedTrait(relayCfg, ctx, leaf, argRenames)
|
|
1132
|
-
: undefined;
|
|
1062
|
+
relayCfg && isBareObject ? relayPaginatedTrait(relayCfg, ctx, leaf, argRenames) : undefined;
|
|
1133
1063
|
if (pg) {
|
|
1134
1064
|
opTraits["smithy.api#paginated"] = pg;
|
|
1135
1065
|
paginated++;
|
|
@@ -1155,9 +1085,7 @@ export const convertGraphQLToSmithy = (
|
|
|
1155
1085
|
operations: serviceOps,
|
|
1156
1086
|
traits: {
|
|
1157
1087
|
"smithy.api#title": serviceTitle,
|
|
1158
|
-
...(serviceDocumentation
|
|
1159
|
-
? { "smithy.api#documentation": serviceDocumentation }
|
|
1160
|
-
: {}),
|
|
1088
|
+
...(serviceDocumentation ? { "smithy.api#documentation": serviceDocumentation } : {}),
|
|
1161
1089
|
},
|
|
1162
1090
|
});
|
|
1163
1091
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable delta between two Smithy model snapshots (dev-time only),
|
|
3
|
+
* as JSON pointers. Used by the patch audit to say what a patch changes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Model files keyed by path relative to `.generated-specs`, as text. */
|
|
7
|
+
export type Models = Map<string, string>;
|
|
8
|
+
|
|
9
|
+
export const MAX_DIFF_LINES = 12;
|
|
10
|
+
|
|
11
|
+
const isObject = (v: unknown): v is Record<string, unknown> =>
|
|
12
|
+
v !== null && typeof v === "object" && !Array.isArray(v);
|
|
13
|
+
|
|
14
|
+
const show = (v: unknown): string => {
|
|
15
|
+
const text = JSON.stringify(v);
|
|
16
|
+
return text.length > 60 ? text.slice(0, 57) + "…" : text;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** JSON pointers at which `a` (with the patch) and `b` (without) differ. */
|
|
20
|
+
const diffPointers = (a: unknown, b: unknown, pointer: string, out: string[]): void => {
|
|
21
|
+
if (out.length > MAX_DIFF_LINES) return;
|
|
22
|
+
if (isObject(a) && isObject(b)) {
|
|
23
|
+
for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
24
|
+
const child = `${pointer}/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`;
|
|
25
|
+
if (!(key in b)) out.push(`+ ${child}`);
|
|
26
|
+
else if (!(key in a)) out.push(`- ${child}`);
|
|
27
|
+
else diffPointers(a[key], b[key], child, out);
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
32
|
+
const n = Math.max(a.length, b.length);
|
|
33
|
+
for (let i = 0; i < n; i++) {
|
|
34
|
+
const child = `${pointer}/${i}`;
|
|
35
|
+
if (i >= b.length) out.push(`+ ${child} ${show(a[i])}`);
|
|
36
|
+
else if (i >= a.length) out.push(`- ${child} ${show(b[i])}`);
|
|
37
|
+
else diffPointers(a[i], b[i], child, out);
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (JSON.stringify(a) !== JSON.stringify(b)) {
|
|
42
|
+
out.push(`~ ${pointer} ${show(a)} → ${show(b)}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Human-readable delta between two model snapshots, `[]` when identical. */
|
|
47
|
+
export const diffModels = (withPatch: Models, without: Models): string[] => {
|
|
48
|
+
const out: string[] = [];
|
|
49
|
+
const many = withPatch.size > 1;
|
|
50
|
+
for (const rel of new Set([...withPatch.keys(), ...without.keys()])) {
|
|
51
|
+
const a = withPatch.get(rel);
|
|
52
|
+
const b = without.get(rel);
|
|
53
|
+
if (a === b) continue;
|
|
54
|
+
if (a === undefined || b === undefined) {
|
|
55
|
+
out.push(`${a === undefined ? "-" : "+"} ${rel}`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const lines: string[] = [];
|
|
59
|
+
diffPointers(JSON.parse(a), JSON.parse(b), "", lines);
|
|
60
|
+
for (const line of lines) {
|
|
61
|
+
// `+ /shapes/com.x.api#Foo/members/…` → `+ Foo/members/…`
|
|
62
|
+
const short = line.replace(/^(. )\/shapes\/[^/#]*#/, "$1");
|
|
63
|
+
out.push((many ? `${rel}: ` : "") + short);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
};
|
package/src/codegen/naming.ts
CHANGED
|
@@ -75,8 +75,7 @@ export const lowerFirst = (s: string): string => {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
/** Upper-case the first character. */
|
|
78
|
-
export const upperFirst = (s: string): string =>
|
|
79
|
-
s.charAt(0).toUpperCase() + s.slice(1);
|
|
78
|
+
export const upperFirst = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
81
|
* Collapse a smithy documentation string to a single safe line for a
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { convertOpenApiToSmithy } from "./openapi.ts";
|
|
3
|
+
|
|
4
|
+
const model = (
|
|
5
|
+
schema: unknown,
|
|
6
|
+
mediaType = "multipart/form-data",
|
|
7
|
+
responseSchema: unknown = { type: "string", format: "binary" },
|
|
8
|
+
components: Record<string, unknown> = {},
|
|
9
|
+
options: { binaryTypes?: boolean } = { binaryTypes: true },
|
|
10
|
+
) =>
|
|
11
|
+
convertOpenApiToSmithy(
|
|
12
|
+
{
|
|
13
|
+
openapi: "3.0.3",
|
|
14
|
+
info: { title: "Binary", version: "1" },
|
|
15
|
+
components,
|
|
16
|
+
paths: {
|
|
17
|
+
"/files": {
|
|
18
|
+
post: {
|
|
19
|
+
operationId: "uploadFile",
|
|
20
|
+
requestBody: { content: { [mediaType]: { schema } } },
|
|
21
|
+
responses: {
|
|
22
|
+
"200": {
|
|
23
|
+
content: {
|
|
24
|
+
"application/octet-stream": {
|
|
25
|
+
schema: responseSchema,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{ namespace: "com.example.binary", serviceName: "Binary", ...options },
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
describe("OpenAPI binary contracts", () => {
|
|
38
|
+
for (const options of [{}, { binaryTypes: false }]) {
|
|
39
|
+
test(`binary conversion preserves existing contracts with ${JSON.stringify(options)}`, () => {
|
|
40
|
+
const result = model(
|
|
41
|
+
{
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
zip: { type: "string", format: "binary" },
|
|
45
|
+
archive: { $ref: "#/components/schemas/Archive" },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
"multipart/form-data",
|
|
49
|
+
{ $ref: "#/components/schemas/Archive" },
|
|
50
|
+
{ schemas: { Archive: { type: "string", format: "binary" } } },
|
|
51
|
+
options,
|
|
52
|
+
);
|
|
53
|
+
const request = result.shapes["com.example.binary#UploadFileRequest"];
|
|
54
|
+
expect(request.members.zip.target).toBe("smithy.api#String");
|
|
55
|
+
expect(request.members.archive.target).toBe("smithy.api#String");
|
|
56
|
+
expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe("smithy.api#Unit");
|
|
57
|
+
expect(result.shapes["com.example.binary#UploadFileResponse"]).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test("component-referenced binary responses retain the original reference's nullability", () => {
|
|
62
|
+
const result = model(
|
|
63
|
+
{ type: "object" },
|
|
64
|
+
"application/json",
|
|
65
|
+
{ $ref: "#/components/schemas/Archive", nullable: true },
|
|
66
|
+
{ schemas: { Archive: { type: "string", format: "binary" } } },
|
|
67
|
+
);
|
|
68
|
+
const body = result.shapes["com.example.binary#UploadFileResponse"].members.body;
|
|
69
|
+
expect(body.target).toBe("smithy.api#Blob");
|
|
70
|
+
expect(body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
71
|
+
expect(body.traits["com.distilled.openapi#nullable"]).toEqual({});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("multipart binary fields become blobs, not text or base64", () => {
|
|
75
|
+
const result = model({
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
zip: { type: "string", format: "binary" },
|
|
79
|
+
encoded: { type: "string", format: "byte" },
|
|
80
|
+
environment: { type: "string" },
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
const request = result.shapes["com.example.binary#UploadFileRequest"];
|
|
84
|
+
expect(request.members.zip.target).toBe("smithy.api#Blob");
|
|
85
|
+
expect(request.members.encoded.target).toBe("smithy.api#String");
|
|
86
|
+
expect(request.members.environment.target).toBe("smithy.api#String");
|
|
87
|
+
const response = result.shapes["com.example.binary#UploadFileResponse"];
|
|
88
|
+
expect(response.members.body.target).toBe("smithy.api#Blob");
|
|
89
|
+
expect(response.members.body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* OpenAPI → Smithy pipeline helper (dev-time only, provider-agnostic).
|
|
3
3
|
*
|
|
4
4
|
* Owns the spec-side pipeline every OpenAPI-sourced provider shares: read the
|
|
5
|
-
* spec file,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `onStalePatch: "warn"`.
|
|
5
|
+
* spec file, convert it with {@link convertOpenApiToSmithy} (upstream names,
|
|
6
|
+
* the verbNoun names deferred), and write `.generated-specs/<name>.json`;
|
|
7
|
+
* then {@link finalizeConvert} applies the package's RFC-6902 patches (Smithy
|
|
8
|
+
* ops only: `/shapes`, `/metadata`) and the deferred names, so patches target
|
|
9
|
+
* the names the spec gives. Stale targets fail unless `onStalePatch: "warn"`.
|
|
10
10
|
*
|
|
11
11
|
* A provider's `scripts/convert.ts` is: a `runOpenApiConvert` call.
|
|
12
12
|
* `scripts/generate.ts` compiles the already-patched models and does not
|
|
@@ -14,16 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as fs from "node:fs/promises";
|
|
16
16
|
import * as path from "node:path";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
type OpenApiConvertOptions,
|
|
20
|
-
} from "./openapi.ts";
|
|
21
|
-
import {
|
|
22
|
-
applyRfc6902Files,
|
|
23
|
-
finalizeConvert,
|
|
24
|
-
isSmithyPatchPath,
|
|
25
|
-
listRfc6902PatchFiles,
|
|
26
|
-
} from "./patches.ts";
|
|
17
|
+
import { convertOpenApiToSmithy, type OpenApiConvertOptions } from "./openapi.ts";
|
|
18
|
+
import { finalizeConvert } from "./patches.ts";
|
|
27
19
|
import { resolveSpecPath } from "./spec-path.ts";
|
|
28
20
|
|
|
29
21
|
export interface OpenApiSpecEntry {
|
|
@@ -32,7 +24,7 @@ export interface OpenApiSpecEntry {
|
|
|
32
24
|
/** Spec file path, relative to `root` (or absolute). */
|
|
33
25
|
readonly specPath: string;
|
|
34
26
|
/**
|
|
35
|
-
* Hook between
|
|
27
|
+
* Hook between reading and conversion (e.g. path prefixing, server
|
|
36
28
|
* rewrites). May mutate the spec in place or return a replacement.
|
|
37
29
|
*/
|
|
38
30
|
readonly preprocess?: (spec: any) => unknown | void | Promise<unknown | void>;
|
|
@@ -41,15 +33,14 @@ export interface OpenApiSpecEntry {
|
|
|
41
33
|
}
|
|
42
34
|
|
|
43
35
|
export interface RunOpenApiConvertOptions {
|
|
44
|
-
/** Absolute package root (usually `path.resolve(import.meta.
|
|
36
|
+
/** Absolute package root (usually `path.resolve(import.meta.dirname, "..")`). */
|
|
45
37
|
readonly root: string;
|
|
46
38
|
readonly specs: readonly OpenApiSpecEntry[];
|
|
47
39
|
/**
|
|
48
|
-
* RFC-6902 patch
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* apply to the Smithy model after conversion; the rest apply to OpenAPI.
|
|
40
|
+
* RFC-6902 patch root, relative to `root`. Default `"patches"`; `false`
|
|
41
|
+
* disables. Layout: `<patchesDir>/<name>/*.json` when the per-spec
|
|
42
|
+
* directory exists; for single-spec providers a flat `<patchesDir>/*.json`
|
|
43
|
+
* also works. Every op targets the Smithy model (`/shapes`, `/metadata`).
|
|
53
44
|
*/
|
|
54
45
|
readonly patchesDir?: string | false;
|
|
55
46
|
/** Output directory, relative to `root`. Default `".generated-specs"`. */
|
|
@@ -68,10 +59,11 @@ export interface RunOpenApiConvertOptions {
|
|
|
68
59
|
*/
|
|
69
60
|
readonly onStalePatch?: "fail" | "warn";
|
|
70
61
|
/**
|
|
71
|
-
* Run {@link finalizeConvert} on the written models (
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
62
|
+
* Run {@link finalizeConvert} on the written models (Smithy patches,
|
|
63
|
+
* deferred names, reference check, finalized marker). Default true. Pass
|
|
64
|
+
* false when the caller finalizes once after several convert steps (Fly
|
|
65
|
+
* machines + sprites + addons); its finalizeConvert must then apply the
|
|
66
|
+
* Smithy patches, from `patches/<name>/`.
|
|
75
67
|
*/
|
|
76
68
|
readonly finalize?: boolean;
|
|
77
69
|
}
|
|
@@ -86,14 +78,10 @@ const exists = async (p: string): Promise<boolean> => {
|
|
|
86
78
|
};
|
|
87
79
|
|
|
88
80
|
/** Run the OpenAPI→Smithy conversion pipeline (plain async — call from a script). */
|
|
89
|
-
export const runOpenApiConvert = async (
|
|
90
|
-
o: RunOpenApiConvertOptions,
|
|
91
|
-
): Promise<void> => {
|
|
81
|
+
export const runOpenApiConvert = async (o: RunOpenApiConvertOptions): Promise<void> => {
|
|
92
82
|
const outDir = path.resolve(o.root, o.outDir ?? ".generated-specs");
|
|
93
83
|
const patchRoot =
|
|
94
|
-
o.patchesDir === false
|
|
95
|
-
? undefined
|
|
96
|
-
: path.resolve(o.root, o.patchesDir ?? "patches");
|
|
84
|
+
o.patchesDir === false ? undefined : path.resolve(o.root, o.patchesDir ?? "patches");
|
|
97
85
|
const parse = o.parse ?? ((text: string) => JSON.parse(text));
|
|
98
86
|
const onStalePatch = o.onStalePatch ?? "fail";
|
|
99
87
|
|
|
@@ -102,69 +90,38 @@ export const runOpenApiConvert = async (
|
|
|
102
90
|
console.log("🛠️ openapi → smithy");
|
|
103
91
|
console.log(` Output: ${outDir}`);
|
|
104
92
|
|
|
93
|
+
// Each spec's patch dir, relative to the patch root: `<name>/` when it
|
|
94
|
+
// exists, else the root itself for a single-spec provider.
|
|
95
|
+
const patchDirs = new Map<string, string>();
|
|
96
|
+
if (patchRoot && (await exists(patchRoot))) {
|
|
97
|
+
for (const entry of o.specs) {
|
|
98
|
+
if (await exists(path.join(patchRoot, entry.name))) patchDirs.set(entry.name, entry.name);
|
|
99
|
+
else if (o.specs.length === 1) patchDirs.set(entry.name, "");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
105
103
|
for (const entry of o.specs) {
|
|
106
104
|
// Production path by default; `specs/.local` under DISTILLED_SPECS_LOCAL.
|
|
107
105
|
const specPath = resolveSpecPath(o.root, entry.specPath);
|
|
108
106
|
let spec: any = parse(await fs.readFile(specPath, "utf8"), specPath);
|
|
109
107
|
|
|
110
|
-
// ---- RFC-6902: OpenAPI ops before convert, Smithy ops after ----
|
|
111
|
-
let patchDir: string | undefined;
|
|
112
|
-
if (patchRoot && (await exists(patchRoot))) {
|
|
113
|
-
const perSpec = path.join(patchRoot, entry.name);
|
|
114
|
-
if (await exists(perSpec)) {
|
|
115
|
-
patchDir = perSpec;
|
|
116
|
-
} else if (o.specs.length === 1) {
|
|
117
|
-
patchDir = patchRoot;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const patchFiles = patchDir ? await listRfc6902PatchFiles(patchDir) : [];
|
|
121
|
-
const patchLabel = (file: string) => `${entry.name}/${path.basename(file)}`;
|
|
122
|
-
const openapiPatches = await applyRfc6902Files(spec, patchFiles, {
|
|
123
|
-
onStalePatch,
|
|
124
|
-
include: (op) => !isSmithyPatchPath(op.path),
|
|
125
|
-
label: patchLabel,
|
|
126
|
-
});
|
|
127
|
-
if (openapiPatches.errors.length) {
|
|
128
|
-
for (const b of openapiPatches.errors)
|
|
129
|
-
console.error(`❌ bad patch: ${b}`);
|
|
130
|
-
throw new Error(
|
|
131
|
-
`${openapiPatches.errors.length} patch operation(s) failed — fix the pointers or delete the patch`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
108
|
// ---- Preprocess hook ----
|
|
136
109
|
if (entry.preprocess) {
|
|
137
110
|
const replaced = await entry.preprocess(spec);
|
|
138
111
|
if (replaced !== undefined) spec = replaced;
|
|
139
112
|
}
|
|
140
113
|
|
|
141
|
-
// ---- Convert,
|
|
114
|
+
// ---- Convert, write ----
|
|
142
115
|
const model = convertOpenApiToSmithy(spec, {
|
|
116
|
+
deferNaming: true,
|
|
143
117
|
...o.options,
|
|
144
118
|
...entry.options,
|
|
145
119
|
});
|
|
146
|
-
const
|
|
147
|
-
onStalePatch,
|
|
148
|
-
include: (op) => isSmithyPatchPath(op.path),
|
|
149
|
-
label: patchLabel,
|
|
150
|
-
});
|
|
151
|
-
if (smithyPatches.errors.length) {
|
|
152
|
-
for (const b of smithyPatches.errors) console.error(`❌ bad patch: ${b}`);
|
|
153
|
-
throw new Error(
|
|
154
|
-
`${smithyPatches.errors.length} Smithy patch operation(s) failed — fix the pointers or delete the patch`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
const opCount = Object.values(model.shapes).filter(
|
|
158
|
-
(s: any) => s.type === "operation",
|
|
159
|
-
).length;
|
|
120
|
+
const opCount = Object.values(model.shapes).filter((s: any) => s.type === "operation").length;
|
|
160
121
|
const outPath = path.join(outDir, `${entry.name}.json`);
|
|
161
122
|
await fs.writeFile(outPath, JSON.stringify(model, null, 2) + "\n");
|
|
162
|
-
const staleOps = openapiPatches.stale + smithyPatches.stale;
|
|
163
123
|
console.log(
|
|
164
|
-
` ✅ ${entry.name}: ${opCount} operations, ${Object.keys(model.shapes).length} shapes
|
|
165
|
-
(patchFiles.length
|
|
166
|
-
? ` (${patchFiles.length} patch file(s) applied${staleOps ? `, ${staleOps} stale op(s) skipped` : ""})`
|
|
167
|
-
: ""),
|
|
124
|
+
` ✅ ${entry.name}: ${opCount} operations, ${Object.keys(model.shapes).length} shapes`,
|
|
168
125
|
);
|
|
169
126
|
}
|
|
170
127
|
|
|
@@ -173,8 +130,10 @@ export const runOpenApiConvert = async (
|
|
|
173
130
|
await finalizeConvert({
|
|
174
131
|
root: o.root,
|
|
175
132
|
outDir,
|
|
176
|
-
|
|
177
|
-
|
|
133
|
+
patchesDir: patchRoot ?? false,
|
|
134
|
+
patchesFor: (resource) => patchDirs.get(resource),
|
|
135
|
+
onStalePatch,
|
|
136
|
+
// The converter computed the names; finalize only applies them.
|
|
178
137
|
operationNaming: "as-is",
|
|
179
138
|
include: (resource) => written.has(resource),
|
|
180
139
|
});
|