@distilled.cloud/core 1.0.0-rc.13 → 1.0.0-rc.15
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.map +1 -1
- package/lib/codegen/boolean-string-enums.js +2 -6
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +3 -5
- 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 +4 -2
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +37 -75
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.js +4 -9
- package/lib/codegen/generator.test.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +12 -33
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +4 -12
- 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.js +1 -1
- package/lib/codegen/openapi-binary.test.js.map +1 -1
- 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 +9 -1
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +48 -42
- 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 +59 -10
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +233 -63
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +8 -4
- 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.js +1 -1
- package/lib/codegen/untagged-unions.test.js.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -5
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +4 -8
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +20 -48
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +6 -6
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js.map +1 -1
- 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.map +1 -1
- package/lib/pagination.js +6 -16
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.js +3 -6
- package/lib/pagination.test.js.map +1 -1
- package/lib/protocol-http.d.ts +20 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +41 -47
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +20 -10
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +9 -18
- 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/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js.map +1 -1
- package/lib/response-validation.test.js +10 -5
- package/lib/response-validation.test.js.map +1 -1
- 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 +2 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -1
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +3 -7
- package/lib/xml.js.map +1 -1
- package/lib/xml.test.js +11 -12
- package/lib/xml.test.js.map +1 -1
- package/package.json +7 -10
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +12 -28
- package/src/codegen/boolean-string-enums.ts +2 -10
- 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 +8 -22
- package/src/codegen/generator.ts +72 -191
- package/src/codegen/graphql-client.test.ts +12 -42
- package/src/codegen/graphql-client.ts +30 -95
- 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 +5 -12
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +79 -136
- 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 +14 -21
- package/src/codegen/patches.ts +313 -103
- 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 +3 -7
- package/src/error-category.ts +5 -17
- package/src/errors.ts +16 -31
- package/src/graphql.test.ts +6 -8
- package/src/graphql.ts +76 -219
- package/src/graphql.types.ts +10 -25
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +13 -35
- package/src/pagination.ts +44 -111
- package/src/protocol-http.test.ts +36 -30
- package/src/protocol-http.ts +73 -138
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +24 -62
- package/src/response-validation.test.ts +12 -18
- package/src/response-validation.ts +3 -12
- 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 +4 -10
- package/src/trait.ts +21 -67
- package/src/xml.test.ts +15 -33
- package/src/xml.ts +9 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, test } from "
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
import { convertOpenApiToSmithy } from "./openapi.ts";
|
|
3
3
|
|
|
4
4
|
const model = (
|
|
@@ -53,12 +53,8 @@ describe("OpenAPI binary contracts", () => {
|
|
|
53
53
|
const request = result.shapes["com.example.binary#UploadFileRequest"];
|
|
54
54
|
expect(request.members.zip.target).toBe("smithy.api#String");
|
|
55
55
|
expect(request.members.archive.target).toBe("smithy.api#String");
|
|
56
|
-
expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe(
|
|
57
|
-
|
|
58
|
-
);
|
|
59
|
-
expect(
|
|
60
|
-
result.shapes["com.example.binary#UploadFileResponse"],
|
|
61
|
-
).toBeUndefined();
|
|
56
|
+
expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe("smithy.api#Unit");
|
|
57
|
+
expect(result.shapes["com.example.binary#UploadFileResponse"]).toBeUndefined();
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
60
|
|
|
@@ -69,8 +65,7 @@ describe("OpenAPI binary contracts", () => {
|
|
|
69
65
|
{ $ref: "#/components/schemas/Archive", nullable: true },
|
|
70
66
|
{ schemas: { Archive: { type: "string", format: "binary" } } },
|
|
71
67
|
);
|
|
72
|
-
const body =
|
|
73
|
-
result.shapes["com.example.binary#UploadFileResponse"].members.body;
|
|
68
|
+
const body = result.shapes["com.example.binary#UploadFileResponse"].members.body;
|
|
74
69
|
expect(body.target).toBe("smithy.api#Blob");
|
|
75
70
|
expect(body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
76
71
|
expect(body.traits["com.distilled.openapi#nullable"]).toEqual({});
|
|
@@ -91,8 +86,6 @@ describe("OpenAPI binary contracts", () => {
|
|
|
91
86
|
expect(request.members.environment.target).toBe("smithy.api#String");
|
|
92
87
|
const response = result.shapes["com.example.binary#UploadFileResponse"];
|
|
93
88
|
expect(response.members.body.target).toBe("smithy.api#Blob");
|
|
94
|
-
expect(
|
|
95
|
-
response.members.body.traits["com.distilled.openapi#rawResponse"],
|
|
96
|
-
).toEqual({});
|
|
89
|
+
expect(response.members.body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
97
90
|
});
|
|
98
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
|
});
|
package/src/codegen/openapi.ts
CHANGED
|
@@ -48,6 +48,8 @@ import {
|
|
|
48
48
|
isMechanicalOperationId,
|
|
49
49
|
isVerbatimRouteId,
|
|
50
50
|
pathToVerbNoun,
|
|
51
|
+
RENAME_METADATA_KEY,
|
|
52
|
+
renameShapes,
|
|
51
53
|
resolveOperationName,
|
|
52
54
|
toVerbNoun,
|
|
53
55
|
type OperationIdRewrite,
|
|
@@ -217,6 +219,13 @@ export interface OpenApiConvertOptions {
|
|
|
217
219
|
* `"METHOD path"` keys when two methods share an `operationId`.
|
|
218
220
|
*/
|
|
219
221
|
readonly operationNames?: OperationIdRewrite;
|
|
222
|
+
/**
|
|
223
|
+
* Name shapes from the spec (`PascalCase(operationId)`, no overrides) and
|
|
224
|
+
* record the {@link operationNaming} names in
|
|
225
|
+
* `metadata[RENAME_METADATA_KEY]`; `finalizeConvert` renames after the
|
|
226
|
+
* Smithy patches, so patches target upstream names.
|
|
227
|
+
*/
|
|
228
|
+
readonly deferNaming?: boolean;
|
|
220
229
|
}
|
|
221
230
|
|
|
222
231
|
export interface SmithyModel {
|
|
@@ -265,9 +274,7 @@ const headerMemberName = (name: string): string => {
|
|
|
265
274
|
if (parts.length === 0) return "_";
|
|
266
275
|
const out = parts
|
|
267
276
|
.map((p, i) =>
|
|
268
|
-
i === 0
|
|
269
|
-
? p.charAt(0).toLowerCase() + p.slice(1)
|
|
270
|
-
: p.charAt(0).toUpperCase() + p.slice(1),
|
|
277
|
+
i === 0 ? p.charAt(0).toLowerCase() + p.slice(1) : p.charAt(0).toUpperCase() + p.slice(1),
|
|
271
278
|
)
|
|
272
279
|
.join("");
|
|
273
280
|
return /^[0-9]/.test(out) ? `_${out}` : out;
|
|
@@ -400,12 +407,7 @@ const flattenObject = (ctx: Ctx, def: any, depth = 0): FlatObject => {
|
|
|
400
407
|
// once per flag combination instead of exponentially (MongoDB Atlas's
|
|
401
408
|
// polymorphic allOf/oneOf graph never finished under the bare depth cap).
|
|
402
409
|
const seen = new Set<string>();
|
|
403
|
-
const visit = (
|
|
404
|
-
d: any,
|
|
405
|
-
dep: number,
|
|
406
|
-
inAllOf: boolean,
|
|
407
|
-
inUnion: boolean,
|
|
408
|
-
): void => {
|
|
410
|
+
const visit = (d: any, dep: number, inAllOf: boolean, inUnion: boolean): void => {
|
|
409
411
|
if (dep > MAX_SCHEMA_DEPTH) return;
|
|
410
412
|
if (d && typeof d === "object" && typeof d.$ref === "string") {
|
|
411
413
|
const key = `${d.$ref}|${inAllOf}|${inUnion}`;
|
|
@@ -455,11 +457,7 @@ const isNullBranch = (ctx: Ctx, branch: any): boolean => {
|
|
|
455
457
|
if (Array.isArray(r.type) && r.type.every((t: unknown) => t === "null")) {
|
|
456
458
|
return true;
|
|
457
459
|
}
|
|
458
|
-
if (
|
|
459
|
-
Array.isArray(r.enum) &&
|
|
460
|
-
r.enum.length > 0 &&
|
|
461
|
-
r.enum.every((v: unknown) => v === null)
|
|
462
|
-
) {
|
|
460
|
+
if (Array.isArray(r.enum) && r.enum.length > 0 && r.enum.every((v: unknown) => v === null)) {
|
|
463
461
|
return true;
|
|
464
462
|
}
|
|
465
463
|
return false;
|
|
@@ -495,9 +493,7 @@ const schemaChildren = (d: any): any[] => [
|
|
|
495
493
|
...(Array.isArray(d.allOf) ? d.allOf : []),
|
|
496
494
|
...(Array.isArray(d.oneOf) ? d.oneOf : []),
|
|
497
495
|
...(Array.isArray(d.anyOf) ? d.anyOf : []),
|
|
498
|
-
...(d.properties && typeof d.properties === "object"
|
|
499
|
-
? Object.values(d.properties)
|
|
500
|
-
: []),
|
|
496
|
+
...(d.properties && typeof d.properties === "object" ? Object.values(d.properties) : []),
|
|
501
497
|
...(d.items ? [d.items] : []),
|
|
502
498
|
...(d.additionalProperties && typeof d.additionalProperties === "object"
|
|
503
499
|
? [d.additionalProperties]
|
|
@@ -763,14 +759,7 @@ const convertSchema = (
|
|
|
763
759
|
// Single-entry allOf over a $ref: passthrough (v0 semantics), carrying
|
|
764
760
|
// the parent's nullability/description.
|
|
765
761
|
if (def.allOf.length === 1 && !def.properties) {
|
|
766
|
-
const r = convertSchema(
|
|
767
|
-
ctx,
|
|
768
|
-
def.allOf[0],
|
|
769
|
-
hint,
|
|
770
|
-
depth + 1,
|
|
771
|
-
dir,
|
|
772
|
-
reservedId,
|
|
773
|
-
);
|
|
762
|
+
const r = convertSchema(ctx, def.allOf[0], hint, depth + 1, dir, reservedId);
|
|
774
763
|
return { target: r.target, nullable: nullable || r.nullable };
|
|
775
764
|
}
|
|
776
765
|
const flat = flattenObject(ctx, def, depth);
|
|
@@ -790,14 +779,7 @@ const convertSchema = (
|
|
|
790
779
|
}
|
|
791
780
|
if (!flat.isObject) return inline(PRELUDE.Document, nullable);
|
|
792
781
|
}
|
|
793
|
-
const members = buildMembers(
|
|
794
|
-
ctx,
|
|
795
|
-
flat.properties,
|
|
796
|
-
flat.required,
|
|
797
|
-
hint,
|
|
798
|
-
depth + 1,
|
|
799
|
-
dir,
|
|
800
|
-
);
|
|
782
|
+
const members = buildMembers(ctx, flat.properties, flat.required, hint, depth + 1, dir);
|
|
801
783
|
return {
|
|
802
784
|
target: emit({ type: "structure", members, traits: docTraits }, hint),
|
|
803
785
|
nullable,
|
|
@@ -877,17 +859,8 @@ const convertSchema = (
|
|
|
877
859
|
// --- object ---------------------------------------------------------------
|
|
878
860
|
if (t === "object" || def.properties || def.additionalProperties) {
|
|
879
861
|
if (def.properties && Object.keys(def.properties).length > 0) {
|
|
880
|
-
const required = new Set<string>(
|
|
881
|
-
|
|
882
|
-
);
|
|
883
|
-
const members = buildMembers(
|
|
884
|
-
ctx,
|
|
885
|
-
def.properties,
|
|
886
|
-
required,
|
|
887
|
-
hint,
|
|
888
|
-
depth + 1,
|
|
889
|
-
dir,
|
|
890
|
-
);
|
|
862
|
+
const required = new Set<string>(Array.isArray(def.required) ? def.required : []);
|
|
863
|
+
const members = buildMembers(ctx, def.properties, required, hint, depth + 1, dir);
|
|
891
864
|
return {
|
|
892
865
|
target: emit({ type: "structure", members, traits: docTraits }, hint),
|
|
893
866
|
nullable,
|
|
@@ -922,9 +895,7 @@ const convertSchema = (
|
|
|
922
895
|
switch (t) {
|
|
923
896
|
case "string":
|
|
924
897
|
return inline(
|
|
925
|
-
ctx.binaryTypes && def.format === "binary"
|
|
926
|
-
? PRELUDE.Blob
|
|
927
|
-
: PRELUDE.String,
|
|
898
|
+
ctx.binaryTypes && def.format === "binary" ? PRELUDE.Blob : PRELUDE.String,
|
|
928
899
|
nullable,
|
|
929
900
|
);
|
|
930
901
|
case "boolean":
|
|
@@ -1049,11 +1020,7 @@ const collectParams = (ctx: Ctx, pathItem: any, op: any): Param[] => {
|
|
|
1049
1020
|
byKey.set(`${p.in}${p.name}`, p);
|
|
1050
1021
|
}
|
|
1051
1022
|
return [...byKey.values()].filter(
|
|
1052
|
-
(p) =>
|
|
1053
|
-
p.in === "path" ||
|
|
1054
|
-
p.in === "query" ||
|
|
1055
|
-
p.in === "body" ||
|
|
1056
|
-
p.in === "header",
|
|
1023
|
+
(p) => p.in === "path" || p.in === "query" || p.in === "body" || p.in === "header",
|
|
1057
1024
|
);
|
|
1058
1025
|
};
|
|
1059
1026
|
|
|
@@ -1104,12 +1071,9 @@ const trimDescription = (desc: unknown): string | undefined => {
|
|
|
1104
1071
|
};
|
|
1105
1072
|
|
|
1106
1073
|
const opDoc = (op: any): string | undefined => {
|
|
1107
|
-
const summary =
|
|
1108
|
-
typeof op.summary === "string" ? op.summary.trim() : undefined;
|
|
1074
|
+
const summary = typeof op.summary === "string" ? op.summary.trim() : undefined;
|
|
1109
1075
|
const desc = trimDescription(op.description);
|
|
1110
|
-
const parts = [summary, desc].filter(
|
|
1111
|
-
(s): s is string => s !== undefined && s !== "",
|
|
1112
|
-
);
|
|
1076
|
+
const parts = [summary, desc].filter((s): s is string => s !== undefined && s !== "");
|
|
1113
1077
|
return parts.length ? parts.join("\n\n") : undefined;
|
|
1114
1078
|
};
|
|
1115
1079
|
|
|
@@ -1135,10 +1099,7 @@ const successSchema = (
|
|
|
1135
1099
|
const binary = resp.content?.["application/octet-stream"]?.schema;
|
|
1136
1100
|
return {
|
|
1137
1101
|
schema:
|
|
1138
|
-
json ??
|
|
1139
|
-
(ctx.binaryTypes && deref(ctx, binary)?.format === "binary"
|
|
1140
|
-
? binary
|
|
1141
|
-
: undefined),
|
|
1102
|
+
json ?? (ctx.binaryTypes && deref(ctx, binary)?.format === "binary" ? binary : undefined),
|
|
1142
1103
|
};
|
|
1143
1104
|
}
|
|
1144
1105
|
return { schema: undefined };
|
|
@@ -1203,9 +1164,7 @@ const detectPagination = (
|
|
|
1203
1164
|
|
|
1204
1165
|
let mode: DetectedPagination["mode"] | undefined;
|
|
1205
1166
|
let outputToken: string | undefined;
|
|
1206
|
-
const pag = bag["pagination"]
|
|
1207
|
-
? flattenObject(ctx, bag["pagination"]).properties
|
|
1208
|
-
: undefined;
|
|
1167
|
+
const pag = bag["pagination"] ? flattenObject(ctx, bag["pagination"]).properties : undefined;
|
|
1209
1168
|
if (pag?.["cursor"]) {
|
|
1210
1169
|
mode = "cursor";
|
|
1211
1170
|
outputToken = "pagination.cursor";
|
|
@@ -1231,9 +1190,7 @@ const detectPagination = (
|
|
|
1231
1190
|
if (!mode || !outputToken) return undefined;
|
|
1232
1191
|
|
|
1233
1192
|
const aliases = PAGINATION_INPUT_ALIASES[mode]!;
|
|
1234
|
-
const inputToken = params.find(
|
|
1235
|
-
(p) => p.in === "query" && aliases.includes(p.name),
|
|
1236
|
-
)?.name;
|
|
1193
|
+
const inputToken = params.find((p) => p.in === "query" && aliases.includes(p.name))?.name;
|
|
1237
1194
|
if (!inputToken) return undefined;
|
|
1238
1195
|
|
|
1239
1196
|
let items: string | undefined;
|
|
@@ -1275,10 +1232,48 @@ const DEFAULT_ERROR_STATUSES = ["401", "429", "500", "503"];
|
|
|
1275
1232
|
|
|
1276
1233
|
const DEFAULT_SUCCESS_STATUSES = ["200", "201", "204"];
|
|
1277
1234
|
|
|
1235
|
+
export { RENAME_METADATA_KEY };
|
|
1236
|
+
|
|
1278
1237
|
export const convertOpenApiToSmithy = (
|
|
1279
1238
|
spec: unknown,
|
|
1280
1239
|
options: OpenApiConvertOptions,
|
|
1281
1240
|
): SmithyModel => {
|
|
1241
|
+
const named = convertOnce(spec, options);
|
|
1242
|
+
if (!options.deferNaming) return named;
|
|
1243
|
+
const upstream = convertOnce(spec, {
|
|
1244
|
+
...options,
|
|
1245
|
+
operationNaming: "as-is",
|
|
1246
|
+
operationNames: undefined,
|
|
1247
|
+
});
|
|
1248
|
+
// Names never steer the conversion (only uniqueness suffixes and the
|
|
1249
|
+
// `By<Param>` rule read them), so both runs create the same shapes in the
|
|
1250
|
+
// same order: the i-th shape of one is the i-th of the other.
|
|
1251
|
+
const from = Object.keys(upstream.shapes);
|
|
1252
|
+
const to = Object.keys(named.shapes);
|
|
1253
|
+
if (from.length !== to.length) {
|
|
1254
|
+
throw new Error(
|
|
1255
|
+
`deferNaming (${options.namespace}): ${from.length} shapes with upstream names, ${to.length} with final names`,
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
const rename: Record<string, string> = {};
|
|
1259
|
+
for (let i = 0; i < from.length; i++) if (from[i] !== to[i]) rename[from[i]!] = to[i]!;
|
|
1260
|
+
const check = structuredClone(upstream);
|
|
1261
|
+
renameShapes(check, new Map(Object.entries(rename)));
|
|
1262
|
+
if (JSON.stringify(check) !== JSON.stringify(named)) {
|
|
1263
|
+
const differs = to.find(
|
|
1264
|
+
(id) => JSON.stringify(check.shapes[id]) !== JSON.stringify(named.shapes[id]),
|
|
1265
|
+
);
|
|
1266
|
+
throw new Error(
|
|
1267
|
+
`deferNaming (${options.namespace}): the upstream-named model does not rename to the final one (first difference: ${differs ?? "metadata"})`,
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
if (Object.keys(rename).length > 0) {
|
|
1271
|
+
upstream.metadata = { ...upstream.metadata, [RENAME_METADATA_KEY]: rename };
|
|
1272
|
+
}
|
|
1273
|
+
return upstream;
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel => {
|
|
1282
1277
|
const doc = spec as any;
|
|
1283
1278
|
const version = detectVersion(doc);
|
|
1284
1279
|
const ctx: Ctx = {
|
|
@@ -1292,18 +1287,13 @@ export const convertOpenApiToSmithy = (
|
|
|
1292
1287
|
sensitivePatterns: options.sensitivePatterns ?? SENSITIVE_FIELD_PATTERNS,
|
|
1293
1288
|
binaryTypes: options.binaryTypes ?? false,
|
|
1294
1289
|
};
|
|
1295
|
-
const statusToErrorClass =
|
|
1296
|
-
|
|
1297
|
-
const defaultErrorStatuses = new Set(
|
|
1298
|
-
options.defaultErrorStatuses ?? DEFAULT_ERROR_STATUSES,
|
|
1299
|
-
);
|
|
1290
|
+
const statusToErrorClass = options.statusToErrorClass ?? DEFAULT_STATUS_TO_ERROR_CLASS;
|
|
1291
|
+
const defaultErrorStatuses = new Set(options.defaultErrorStatuses ?? DEFAULT_ERROR_STATUSES);
|
|
1300
1292
|
const skipDeprecated = options.skipDeprecated ?? true;
|
|
1301
1293
|
const successStatuses = options.successStatuses ?? DEFAULT_SUCCESS_STATUSES;
|
|
1302
1294
|
const httpMethods = [
|
|
1303
1295
|
...HTTP_METHODS,
|
|
1304
|
-
...OPTIONAL_HTTP_METHODS.filter((m) =>
|
|
1305
|
-
options.extraHttpMethods?.includes(m),
|
|
1306
|
-
),
|
|
1296
|
+
...OPTIONAL_HTTP_METHODS.filter((m) => options.extraHttpMethods?.includes(m)),
|
|
1307
1297
|
];
|
|
1308
1298
|
|
|
1309
1299
|
// Error class names and the service name are reserved up front so schema
|
|
@@ -1343,11 +1333,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1343
1333
|
// No id: everything comes from the route, including whether a
|
|
1344
1334
|
// GET on a collection route is `list` or `get`.
|
|
1345
1335
|
named = pathToVerbNoun(idCtx, {
|
|
1346
|
-
returnsCollection: responseIsCollection(
|
|
1347
|
-
ctx,
|
|
1348
|
-
op.responses,
|
|
1349
|
-
successStatuses,
|
|
1350
|
-
),
|
|
1336
|
+
returnsCollection: responseIsCollection(ctx, op.responses, successStatuses),
|
|
1351
1337
|
});
|
|
1352
1338
|
} else if (isMechanicalOperationId(op.operationId, idCtx)) {
|
|
1353
1339
|
// Method-prefixed and reading the route (`get-feeds`,
|
|
@@ -1383,9 +1369,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1383
1369
|
|
|
1384
1370
|
// ---- URI + labels (sanitize placeholder names to member idents) ----
|
|
1385
1371
|
let uri = rawPath.split(/[?#]/)[0]!;
|
|
1386
|
-
const rawLabels = Array.from(uri.matchAll(/\{([^}]+)\}/g)).map(
|
|
1387
|
-
(m) => m[1]!,
|
|
1388
|
-
);
|
|
1372
|
+
const rawLabels = Array.from(uri.matchAll(/\{([^}]+)\}/g)).map((m) => m[1]!);
|
|
1389
1373
|
const members: Record<string, any> = {};
|
|
1390
1374
|
const addMember = (name: string, member: any): boolean => {
|
|
1391
1375
|
if (name in members) return false;
|
|
@@ -1402,9 +1386,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1402
1386
|
traits: {
|
|
1403
1387
|
"smithy.api#httpLabel": {},
|
|
1404
1388
|
"smithy.api#required": {},
|
|
1405
|
-
...(p?.description
|
|
1406
|
-
? { "smithy.api#documentation": p.description }
|
|
1407
|
-
: {}),
|
|
1389
|
+
...(p?.description ? { "smithy.api#documentation": p.description } : {}),
|
|
1408
1390
|
},
|
|
1409
1391
|
});
|
|
1410
1392
|
}
|
|
@@ -1416,21 +1398,13 @@ export const convertOpenApiToSmithy = (
|
|
|
1416
1398
|
continue;
|
|
1417
1399
|
}
|
|
1418
1400
|
const san = memberIdent(p.name);
|
|
1419
|
-
const conv = convertSchema(
|
|
1420
|
-
ctx,
|
|
1421
|
-
p.schema,
|
|
1422
|
-
`${opName}Request${pascal(p.name)}`,
|
|
1423
|
-
0,
|
|
1424
|
-
"in",
|
|
1425
|
-
);
|
|
1401
|
+
const conv = convertSchema(ctx, p.schema, `${opName}Request${pascal(p.name)}`, 0, "in");
|
|
1426
1402
|
addMember(san, {
|
|
1427
1403
|
target: conv.target,
|
|
1428
1404
|
traits: {
|
|
1429
1405
|
"smithy.api#httpQuery": p.name,
|
|
1430
1406
|
...(p.required ? { "smithy.api#required": {} } : {}),
|
|
1431
|
-
...(p.description
|
|
1432
|
-
? { "smithy.api#documentation": p.description }
|
|
1433
|
-
: {}),
|
|
1407
|
+
...(p.description ? { "smithy.api#documentation": p.description } : {}),
|
|
1434
1408
|
},
|
|
1435
1409
|
});
|
|
1436
1410
|
}
|
|
@@ -1439,13 +1413,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1439
1413
|
if (options.headerParams) {
|
|
1440
1414
|
for (const p of params) {
|
|
1441
1415
|
if (p.in !== "header") continue;
|
|
1442
|
-
const conv = convertSchema(
|
|
1443
|
-
ctx,
|
|
1444
|
-
p.schema,
|
|
1445
|
-
`${opName}Request${pascal(p.name)}`,
|
|
1446
|
-
0,
|
|
1447
|
-
"in",
|
|
1448
|
-
);
|
|
1416
|
+
const conv = convertSchema(ctx, p.schema, `${opName}Request${pascal(p.name)}`, 0, "in");
|
|
1449
1417
|
addMember(headerMemberName(p.name), {
|
|
1450
1418
|
target: conv.target,
|
|
1451
1419
|
traits: {
|
|
@@ -1453,9 +1421,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1453
1421
|
// a normal identifier.
|
|
1454
1422
|
"smithy.api#httpHeader": p.name,
|
|
1455
1423
|
...(p.required ? { "smithy.api#required": {} } : {}),
|
|
1456
|
-
...(p.description
|
|
1457
|
-
? { "smithy.api#documentation": p.description }
|
|
1458
|
-
: {}),
|
|
1424
|
+
...(p.description ? { "smithy.api#documentation": p.description } : {}),
|
|
1459
1425
|
},
|
|
1460
1426
|
});
|
|
1461
1427
|
}
|
|
@@ -1470,9 +1436,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1470
1436
|
bodySchema = bodyParam?.schema;
|
|
1471
1437
|
bodyRequired = bodyParam?.required === true;
|
|
1472
1438
|
} else if (op.requestBody) {
|
|
1473
|
-
const rb = op.requestBody.$ref
|
|
1474
|
-
? resolvePointer(doc, op.requestBody.$ref)
|
|
1475
|
-
: op.requestBody;
|
|
1439
|
+
const rb = op.requestBody.$ref ? resolvePointer(doc, op.requestBody.$ref) : op.requestBody;
|
|
1476
1440
|
bodyRequired = rb?.required === true;
|
|
1477
1441
|
const content = rb?.content ?? {};
|
|
1478
1442
|
if (content["application/json"]) {
|
|
@@ -1507,13 +1471,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1507
1471
|
// runtime's unknown-key passthrough is the escape hatch, and an
|
|
1508
1472
|
// opaque `body: unknown` payload member would swallow the typed
|
|
1509
1473
|
// surface.
|
|
1510
|
-
const conv = convertSchema(
|
|
1511
|
-
ctx,
|
|
1512
|
-
bodySchema,
|
|
1513
|
-
`${opName}RequestBody`,
|
|
1514
|
-
0,
|
|
1515
|
-
"in",
|
|
1516
|
-
);
|
|
1474
|
+
const conv = convertSchema(ctx, bodySchema, `${opName}RequestBody`, 0, "in");
|
|
1517
1475
|
if (conv.target !== PRELUDE.Document) {
|
|
1518
1476
|
addMember("body", {
|
|
1519
1477
|
target: conv.target,
|
|
@@ -1562,13 +1520,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1562
1520
|
isNameable(ctx, resolved);
|
|
1563
1521
|
if (isPlainRef) {
|
|
1564
1522
|
// Reuse the named component shape as the output directly.
|
|
1565
|
-
outputTarget = convertSchema(
|
|
1566
|
-
ctx,
|
|
1567
|
-
respSchema,
|
|
1568
|
-
opName,
|
|
1569
|
-
0,
|
|
1570
|
-
"out",
|
|
1571
|
-
).target;
|
|
1523
|
+
outputTarget = convertSchema(ctx, respSchema, opName, 0, "out").target;
|
|
1572
1524
|
} else {
|
|
1573
1525
|
outputTarget = addShape(ctx, `${opName}Response`, {
|
|
1574
1526
|
type: "structure",
|
|
@@ -1587,13 +1539,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1587
1539
|
// Non-flattenable response (bare array/scalar/map/union, or an
|
|
1588
1540
|
// opaque object) → wrapper whose sole TYPED member IS the payload;
|
|
1589
1541
|
// the SdkSpec's rootPipe collapses the wrapper.
|
|
1590
|
-
const conv = convertSchema(
|
|
1591
|
-
ctx,
|
|
1592
|
-
respSchema,
|
|
1593
|
-
`${opName}ResponseBody`,
|
|
1594
|
-
0,
|
|
1595
|
-
"out",
|
|
1596
|
-
);
|
|
1542
|
+
const conv = convertSchema(ctx, respSchema, `${opName}ResponseBody`, 0, "out");
|
|
1597
1543
|
if (conv.target !== PRELUDE.Document || deref(ctx, respSchema)) {
|
|
1598
1544
|
outputTarget = addShape(ctx, `${opName}Response`, {
|
|
1599
1545
|
type: "structure",
|
|
@@ -1672,7 +1618,7 @@ export const convertOpenApiToSmithy = (
|
|
|
1672
1618
|
? {
|
|
1673
1619
|
...base,
|
|
1674
1620
|
...override,
|
|
1675
|
-
traits: { ...base.traits, ...
|
|
1621
|
+
traits: { ...base.traits, ...override.traits },
|
|
1676
1622
|
}
|
|
1677
1623
|
: base;
|
|
1678
1624
|
}
|
|
@@ -1681,14 +1627,11 @@ export const convertOpenApiToSmithy = (
|
|
|
1681
1627
|
ctx.shapes[`${ctx.ns}#${serviceName}`] = {
|
|
1682
1628
|
type: "service",
|
|
1683
1629
|
version:
|
|
1684
|
-
options.serviceVersion ??
|
|
1685
|
-
(typeof doc.info?.version === "string" ? doc.info.version : "1.0"),
|
|
1630
|
+
options.serviceVersion ?? (typeof doc.info?.version === "string" ? doc.info.version : "1.0"),
|
|
1686
1631
|
operations: serviceOps,
|
|
1687
1632
|
traits: {
|
|
1688
1633
|
"smithy.api#title":
|
|
1689
|
-
typeof doc.info?.title === "string"
|
|
1690
|
-
? doc.info.title
|
|
1691
|
-
: options.serviceName,
|
|
1634
|
+
typeof doc.info?.title === "string" ? doc.info.title : options.serviceName,
|
|
1692
1635
|
...(typeof doc.info?.description === "string"
|
|
1693
1636
|
? {
|
|
1694
1637
|
"smithy.api#documentation": trimDescription(doc.info.description),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { ShapeMap } from "./graph.ts";
|
|
1
2
|
/**
|
|
2
3
|
* Operation-level smithy helpers for the SDK generators (dev-time only).
|
|
3
4
|
*/
|
|
4
5
|
import { local } from "./naming.ts";
|
|
5
|
-
import type { ShapeMap } from "./graph.ts";
|
|
6
6
|
|
|
7
7
|
export interface OpEntry {
|
|
8
8
|
id: string;
|
|
@@ -57,10 +57,7 @@ export const ensureNamedIo = (
|
|
|
57
57
|
* Every error shape id referenced by the operations' `errors` lists —
|
|
58
58
|
* deduplicated, existing in the model, sorted by local name.
|
|
59
59
|
*/
|
|
60
|
-
export const collectOpErrorIds = (
|
|
61
|
-
operations: readonly OpEntry[],
|
|
62
|
-
shapes: ShapeMap,
|
|
63
|
-
): string[] => {
|
|
60
|
+
export const collectOpErrorIds = (operations: readonly OpEntry[], shapes: ShapeMap): string[] => {
|
|
64
61
|
const errorIds: string[] = [];
|
|
65
62
|
const seen = new Set<string>();
|
|
66
63
|
for (const op of operations) {
|