@aws/nx-plugin 1.0.0-rc.31 → 1.0.0-rc.33
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/LICENSE-THIRD-PARTY +72 -70
- package/package.json +5 -5
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
- package/src/infra/app/files/app/src/main.ts.template +1 -1
- package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
- package/src/infra/app/generator.js +3 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +64 -3
- package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +280 -0
- package/src/open-api/ts-client/files/client.gen.ts.template +37 -2
- package/src/open-api/ts-client/generator.js +5 -1
- package/src/open-api/ts-client/generator.js.map +1 -1
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
- package/src/open-api/ts-hooks/generator.js +5 -1
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/open-api/utils/normalise.js +13 -6
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/open-api/utils/parser.js +12 -1
- package/src/open-api/utils/parser.js.map +1 -1
- package/src/open-api/utils/types.d.ts +4 -1
- package/src/open-api/utils/types.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +5 -2
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.js.map +1 -1
- package/src/preset/schema.d.ts +2 -0
- package/src/preset/schema.json +6 -0
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +426 -18
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +283 -11
- package/src/smithy/ts/api/files/handler.ts.template +2 -2
- package/src/smithy/ts/api/files/local-server.ts.template +2 -2
- package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
- package/src/smithy/ts/api/files/service.ts.template +3 -3
- package/src/smithy/ts/api/generator.js +3 -1
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +426 -18
- package/src/trpc/backend/files/src/client/index.ts.template +1 -1
- package/src/trpc/backend/files/src/handler.ts.template +1 -1
- package/src/trpc/backend/files/src/index.ts.template +5 -5
- package/src/trpc/backend/files/src/init.ts.template +1 -1
- package/src/trpc/backend/files/src/local-server.ts.template +1 -1
- package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
- package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
- package/src/trpc/backend/files/src/router.ts.template +2 -2
- package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
- package/src/trpc/backend/generator.js +3 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
- package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/a2a-connection/generator.js +3 -1
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/a2a/index.ts.template +1 -1
- package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
- package/src/ts/agent/files/http/client.ts.template +2 -2
- package/src/ts/agent/files/http/index.ts.template +2 -2
- package/src/ts/agent/files/http/router.ts.template +3 -3
- package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/gateway-connection/generator.js +3 -1
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +5 -2
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/mcp-connection/generator.js +3 -1
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
- package/src/ts/astro-docs/generator.js +2 -0
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/dynamodb/files/src/client.ts.template +5 -2
- package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
- package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
- package/src/ts/dynamodb/files/src/index.ts.template +2 -2
- package/src/ts/dynamodb/generator.js +3 -1
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/lib/generator.js +7 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +19 -4
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/types.d.ts +6 -0
- package/src/ts/lib/types.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -31
- package/src/ts/mcp-server/generator.js +11 -22
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
- package/src/ts/nx-generator/generator.js +5 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
- package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
- package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
- package/src/ts/nx-plugin/generator.js +3 -1
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.js +7 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
- package/src/ts/rdb/files/src/index.ts.template +1 -1
- package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
- package/src/ts/rdb/files/src/prisma.ts.template +7 -4
- package/src/ts/rdb/generator.js +3 -1
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
- package/src/utils/agent-chat/agent-chat.js +3 -1
- package/src/utils/agent-chat/agent-chat.js.map +1 -1
- package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-connection/agent-connection.js +4 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
- package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
- package/src/utils/api-constructs/api-constructs.js +8 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
- package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
- package/src/utils/ast.js +16 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/commands.d.ts +1 -1
- package/src/utils/commands.js +4 -1
- package/src/utils/commands.js.map +1 -1
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
- package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
- package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
- package/src/utils/files/common/constructs/src/index.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
- package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
- package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
- package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
- package/src/utils/function-constructs/function-constructs.js +3 -1
- package/src/utils/function-constructs/function-constructs.js.map +1 -1
- package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
- package/src/utils/identity-constructs/identity-constructs.js +5 -1
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
- package/src/utils/module-format.d.ts +28 -0
- package/src/utils/module-format.js +28 -0
- package/src/utils/module-format.js.map +1 -0
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
- package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
- package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/shared-constructs.js +3 -1
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-infra-config.js +3 -1
- package/src/utils/shared-infra-config.js.map +1 -1
- package/src/utils/shared-infra-scripts.js +3 -1
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.js +3 -1
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.d.ts +2 -0
- package/src/utils/test.js +7 -1
- package/src/utils/test.js.map +1 -1
- package/src/utils/versions.d.ts +61 -61
- package/src/utils/versions.js +59 -59
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
- package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
- package/src/utils/website-constructs/website-constructs.js +9 -2
- package/src/utils/website-constructs/website-constructs.js.map +1 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`openApiTsClientGenerator - multipart/form-data > should match the generated client snapshot > client.gen.ts 1`] = `
|
|
4
|
+
"import type {
|
|
5
|
+
Upload200Response,
|
|
6
|
+
UploadRequestContent,
|
|
7
|
+
UploadRequest,
|
|
8
|
+
} from './types.gen.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Utility for serialisation and deserialisation of API types.
|
|
12
|
+
*/
|
|
13
|
+
export class $IO {
|
|
14
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
15
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
16
|
+
|
|
17
|
+
public static Upload200Response = {
|
|
18
|
+
toJson: (model: Upload200Response): any => {
|
|
19
|
+
if (model === undefined || model === null) {
|
|
20
|
+
return model;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...(model.size === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: {
|
|
26
|
+
size: model.size,
|
|
27
|
+
}),
|
|
28
|
+
...(model.note === undefined
|
|
29
|
+
? {}
|
|
30
|
+
: {
|
|
31
|
+
note: model.note,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
fromJson: (json: any): Upload200Response => {
|
|
36
|
+
if (json === undefined || json === null) {
|
|
37
|
+
return json;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...(json['size'] === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: {
|
|
43
|
+
size: json['size'],
|
|
44
|
+
}),
|
|
45
|
+
...(json['note'] === undefined
|
|
46
|
+
? {}
|
|
47
|
+
: {
|
|
48
|
+
note: json['note'],
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
public static UploadRequestContent = {
|
|
55
|
+
toJson: (model: UploadRequestContent): any => {
|
|
56
|
+
if (model === undefined || model === null) {
|
|
57
|
+
return model;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...(model.file === undefined
|
|
61
|
+
? {}
|
|
62
|
+
: {
|
|
63
|
+
file: model.file,
|
|
64
|
+
}),
|
|
65
|
+
...(model.note === undefined
|
|
66
|
+
? {}
|
|
67
|
+
: {
|
|
68
|
+
note: model.note,
|
|
69
|
+
}),
|
|
70
|
+
...(model.tags === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: {
|
|
73
|
+
tags: model.tags,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
fromJson: (json: any): UploadRequestContent => {
|
|
78
|
+
if (json === undefined || json === null) {
|
|
79
|
+
return json;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
file: json['file'],
|
|
83
|
+
...(json['note'] === undefined
|
|
84
|
+
? {}
|
|
85
|
+
: {
|
|
86
|
+
note: json['note'],
|
|
87
|
+
}),
|
|
88
|
+
...(json['tags'] === undefined
|
|
89
|
+
? {}
|
|
90
|
+
: {
|
|
91
|
+
tags: json['tags'],
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Client configuration for TestApi
|
|
100
|
+
*/
|
|
101
|
+
export interface TestApiConfig {
|
|
102
|
+
/**
|
|
103
|
+
* Base URL for the API
|
|
104
|
+
*/
|
|
105
|
+
url: string;
|
|
106
|
+
/**
|
|
107
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
108
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
109
|
+
*/
|
|
110
|
+
fetch?: typeof fetch;
|
|
111
|
+
/**
|
|
112
|
+
* Additional configuration
|
|
113
|
+
*/
|
|
114
|
+
options?: {
|
|
115
|
+
/**
|
|
116
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
117
|
+
* the request in the OpenAPI specification.
|
|
118
|
+
* Set this to false to omit this header.
|
|
119
|
+
*/
|
|
120
|
+
omitContentTypeHeader?: boolean;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* API Client for TestApi
|
|
126
|
+
*/
|
|
127
|
+
export class TestApi {
|
|
128
|
+
private $config: TestApiConfig;
|
|
129
|
+
|
|
130
|
+
constructor(config: TestApiConfig) {
|
|
131
|
+
this.$config = config;
|
|
132
|
+
|
|
133
|
+
this.upload = this.upload.bind(this);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
137
|
+
csv: ',',
|
|
138
|
+
ssv: ' ',
|
|
139
|
+
pipes: '|',
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
143
|
+
if (value === undefined || value === null) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
if (typeof value !== 'object') {
|
|
147
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
148
|
+
}
|
|
149
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
150
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
private $url = (
|
|
155
|
+
path: string,
|
|
156
|
+
pathParameters: { [key: string]: any },
|
|
157
|
+
queryParameters: { [key: string]: any },
|
|
158
|
+
collectionFormats?: {
|
|
159
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
160
|
+
},
|
|
161
|
+
): string => {
|
|
162
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
163
|
+
? this.$config.url.slice(0, -1)
|
|
164
|
+
: this.$config.url;
|
|
165
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
166
|
+
(withParams, [key, value]) =>
|
|
167
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
168
|
+
path,
|
|
169
|
+
);
|
|
170
|
+
const queryString = Object.entries(queryParameters)
|
|
171
|
+
.flatMap(([key, value]) => {
|
|
172
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
173
|
+
return value.map(
|
|
174
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
179
|
+
value !== null &&
|
|
180
|
+
typeof value === 'object'
|
|
181
|
+
) {
|
|
182
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
183
|
+
}
|
|
184
|
+
const delimiter =
|
|
185
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
186
|
+
return [
|
|
187
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
188
|
+
];
|
|
189
|
+
})
|
|
190
|
+
.join('&');
|
|
191
|
+
return (
|
|
192
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
private $headers = (
|
|
197
|
+
headerParameters: { [key: string]: any },
|
|
198
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
199
|
+
): [string, string][] => {
|
|
200
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
201
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
202
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
203
|
+
}
|
|
204
|
+
const delimiter =
|
|
205
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
206
|
+
return [
|
|
207
|
+
[
|
|
208
|
+
key,
|
|
209
|
+
Array.isArray(value)
|
|
210
|
+
? value.map(String).join(delimiter)
|
|
211
|
+
: String(value),
|
|
212
|
+
],
|
|
213
|
+
];
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
private $formData = (model: { [key: string]: any }): FormData => {
|
|
218
|
+
const formData = new FormData();
|
|
219
|
+
const append = (key: string, value: any): void => {
|
|
220
|
+
if (value === undefined || value === null) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (value instanceof Blob || typeof value === 'string') {
|
|
224
|
+
formData.append(key, value);
|
|
225
|
+
} else if (Array.isArray(value)) {
|
|
226
|
+
value.forEach((v) => append(key, v));
|
|
227
|
+
} else if (typeof value === 'object') {
|
|
228
|
+
formData.append(key, JSON.stringify(value));
|
|
229
|
+
} else {
|
|
230
|
+
formData.append(key, String(value));
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
Object.entries(model).forEach(([key, value]) => append(key, value));
|
|
234
|
+
return formData;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
private $fetch: typeof fetch = (...args) =>
|
|
238
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
239
|
+
|
|
240
|
+
public async upload(input: UploadRequest): Promise<Upload200Response> {
|
|
241
|
+
const pathParameters: { [key: string]: any } = {};
|
|
242
|
+
const queryParameters: { [key: string]: any } = {};
|
|
243
|
+
const headerParameters: { [key: string]: any } = {};
|
|
244
|
+
const body = this.$formData($IO.UploadRequestContent.toJson(input));
|
|
245
|
+
|
|
246
|
+
const response = await this.$fetch(
|
|
247
|
+
this.$url('/upload', pathParameters, queryParameters),
|
|
248
|
+
{
|
|
249
|
+
headers: this.$headers(headerParameters),
|
|
250
|
+
method: 'POST',
|
|
251
|
+
body,
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
if (response.status === 200) {
|
|
256
|
+
return $IO.Upload200Response.fromJson(await response.json());
|
|
257
|
+
}
|
|
258
|
+
throw new Error(
|
|
259
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
"
|
|
264
|
+
`;
|
|
265
|
+
|
|
266
|
+
exports[`openApiTsClientGenerator - multipart/form-data > should match the generated client snapshot > types.gen.ts 1`] = `
|
|
267
|
+
"export type Upload200Response = {
|
|
268
|
+
size?: number;
|
|
269
|
+
note?: string;
|
|
270
|
+
};
|
|
271
|
+
export type UploadRequestContent = {
|
|
272
|
+
file: Blob;
|
|
273
|
+
note?: string;
|
|
274
|
+
tags?: Array<string>;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export type UploadRequest = UploadRequestContent;
|
|
278
|
+
export type UploadError = never;
|
|
279
|
+
"
|
|
280
|
+
`;
|
|
@@ -29,6 +29,13 @@ const composedMarshaller = (property, method) =>
|
|
|
29
29
|
property.export === 'reference' && discriminatorBaseNames.has(property.type)
|
|
30
30
|
? `$IO.${property.typescriptType}.$${method}Base`
|
|
31
31
|
: `$IO.${property.typescriptType}.${method}`;
|
|
32
|
+
// The single wire media type chosen for an operation's request body, if any.
|
|
33
|
+
const bodyMediaTypeOf = (op) => {
|
|
34
|
+
if (!op.parametersBody || !op.parametersBody.mediaTypes) return undefined;
|
|
35
|
+
const mediaTypes = Array.isArray(op.parametersBody.mediaTypes) ? op.parametersBody.mediaTypes : [op.parametersBody.mediaTypes];
|
|
36
|
+
return mediaTypes.find(mt => mt === 'application/json' || mt.endsWith('+json')) || mediaTypes[0];
|
|
37
|
+
};
|
|
38
|
+
const hasMultipartBody = allOperations.some(op => bodyMediaTypeOf(op) === 'multipart/form-data');
|
|
32
39
|
_%>
|
|
33
40
|
<%_ if ((models.length + allOperations.filter(p => p.parameters.length > 0).length) > 0) { _%>
|
|
34
41
|
import type {
|
|
@@ -38,7 +45,7 @@ import type {
|
|
|
38
45
|
<%_ allOperations.filter(p => p.parameters.length > 0).forEach((op) => { _%>
|
|
39
46
|
<%- op.requestTypeName %>,
|
|
40
47
|
<%_ }); _%>
|
|
41
|
-
} from './types.gen
|
|
48
|
+
} from './types.gen<% if (esm) { %>.js<% } %>';
|
|
42
49
|
<%_ } _%>
|
|
43
50
|
<%_
|
|
44
51
|
// Nested arrays of primitives (besides dates) don't need to have .map(...) called to convert them as the base case will be a noop
|
|
@@ -478,6 +485,28 @@ export class <%- className %> {
|
|
|
478
485
|
});
|
|
479
486
|
};
|
|
480
487
|
|
|
488
|
+
<%_ if (hasMultipartBody) { _%>
|
|
489
|
+
private $formData = (model: { [key: string]: any }): FormData => {
|
|
490
|
+
const formData = new FormData();
|
|
491
|
+
const append = (key: string, value: any): void => {
|
|
492
|
+
if (value === undefined || value === null) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (value instanceof Blob || typeof value === 'string') {
|
|
496
|
+
formData.append(key, value);
|
|
497
|
+
} else if (Array.isArray(value)) {
|
|
498
|
+
value.forEach((v) => append(key, v));
|
|
499
|
+
} else if (typeof value === 'object') {
|
|
500
|
+
formData.append(key, JSON.stringify(value));
|
|
501
|
+
} else {
|
|
502
|
+
formData.append(key, String(value));
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
Object.entries(model).forEach(([key, value]) => append(key, value));
|
|
506
|
+
return formData;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
<%_ } _%>
|
|
481
510
|
private $fetch: typeof fetch = (...args) => (this.$config.fetch ?? fetch)(...args);
|
|
482
511
|
<%_ allOperations.forEach((op) => { _%>
|
|
483
512
|
<%_ const hasTag = op.tags && op.tags.length > 0; _%>
|
|
@@ -538,7 +567,13 @@ export class <%- className %> {
|
|
|
538
567
|
} as const;
|
|
539
568
|
<%_ } _%>
|
|
540
569
|
<%_ if (op.parametersBody) { _%>
|
|
541
|
-
<%_ if (
|
|
570
|
+
<%_ if (bodyMediaTypeOf(op) === 'multipart/form-data') { _%>
|
|
571
|
+
<%_ /* A multipart body is sent as FormData: Blob fields stream as file
|
|
572
|
+
parts, primitives serialise to strings, and fetch computes the
|
|
573
|
+
boundary itself (so the Content-Type header is intentionally unset
|
|
574
|
+
above). */ _%>
|
|
575
|
+
const body = <% if (!op.parametersBody.isRequired) { %>input === undefined ? undefined : <% } %>this.$formData(<%- op.explicitRequestBodyParameter ? `$IO.${op.operationIdPascalCase}RequestBodyParameters.toJson(input).${op.explicitRequestBodyParameter.prop}` : renderToJsonValue(op.parametersBody, 'input') %>);
|
|
576
|
+
<%_ } else if (op.parametersBody.isPrimitive && ['number', 'boolean', 'string'].includes(op.parametersBody.type) && !['array', 'dictionary'].includes(op.parametersBody.export) && !["date", "date-time"].includes(op.parametersBody.format)) { _%>
|
|
542
577
|
const body = <% if (!op.parametersBody.isRequired) { %>input === undefined ? undefined : <% } %>String(input<%- op.explicitRequestBodyParameter ? `.${op.explicitRequestBodyParameter.typescriptName}` : '' %>);
|
|
543
578
|
<%_ } else if (op.parametersBody.isPrimitive && ["date", "date-time"].includes(op.parametersBody.format)) { _%>
|
|
544
579
|
const body = <%- renderToJsonDateValue('input', op.parametersBody.format) %>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/ import { generateFiles } from "@nx/devkit";
|
|
5
5
|
import * as path from "path";
|
|
6
6
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
7
|
+
import { esmVars } from "../../utils/module-format.js";
|
|
7
8
|
import { buildOpenApiCodeGenData } from "../utils/codegen-data.js";
|
|
8
9
|
import { parseOpenApiSpec } from "../utils/parse.js";
|
|
9
10
|
/**
|
|
@@ -22,7 +23,10 @@ import { parseOpenApiSpec } from "../utils/parse.js";
|
|
|
22
23
|
/**
|
|
23
24
|
* Generate an OpenAPI typescript client in the target directory
|
|
24
25
|
*/ export const generateOpenApiTsClient = (tree, data, outputPath)=>{
|
|
25
|
-
generateFiles(tree, path.join(import.meta.dirname, 'files'), outputPath,
|
|
26
|
+
generateFiles(tree, path.join(import.meta.dirname, 'files'), outputPath, {
|
|
27
|
+
...data,
|
|
28
|
+
...esmVars(tree)
|
|
29
|
+
});
|
|
26
30
|
};
|
|
27
31
|
export default openApiTsClientGenerator;
|
|
28
32
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/ts-client/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { generateFiles, type Tree } from '@nx/devkit';\nimport * as path from 'path';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { buildOpenApiCodeGenData } from '../utils/codegen-data';\nimport type { CodeGenData } from '../utils/codegen-data/types';\nimport { parseOpenApiSpec } from '../utils/parse';\nimport type { OpenApiTsClientGeneratorSchema } from './schema';\n\n/**\n * Generates typescript client from an openapi spec\n */\nexport const openApiTsClientGenerator = async (\n tree: Tree,\n options: OpenApiTsClientGeneratorSchema,\n) => {\n const data = await buildOpenApiCodeGenerationData(\n tree,\n options.openApiSpecPath,\n );\n\n generateOpenApiTsClient(tree, data, options.outputPath);\n\n await formatFilesInSubtree(tree);\n};\n\n/**\n * Build a data structure which can be used to generate code from OpenAPI\n */\nexport const buildOpenApiCodeGenerationData = async (\n tree: Tree,\n specPath: string,\n) => {\n const spec = await parseOpenApiSpec(tree, specPath);\n return buildOpenApiCodeGenData(spec);\n};\n\n/**\n * Generate an OpenAPI typescript client in the target directory\n */\nexport const generateOpenApiTsClient = (\n tree: Tree,\n data: CodeGenData,\n outputPath: string,\n) => {\n generateFiles(\n tree,\n path.join(import.meta.dirname, 'files'),\n outputPath,\n data,\n );\n};\n\nexport default openApiTsClientGenerator;\n"],"names":["generateFiles","path","formatFilesInSubtree","buildOpenApiCodeGenData","parseOpenApiSpec","openApiTsClientGenerator","tree","options","data","buildOpenApiCodeGenerationData","openApiSpecPath","generateOpenApiTsClient","outputPath","specPath","spec","join","dirname"],"mappings":"AAAA;;;CAGC,GACD,SAASA,aAAa,QAAmB,aAAa;AACtD,YAAYC,UAAU,OAAO;AAC7B,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,uBAAuB,QAAQ,2BAAwB;AAEhE,SAASC,gBAAgB,QAAQ,oBAAiB;AAGlD;;CAEC,GACD,OAAO,MAAMC,2BAA2B,OACtCC,MACAC;IAEA,MAAMC,OAAO,MAAMC,+BACjBH,MACAC,QAAQG,eAAe;IAGzBC,wBAAwBL,MAAME,MAAMD,QAAQK,UAAU;IAEtD,
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/ts-client/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { generateFiles, type Tree } from '@nx/devkit';\nimport * as path from 'path';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { esmVars } from '../../utils/module-format';\nimport { buildOpenApiCodeGenData } from '../utils/codegen-data';\nimport type { CodeGenData } from '../utils/codegen-data/types';\nimport { parseOpenApiSpec } from '../utils/parse';\nimport type { OpenApiTsClientGeneratorSchema } from './schema';\n\n/**\n * Generates typescript client from an openapi spec\n */\nexport const openApiTsClientGenerator = async (\n tree: Tree,\n options: OpenApiTsClientGeneratorSchema,\n) => {\n const data = await buildOpenApiCodeGenerationData(\n tree,\n options.openApiSpecPath,\n );\n\n generateOpenApiTsClient(tree, data, options.outputPath);\n\n await formatFilesInSubtree(tree);\n};\n\n/**\n * Build a data structure which can be used to generate code from OpenAPI\n */\nexport const buildOpenApiCodeGenerationData = async (\n tree: Tree,\n specPath: string,\n) => {\n const spec = await parseOpenApiSpec(tree, specPath);\n return buildOpenApiCodeGenData(spec);\n};\n\n/**\n * Generate an OpenAPI typescript client in the target directory\n */\nexport const generateOpenApiTsClient = (\n tree: Tree,\n data: CodeGenData,\n outputPath: string,\n) => {\n generateFiles(\n tree,\n path.join(import.meta.dirname, 'files'),\n outputPath,\n { ...data, ...esmVars(tree) },\n );\n};\n\nexport default openApiTsClientGenerator;\n"],"names":["generateFiles","path","formatFilesInSubtree","esmVars","buildOpenApiCodeGenData","parseOpenApiSpec","openApiTsClientGenerator","tree","options","data","buildOpenApiCodeGenerationData","openApiSpecPath","generateOpenApiTsClient","outputPath","specPath","spec","join","dirname"],"mappings":"AAAA;;;CAGC,GACD,SAASA,aAAa,QAAmB,aAAa;AACtD,YAAYC,UAAU,OAAO;AAC7B,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,uBAAuB,QAAQ,2BAAwB;AAEhE,SAASC,gBAAgB,QAAQ,oBAAiB;AAGlD;;CAEC,GACD,OAAO,MAAMC,2BAA2B,OACtCC,MACAC;IAEA,MAAMC,OAAO,MAAMC,+BACjBH,MACAC,QAAQG,eAAe;IAGzBC,wBAAwBL,MAAME,MAAMD,QAAQK,UAAU;IAEtD,MAAMX,qBAAqBK;AAC7B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMG,iCAAiC,OAC5CH,MACAO;IAEA,MAAMC,OAAO,MAAMV,iBAAiBE,MAAMO;IAC1C,OAAOV,wBAAwBW;AACjC,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMH,0BAA0B,CACrCL,MACAE,MACAI;IAEAb,cACEO,MACAN,KAAKe,IAAI,CAAC,YAAYC,OAAO,EAAE,UAC/BJ,YACA;QAAE,GAAGJ,IAAI;QAAE,GAAGN,QAAQI,KAAK;IAAC;AAEhC,EAAE;AAEF,eAAeD,yBAAyB"}
|
|
@@ -41,9 +41,9 @@ import type {
|
|
|
41
41
|
<%_ uniq(allOperations.flatMap((op) => op.isInfiniteQuery && op.infiniteQueryCursorProperty && modelsByName[op.infiniteQueryCursorProperty.type] ? [modelsByName[op.infiniteQueryCursorProperty.type].typescriptType] : [])).forEach((cursorTypeModel) => { _%>
|
|
42
42
|
<%- cursorTypeModel %>,
|
|
43
43
|
<%_ }); _%>
|
|
44
|
-
} from './types.gen
|
|
44
|
+
} from './types.gen<% if (esm) { %>.js<% } %>';
|
|
45
45
|
<%_ } _%>
|
|
46
|
-
import { <%- className %> } from './client.gen
|
|
46
|
+
import { <%- className %> } from './client.gen<% if (esm) { %>.js<% } %>';
|
|
47
47
|
|
|
48
48
|
export interface <%- className %>OptionsProxyConfig {
|
|
49
49
|
client: <%- className %>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/ import { generateFiles } from "@nx/devkit";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
7
|
+
import { esmVars } from "../../utils/module-format.js";
|
|
7
8
|
import { buildOpenApiCodeGenerationData, generateOpenApiTsClient } from "../ts-client/generator.js";
|
|
8
9
|
/**
|
|
9
10
|
* Generates typescript hooks from an openapi spec
|
|
@@ -16,7 +17,10 @@ import { buildOpenApiCodeGenerationData, generateOpenApiTsClient } from "../ts-c
|
|
|
16
17
|
/**
|
|
17
18
|
* Generate OpenAPI typescript hooks in the target directory
|
|
18
19
|
*/ export const generateOpenApiTsHooks = (tree, data, outputPath)=>{
|
|
19
|
-
generateFiles(tree, path.join(import.meta.dirname, 'files'), outputPath,
|
|
20
|
+
generateFiles(tree, path.join(import.meta.dirname, 'files'), outputPath, {
|
|
21
|
+
...data,
|
|
22
|
+
...esmVars(tree)
|
|
23
|
+
});
|
|
20
24
|
};
|
|
21
25
|
export default openApiTsHooksGenerator;
|
|
22
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/ts-hooks/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { generateFiles, type Tree } from '@nx/devkit';\nimport path from 'path';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport {\n buildOpenApiCodeGenerationData,\n generateOpenApiTsClient,\n} from '../ts-client/generator';\nimport type { CodeGenData } from '../utils/codegen-data/types';\nimport type { OpenApiTsHooksGeneratorSchema } from './schema';\n\n/**\n * Generates typescript hooks from an openapi spec\n */\nexport const openApiTsHooksGenerator = async (\n tree: Tree,\n options: OpenApiTsHooksGeneratorSchema,\n) => {\n const data = await buildOpenApiCodeGenerationData(\n tree,\n options.openApiSpecPath,\n );\n\n generateOpenApiTsClient(tree, data, options.outputPath);\n generateOpenApiTsHooks(tree, data, options.outputPath);\n\n await formatFilesInSubtree(tree);\n};\n\n/**\n * Generate OpenAPI typescript hooks in the target directory\n */\nexport const generateOpenApiTsHooks = (\n tree: Tree,\n data: CodeGenData,\n outputPath: string,\n) => {\n generateFiles(\n tree,\n path.join(import.meta.dirname, 'files'),\n outputPath,\n data,\n );\n};\n\nexport default openApiTsHooksGenerator;\n"],"names":["generateFiles","path","formatFilesInSubtree","buildOpenApiCodeGenerationData","generateOpenApiTsClient","openApiTsHooksGenerator","tree","options","data","openApiSpecPath","outputPath","generateOpenApiTsHooks","join","dirname"],"mappings":"AAAA;;;CAGC,GACD,SAASA,aAAa,QAAmB,aAAa;AACtD,OAAOC,UAAU,OAAO;AACxB,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SACEC,8BAA8B,EAC9BC,uBAAuB,QAClB,4BAAyB;AAIhC;;CAEC,GACD,OAAO,MAAMC,0BAA0B,OACrCC,MACAC;IAEA,MAAMC,OAAO,MAAML,+BACjBG,MACAC,QAAQE,eAAe;IAGzBL,wBAAwBE,MAAME,MAAMD,QAAQG,UAAU;IACtDC,uBAAuBL,MAAME,MAAMD,QAAQG,UAAU;IAErD,
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/open-api/ts-hooks/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { generateFiles, type Tree } from '@nx/devkit';\nimport path from 'path';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { esmVars } from '../../utils/module-format';\nimport {\n buildOpenApiCodeGenerationData,\n generateOpenApiTsClient,\n} from '../ts-client/generator';\nimport type { CodeGenData } from '../utils/codegen-data/types';\nimport type { OpenApiTsHooksGeneratorSchema } from './schema';\n\n/**\n * Generates typescript hooks from an openapi spec\n */\nexport const openApiTsHooksGenerator = async (\n tree: Tree,\n options: OpenApiTsHooksGeneratorSchema,\n) => {\n const data = await buildOpenApiCodeGenerationData(\n tree,\n options.openApiSpecPath,\n );\n\n generateOpenApiTsClient(tree, data, options.outputPath);\n generateOpenApiTsHooks(tree, data, options.outputPath);\n\n await formatFilesInSubtree(tree);\n};\n\n/**\n * Generate OpenAPI typescript hooks in the target directory\n */\nexport const generateOpenApiTsHooks = (\n tree: Tree,\n data: CodeGenData,\n outputPath: string,\n) => {\n generateFiles(\n tree,\n path.join(import.meta.dirname, 'files'),\n outputPath,\n { ...data, ...esmVars(tree) },\n );\n};\n\nexport default openApiTsHooksGenerator;\n"],"names":["generateFiles","path","formatFilesInSubtree","esmVars","buildOpenApiCodeGenerationData","generateOpenApiTsClient","openApiTsHooksGenerator","tree","options","data","openApiSpecPath","outputPath","generateOpenApiTsHooks","join","dirname"],"mappings":"AAAA;;;CAGC,GACD,SAASA,aAAa,QAAmB,aAAa;AACtD,OAAOC,UAAU,OAAO;AACxB,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SACEC,8BAA8B,EAC9BC,uBAAuB,QAClB,4BAAyB;AAIhC;;CAEC,GACD,OAAO,MAAMC,0BAA0B,OACrCC,MACAC;IAEA,MAAMC,OAAO,MAAML,+BACjBG,MACAC,QAAQE,eAAe;IAGzBL,wBAAwBE,MAAME,MAAMD,QAAQG,UAAU;IACtDC,uBAAuBL,MAAME,MAAMD,QAAQG,UAAU;IAErD,MAAMT,qBAAqBK;AAC7B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMK,yBAAyB,CACpCL,MACAE,MACAE;IAEAX,cACEO,MACAN,KAAKY,IAAI,CAAC,YAAYC,OAAO,EAAE,UAC/BH,YACA;QAAE,GAAGF,IAAI;QAAE,GAAGN,QAAQI,KAAK;IAAC;AAEhC,EAAE;AAEF,eAAeD,wBAAwB"}
|
|
@@ -437,15 +437,22 @@ const hoistInlineObjectSubSchemas = (nameParts, schema, seenModelNameCounts)=>{
|
|
|
437
437
|
}
|
|
438
438
|
if ('requestBody' in operation) {
|
|
439
439
|
const requestBody = resolveIfRef(spec, operation.requestBody);
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
440
|
+
const contentMediaTypes = Object.keys(requestBody?.content ?? {});
|
|
441
|
+
// Hoist the JSON body, falling back to a form-data body (multipart or
|
|
442
|
+
// urlencoded) so an inline form object is fully typed and marshalled
|
|
443
|
+
// rather than left `unknown`.
|
|
444
|
+
const bodyMediaType = preferredJsonMediaType(contentMediaTypes) ?? contentMediaTypes.find((mt)=>[
|
|
445
|
+
'multipart/form-data',
|
|
446
|
+
'application/x-www-form-urlencoded'
|
|
447
|
+
].includes(mt.split(';')[0]));
|
|
448
|
+
const bodyRequestSchema = bodyMediaType ? requestBody.content[bodyMediaType].schema : undefined;
|
|
449
|
+
if (bodyRequestSchema && !isRef(bodyRequestSchema) && ([
|
|
443
450
|
'object',
|
|
444
451
|
'array'
|
|
445
|
-
].includes(
|
|
452
|
+
].includes(bodyRequestSchema.type) || isCompositeSchema(bodyRequestSchema) || bodyRequestSchema?.type === 'string' && bodyRequestSchema.enum)) {
|
|
446
453
|
const schemaName = `${upperFirst(deduplicatedOpId)}RequestContent`;
|
|
447
|
-
spec.components.schemas[schemaName] =
|
|
448
|
-
requestBody.content[
|
|
454
|
+
spec.components.schemas[schemaName] = bodyRequestSchema;
|
|
455
|
+
requestBody.content[bodyMediaType].schema = {
|
|
449
456
|
$ref: `#/components/schemas/${schemaName}`
|
|
450
457
|
};
|
|
451
458
|
}
|