@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.34
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 +75 -86
- package/generators.json +27 -0
- package/package.json +10 -10
- package/src/connection/generator.js +12 -1
- package/src/connection/generator.js.map +1 -1
- package/src/connection/supported-connections.d.ts +10 -1
- package/src/connection/supported-connections.js +13 -0
- package/src/connection/supported-connections.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +21 -21
- 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.complex-types.spec.ts.snap +12 -12
- package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +74 -10
- package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +22 -4
- package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +53 -8
- package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +32 -4
- package/src/open-api/ts-client/__snapshots__/generator.fast-api-gaps.spec.ts.snap +736 -0
- package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +86 -11
- package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +21 -3
- package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +2 -2
- package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +6 -6
- package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2 -2
- package/src/open-api/ts-client/__snapshots__/generator.spec-compliance.spec.ts.snap +1883 -0
- package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +4 -4
- package/src/open-api/ts-client/files/client.gen.ts.template +196 -13
- package/src/open-api/ts-client/files/types.gen.ts.template +2 -0
- package/src/open-api/ts-client/generator.js +27 -2
- 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/codegen-data/languages.js +6 -0
- package/src/open-api/utils/codegen-data/languages.js.map +1 -1
- package/src/open-api/utils/codegen-data/types.d.ts +16 -1
- package/src/open-api/utils/codegen-data/types.js.map +1 -1
- package/src/open-api/utils/codegen-data.js +71 -0
- package/src/open-api/utils/codegen-data.js.map +1 -1
- package/src/open-api/utils/normalise.js +53 -8
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/open-api/utils/parser.js +48 -15
- package/src/open-api/utils/parser.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +5 -3
- 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 +12 -12
- 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/py/rdb/__snapshots__/generator.spec.ts.snap +2038 -0
- package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +104 -0
- package/src/py/rdb/agent-connection/generator.d.ts +10 -0
- package/src/py/rdb/agent-connection/generator.js +46 -0
- package/src/py/rdb/agent-connection/generator.js.map +1 -0
- package/src/py/rdb/agent-connection/schema.d.js +8 -0
- package/src/py/rdb/agent-connection/schema.d.js.map +1 -0
- package/src/py/rdb/agent-connection/schema.d.ts +15 -0
- package/src/py/rdb/agent-connection/schema.json +27 -0
- package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +44 -0
- package/src/py/rdb/fast-api-connection/files/__apiModuleName__/dependencies/__rdbNameSnake__.py.template +14 -0
- package/src/py/rdb/fast-api-connection/generator.d.ts +10 -0
- package/src/py/rdb/fast-api-connection/generator.js +54 -0
- package/src/py/rdb/fast-api-connection/generator.js.map +1 -0
- package/src/py/rdb/fast-api-connection/schema.d.js +8 -0
- package/src/py/rdb/fast-api-connection/schema.d.js.map +1 -0
- package/src/py/rdb/fast-api-connection/schema.d.ts +13 -0
- package/src/py/rdb/fast-api-connection/schema.json +23 -0
- package/src/py/rdb/files/Dockerfile.create-db-user.template +10 -0
- package/src/py/rdb/files/Dockerfile.migration.template +10 -0
- package/src/py/rdb/files/__name__/__init__.py.template +3 -0
- package/src/py/rdb/files/__name__/connection.py.template +55 -0
- package/src/py/rdb/files/__name__/create_db_user_handler.py.template +97 -0
- package/src/py/rdb/files/__name__/migration_handler.py.template +36 -0
- package/src/py/rdb/files/__name__/models/__init__.py.template +3 -0
- package/src/py/rdb/files/__name__/models/example.py.template +8 -0
- package/src/py/rdb/files/__name__/utils.py.template +104 -0
- package/src/py/rdb/files/alembic.ini.template +38 -0
- package/src/py/rdb/files/config.json.template +14 -0
- package/src/py/rdb/files/migrations/env.py.template +80 -0
- package/src/py/rdb/files/migrations/script.py.mako.template +28 -0
- package/src/py/rdb/generator.d.ts +6 -0
- package/src/py/rdb/generator.js +263 -0
- package/src/py/rdb/generator.js.map +1 -0
- package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +101 -0
- package/src/py/rdb/mcp-server-connection/generator.d.ts +10 -0
- package/src/py/rdb/mcp-server-connection/generator.js +46 -0
- package/src/py/rdb/mcp-server-connection/generator.js.map +1 -0
- package/src/py/rdb/mcp-server-connection/schema.d.js +8 -0
- package/src/py/rdb/mcp-server-connection/schema.d.js.map +1 -0
- package/src/py/rdb/mcp-server-connection/schema.d.ts +15 -0
- package/src/py/rdb/mcp-server-connection/schema.json +27 -0
- package/src/py/rdb/schema.d.js +6 -0
- package/src/py/rdb/schema.d.js.map +1 -0
- package/src/py/rdb/schema.d.ts +16 -0
- package/src/py/rdb/schema.json +77 -0
- package/src/py/rdb/utils.d.ts +6 -0
- package/src/py/rdb/utils.js +16 -0
- package/src/py/rdb/utils.js.map +1 -0
- package/src/sdk/py.d.ts +2 -0
- package/src/sdk/py.js +1 -0
- package/src/sdk/py.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
- 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 +12 -12
- 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 -8
- package/src/ts/mcp-server/generator.js +3 -2
- 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 +149 -177
- 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 +7 -4
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/schema.json +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +45 -45
- 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/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 +61 -17
- package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +68 -78
- package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +88 -8
- package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +5 -32
- package/src/utils/rdb-constructs/rdb-constructs.d.ts +11 -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 +12 -22
- 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-rdb-scripts.js +5 -1
- package/src/utils/shared-rdb-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 +73 -69
- package/src/utils/versions.js +71 -67
- 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
- package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +0 -25
|
@@ -0,0 +1,1883 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`openApiTsClientGenerator - spec compliance > should JSON-serialise a content-based query parameter with marshalled dates > client.gen.ts 1`] = `
|
|
4
|
+
"import type {
|
|
5
|
+
ContentParamRequestQueryParameters,
|
|
6
|
+
Filter,
|
|
7
|
+
ContentParamRequest,
|
|
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 ContentParamRequestQueryParameters = {
|
|
18
|
+
toJson: (model: ContentParamRequestQueryParameters): any => {
|
|
19
|
+
if (model === undefined || model === null) {
|
|
20
|
+
return model;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...(model.filter === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: {
|
|
26
|
+
filter: $IO.Filter.toJson(model.filter),
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
fromJson: (json: any): ContentParamRequestQueryParameters => {
|
|
31
|
+
if (json === undefined || json === null) {
|
|
32
|
+
return json;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
filter: $IO.Filter.fromJson(json['filter']),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
public static Filter = {
|
|
41
|
+
toJson: (model: Filter): any => {
|
|
42
|
+
if (model === undefined || model === null) {
|
|
43
|
+
return model;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...(model.field === undefined
|
|
47
|
+
? {}
|
|
48
|
+
: {
|
|
49
|
+
field: model.field,
|
|
50
|
+
}),
|
|
51
|
+
...(model.since === undefined
|
|
52
|
+
? {}
|
|
53
|
+
: {
|
|
54
|
+
since: model.since.toISOString(),
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
fromJson: (json: any): Filter => {
|
|
59
|
+
if (json === undefined || json === null) {
|
|
60
|
+
return json;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
field: json['field'],
|
|
64
|
+
...(json['since'] === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: {
|
|
67
|
+
since: new Date(json['since']),
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Client configuration for TestApi
|
|
76
|
+
*/
|
|
77
|
+
export interface TestApiConfig {
|
|
78
|
+
/**
|
|
79
|
+
* Base URL for the API
|
|
80
|
+
*/
|
|
81
|
+
url: string;
|
|
82
|
+
/**
|
|
83
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
84
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
85
|
+
*/
|
|
86
|
+
fetch?: typeof fetch;
|
|
87
|
+
/**
|
|
88
|
+
* Additional configuration
|
|
89
|
+
*/
|
|
90
|
+
options?: {
|
|
91
|
+
/**
|
|
92
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
93
|
+
* the request in the OpenAPI specification.
|
|
94
|
+
* Set this to false to omit this header.
|
|
95
|
+
*/
|
|
96
|
+
omitContentTypeHeader?: boolean;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* API Client for TestApi
|
|
102
|
+
*/
|
|
103
|
+
export class TestApi {
|
|
104
|
+
private $config: TestApiConfig;
|
|
105
|
+
|
|
106
|
+
constructor(config: TestApiConfig) {
|
|
107
|
+
this.$config = config;
|
|
108
|
+
|
|
109
|
+
this.contentParam = this.contentParam.bind(this);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
113
|
+
csv: ',',
|
|
114
|
+
ssv: ' ',
|
|
115
|
+
pipes: '|',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
119
|
+
if (value === undefined || value === null) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
if (typeof value !== 'object') {
|
|
123
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
124
|
+
}
|
|
125
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
126
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
private $url = (
|
|
131
|
+
path: string,
|
|
132
|
+
pathParameters: { [key: string]: any },
|
|
133
|
+
queryParameters: { [key: string]: any },
|
|
134
|
+
collectionFormats?: {
|
|
135
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
136
|
+
},
|
|
137
|
+
): string => {
|
|
138
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
139
|
+
? this.$config.url.slice(0, -1)
|
|
140
|
+
: this.$config.url;
|
|
141
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
142
|
+
(withParams, [key, value]) =>
|
|
143
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
144
|
+
path,
|
|
145
|
+
);
|
|
146
|
+
const queryString = Object.entries(queryParameters)
|
|
147
|
+
.flatMap(([key, value]) => {
|
|
148
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
149
|
+
return value.map(
|
|
150
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (
|
|
154
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
155
|
+
value !== null &&
|
|
156
|
+
typeof value === 'object'
|
|
157
|
+
) {
|
|
158
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
159
|
+
}
|
|
160
|
+
const delimiter =
|
|
161
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
162
|
+
return [
|
|
163
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
164
|
+
];
|
|
165
|
+
})
|
|
166
|
+
.join('&');
|
|
167
|
+
return (
|
|
168
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
private $headers = (
|
|
173
|
+
headerParameters: { [key: string]: any },
|
|
174
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
175
|
+
): [string, string][] => {
|
|
176
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
177
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
178
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
179
|
+
}
|
|
180
|
+
const delimiter =
|
|
181
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
182
|
+
return [
|
|
183
|
+
[
|
|
184
|
+
key,
|
|
185
|
+
Array.isArray(value)
|
|
186
|
+
? value.map(String).join(delimiter)
|
|
187
|
+
: String(value),
|
|
188
|
+
],
|
|
189
|
+
];
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
private $fetch: typeof fetch = (...args) =>
|
|
194
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
195
|
+
|
|
196
|
+
public async contentParam(input: ContentParamRequest): Promise<string> {
|
|
197
|
+
const pathParameters: { [key: string]: any } = {};
|
|
198
|
+
const queryParameters: { [key: string]: any } =
|
|
199
|
+
$IO.ContentParamRequestQueryParameters.toJson(input);
|
|
200
|
+
if (queryParameters['filter'] !== undefined) {
|
|
201
|
+
queryParameters['filter'] = JSON.stringify(queryParameters['filter']);
|
|
202
|
+
}
|
|
203
|
+
const headerParameters: { [key: string]: any } = {};
|
|
204
|
+
const queryCollectionFormats = {
|
|
205
|
+
filter: 'multi',
|
|
206
|
+
} as const;
|
|
207
|
+
|
|
208
|
+
const body = undefined;
|
|
209
|
+
|
|
210
|
+
const response = await this.$fetch(
|
|
211
|
+
this.$url(
|
|
212
|
+
'/query',
|
|
213
|
+
pathParameters,
|
|
214
|
+
queryParameters,
|
|
215
|
+
queryCollectionFormats,
|
|
216
|
+
),
|
|
217
|
+
{
|
|
218
|
+
headers: this.$headers(headerParameters),
|
|
219
|
+
method: 'GET',
|
|
220
|
+
body,
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
if (response.status === 200) {
|
|
225
|
+
return await response.json();
|
|
226
|
+
}
|
|
227
|
+
throw new Error(
|
|
228
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
"
|
|
233
|
+
`;
|
|
234
|
+
|
|
235
|
+
exports[`openApiTsClientGenerator - spec compliance > should JSON-serialise a content-based query parameter with marshalled dates > types.gen.ts 1`] = `
|
|
236
|
+
"export type ContentParamRequestQueryParameters = {
|
|
237
|
+
filter: Filter;
|
|
238
|
+
};
|
|
239
|
+
export type Filter = {
|
|
240
|
+
field: string;
|
|
241
|
+
since?: Date;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export type ContentParamRequest = ContentParamRequestQueryParameters;
|
|
245
|
+
export type ContentParamError = never;
|
|
246
|
+
"
|
|
247
|
+
`;
|
|
248
|
+
|
|
249
|
+
exports[`openApiTsClientGenerator - spec compliance > should keep a decimal format string un-corrupted and round-trip byte fields > client.gen.ts 1`] = `
|
|
250
|
+
"import type { BlobMeta, PutBlobMetaRequest } from './types.gen.js';
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Utility for serialisation and deserialisation of API types.
|
|
254
|
+
*/
|
|
255
|
+
export class $IO {
|
|
256
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
257
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
258
|
+
|
|
259
|
+
public static BlobMeta = {
|
|
260
|
+
toJson: (model: BlobMeta): any => {
|
|
261
|
+
if (model === undefined || model === null) {
|
|
262
|
+
return model;
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
...(model.data === undefined
|
|
266
|
+
? {}
|
|
267
|
+
: {
|
|
268
|
+
data: model.data,
|
|
269
|
+
}),
|
|
270
|
+
...(model.price === undefined
|
|
271
|
+
? {}
|
|
272
|
+
: {
|
|
273
|
+
price: model.price,
|
|
274
|
+
}),
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
fromJson: (json: any): BlobMeta => {
|
|
278
|
+
if (json === undefined || json === null) {
|
|
279
|
+
return json;
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
data: json['data'],
|
|
283
|
+
price: json['price'],
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Client configuration for TestApi
|
|
291
|
+
*/
|
|
292
|
+
export interface TestApiConfig {
|
|
293
|
+
/**
|
|
294
|
+
* Base URL for the API
|
|
295
|
+
*/
|
|
296
|
+
url: string;
|
|
297
|
+
/**
|
|
298
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
299
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
300
|
+
*/
|
|
301
|
+
fetch?: typeof fetch;
|
|
302
|
+
/**
|
|
303
|
+
* Additional configuration
|
|
304
|
+
*/
|
|
305
|
+
options?: {
|
|
306
|
+
/**
|
|
307
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
308
|
+
* the request in the OpenAPI specification.
|
|
309
|
+
* Set this to false to omit this header.
|
|
310
|
+
*/
|
|
311
|
+
omitContentTypeHeader?: boolean;
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* API Client for TestApi
|
|
317
|
+
*/
|
|
318
|
+
export class TestApi {
|
|
319
|
+
private $config: TestApiConfig;
|
|
320
|
+
|
|
321
|
+
constructor(config: TestApiConfig) {
|
|
322
|
+
this.$config = config;
|
|
323
|
+
|
|
324
|
+
this.putBlobMeta = this.putBlobMeta.bind(this);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
328
|
+
csv: ',',
|
|
329
|
+
ssv: ' ',
|
|
330
|
+
pipes: '|',
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
334
|
+
if (value === undefined || value === null) {
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
if (typeof value !== 'object') {
|
|
338
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
339
|
+
}
|
|
340
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
341
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
342
|
+
);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
private $url = (
|
|
346
|
+
path: string,
|
|
347
|
+
pathParameters: { [key: string]: any },
|
|
348
|
+
queryParameters: { [key: string]: any },
|
|
349
|
+
collectionFormats?: {
|
|
350
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
351
|
+
},
|
|
352
|
+
): string => {
|
|
353
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
354
|
+
? this.$config.url.slice(0, -1)
|
|
355
|
+
: this.$config.url;
|
|
356
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
357
|
+
(withParams, [key, value]) =>
|
|
358
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
359
|
+
path,
|
|
360
|
+
);
|
|
361
|
+
const queryString = Object.entries(queryParameters)
|
|
362
|
+
.flatMap(([key, value]) => {
|
|
363
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
364
|
+
return value.map(
|
|
365
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
if (
|
|
369
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
370
|
+
value !== null &&
|
|
371
|
+
typeof value === 'object'
|
|
372
|
+
) {
|
|
373
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
374
|
+
}
|
|
375
|
+
const delimiter =
|
|
376
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
377
|
+
return [
|
|
378
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
379
|
+
];
|
|
380
|
+
})
|
|
381
|
+
.join('&');
|
|
382
|
+
return (
|
|
383
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
384
|
+
);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
private $headers = (
|
|
388
|
+
headerParameters: { [key: string]: any },
|
|
389
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
390
|
+
): [string, string][] => {
|
|
391
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
392
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
393
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
394
|
+
}
|
|
395
|
+
const delimiter =
|
|
396
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
397
|
+
return [
|
|
398
|
+
[
|
|
399
|
+
key,
|
|
400
|
+
Array.isArray(value)
|
|
401
|
+
? value.map(String).join(delimiter)
|
|
402
|
+
: String(value),
|
|
403
|
+
],
|
|
404
|
+
];
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
private $fetch: typeof fetch = (...args) =>
|
|
409
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
410
|
+
|
|
411
|
+
public async putBlobMeta(input: PutBlobMetaRequest): Promise<BlobMeta> {
|
|
412
|
+
const pathParameters: { [key: string]: any } = {};
|
|
413
|
+
const queryParameters: { [key: string]: any } = {};
|
|
414
|
+
const headerParameters: { [key: string]: any } = {};
|
|
415
|
+
if (!this.$config.options?.omitContentTypeHeader) {
|
|
416
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
417
|
+
}
|
|
418
|
+
const body =
|
|
419
|
+
typeof input === 'object'
|
|
420
|
+
? JSON.stringify($IO.BlobMeta.toJson(input))
|
|
421
|
+
: String($IO.BlobMeta.toJson(input));
|
|
422
|
+
|
|
423
|
+
const response = await this.$fetch(
|
|
424
|
+
this.$url('/blob-meta', pathParameters, queryParameters),
|
|
425
|
+
{
|
|
426
|
+
headers: this.$headers(headerParameters),
|
|
427
|
+
method: 'POST',
|
|
428
|
+
body,
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
if (response.status === 200) {
|
|
433
|
+
return $IO.BlobMeta.fromJson(await response.json());
|
|
434
|
+
}
|
|
435
|
+
throw new Error(
|
|
436
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
"
|
|
441
|
+
`;
|
|
442
|
+
|
|
443
|
+
exports[`openApiTsClientGenerator - spec compliance > should keep a decimal format string un-corrupted and round-trip byte fields > types.gen.ts 1`] = `
|
|
444
|
+
"export type BlobMeta = {
|
|
445
|
+
data: string;
|
|
446
|
+
price: string;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
export type PutBlobMetaRequest = BlobMeta;
|
|
450
|
+
export type PutBlobMetaError = never;
|
|
451
|
+
"
|
|
452
|
+
`;
|
|
453
|
+
|
|
454
|
+
exports[`openApiTsClientGenerator - spec compliance > should omit the body entirely for an optional request body > client.gen.ts 1`] = `
|
|
455
|
+
"import type { SearchRequestContent, SearchRequest } from './types.gen.js';
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Utility for serialisation and deserialisation of API types.
|
|
459
|
+
*/
|
|
460
|
+
export class $IO {
|
|
461
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
462
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
463
|
+
|
|
464
|
+
public static SearchRequestContent = {
|
|
465
|
+
toJson: (model: SearchRequestContent): any => {
|
|
466
|
+
if (model === undefined || model === null) {
|
|
467
|
+
return model;
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
...(model.query === undefined
|
|
471
|
+
? {}
|
|
472
|
+
: {
|
|
473
|
+
query: model.query,
|
|
474
|
+
}),
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
fromJson: (json: any): SearchRequestContent => {
|
|
478
|
+
if (json === undefined || json === null) {
|
|
479
|
+
return json;
|
|
480
|
+
}
|
|
481
|
+
return {
|
|
482
|
+
query: json['query'],
|
|
483
|
+
};
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Client configuration for TestApi
|
|
490
|
+
*/
|
|
491
|
+
export interface TestApiConfig {
|
|
492
|
+
/**
|
|
493
|
+
* Base URL for the API
|
|
494
|
+
*/
|
|
495
|
+
url: string;
|
|
496
|
+
/**
|
|
497
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
498
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
499
|
+
*/
|
|
500
|
+
fetch?: typeof fetch;
|
|
501
|
+
/**
|
|
502
|
+
* Additional configuration
|
|
503
|
+
*/
|
|
504
|
+
options?: {
|
|
505
|
+
/**
|
|
506
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
507
|
+
* the request in the OpenAPI specification.
|
|
508
|
+
* Set this to false to omit this header.
|
|
509
|
+
*/
|
|
510
|
+
omitContentTypeHeader?: boolean;
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* API Client for TestApi
|
|
516
|
+
*/
|
|
517
|
+
export class TestApi {
|
|
518
|
+
private $config: TestApiConfig;
|
|
519
|
+
|
|
520
|
+
constructor(config: TestApiConfig) {
|
|
521
|
+
this.$config = config;
|
|
522
|
+
|
|
523
|
+
this.search = this.search.bind(this);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
527
|
+
csv: ',',
|
|
528
|
+
ssv: ' ',
|
|
529
|
+
pipes: '|',
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
533
|
+
if (value === undefined || value === null) {
|
|
534
|
+
return [];
|
|
535
|
+
}
|
|
536
|
+
if (typeof value !== 'object') {
|
|
537
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
538
|
+
}
|
|
539
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
540
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
541
|
+
);
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
private $url = (
|
|
545
|
+
path: string,
|
|
546
|
+
pathParameters: { [key: string]: any },
|
|
547
|
+
queryParameters: { [key: string]: any },
|
|
548
|
+
collectionFormats?: {
|
|
549
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
550
|
+
},
|
|
551
|
+
): string => {
|
|
552
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
553
|
+
? this.$config.url.slice(0, -1)
|
|
554
|
+
: this.$config.url;
|
|
555
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
556
|
+
(withParams, [key, value]) =>
|
|
557
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
558
|
+
path,
|
|
559
|
+
);
|
|
560
|
+
const queryString = Object.entries(queryParameters)
|
|
561
|
+
.flatMap(([key, value]) => {
|
|
562
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
563
|
+
return value.map(
|
|
564
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
if (
|
|
568
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
569
|
+
value !== null &&
|
|
570
|
+
typeof value === 'object'
|
|
571
|
+
) {
|
|
572
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
573
|
+
}
|
|
574
|
+
const delimiter =
|
|
575
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
576
|
+
return [
|
|
577
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
578
|
+
];
|
|
579
|
+
})
|
|
580
|
+
.join('&');
|
|
581
|
+
return (
|
|
582
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
583
|
+
);
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
private $headers = (
|
|
587
|
+
headerParameters: { [key: string]: any },
|
|
588
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
589
|
+
): [string, string][] => {
|
|
590
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
591
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
592
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
593
|
+
}
|
|
594
|
+
const delimiter =
|
|
595
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
596
|
+
return [
|
|
597
|
+
[
|
|
598
|
+
key,
|
|
599
|
+
Array.isArray(value)
|
|
600
|
+
? value.map(String).join(delimiter)
|
|
601
|
+
: String(value),
|
|
602
|
+
],
|
|
603
|
+
];
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
private $fetch: typeof fetch = (...args) =>
|
|
608
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
609
|
+
|
|
610
|
+
public async search(input?: SearchRequest): Promise<string> {
|
|
611
|
+
const pathParameters: { [key: string]: any } = {};
|
|
612
|
+
const queryParameters: { [key: string]: any } = {};
|
|
613
|
+
const headerParameters: { [key: string]: any } = {};
|
|
614
|
+
if (!this.$config.options?.omitContentTypeHeader) {
|
|
615
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
616
|
+
}
|
|
617
|
+
const body =
|
|
618
|
+
input === undefined
|
|
619
|
+
? undefined
|
|
620
|
+
: typeof input === 'object'
|
|
621
|
+
? JSON.stringify($IO.SearchRequestContent.toJson(input))
|
|
622
|
+
: String($IO.SearchRequestContent.toJson(input));
|
|
623
|
+
|
|
624
|
+
const response = await this.$fetch(
|
|
625
|
+
this.$url('/search', pathParameters, queryParameters),
|
|
626
|
+
{
|
|
627
|
+
headers: this.$headers(headerParameters),
|
|
628
|
+
method: 'POST',
|
|
629
|
+
body,
|
|
630
|
+
},
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
if (response.status === 200) {
|
|
634
|
+
return await response.json();
|
|
635
|
+
}
|
|
636
|
+
throw new Error(
|
|
637
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
"
|
|
642
|
+
`;
|
|
643
|
+
|
|
644
|
+
exports[`openApiTsClientGenerator - spec compliance > should omit the body entirely for an optional request body > types.gen.ts 1`] = `
|
|
645
|
+
"export type SearchRequestContent = {
|
|
646
|
+
query: string;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
export type SearchRequest = SearchRequestContent | undefined;
|
|
650
|
+
export type SearchError = never;
|
|
651
|
+
"
|
|
652
|
+
`;
|
|
653
|
+
|
|
654
|
+
exports[`openApiTsClientGenerator - spec compliance > should parse 4XX range responses as typed errors and 5XX text as raw text > client.gen.ts 1`] = `
|
|
655
|
+
"import type {
|
|
656
|
+
GetThing4XXResponse,
|
|
657
|
+
GetThingRequestPathParameters,
|
|
658
|
+
GetThingRequest,
|
|
659
|
+
} from './types.gen.js';
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Utility for serialisation and deserialisation of API types.
|
|
663
|
+
*/
|
|
664
|
+
export class $IO {
|
|
665
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
666
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
667
|
+
|
|
668
|
+
public static GetThing4XXResponse = {
|
|
669
|
+
toJson: (model: GetThing4XXResponse): any => {
|
|
670
|
+
if (model === undefined || model === null) {
|
|
671
|
+
return model;
|
|
672
|
+
}
|
|
673
|
+
return {
|
|
674
|
+
...(model.reason === undefined
|
|
675
|
+
? {}
|
|
676
|
+
: {
|
|
677
|
+
reason: model.reason,
|
|
678
|
+
}),
|
|
679
|
+
};
|
|
680
|
+
},
|
|
681
|
+
fromJson: (json: any): GetThing4XXResponse => {
|
|
682
|
+
if (json === undefined || json === null) {
|
|
683
|
+
return json;
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
reason: json['reason'],
|
|
687
|
+
};
|
|
688
|
+
},
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
public static GetThingRequestPathParameters = {
|
|
692
|
+
toJson: (model: GetThingRequestPathParameters): any => {
|
|
693
|
+
if (model === undefined || model === null) {
|
|
694
|
+
return model;
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
...(model.id === undefined
|
|
698
|
+
? {}
|
|
699
|
+
: {
|
|
700
|
+
id: model.id,
|
|
701
|
+
}),
|
|
702
|
+
};
|
|
703
|
+
},
|
|
704
|
+
fromJson: (json: any): GetThingRequestPathParameters => {
|
|
705
|
+
if (json === undefined || json === null) {
|
|
706
|
+
return json;
|
|
707
|
+
}
|
|
708
|
+
return {
|
|
709
|
+
id: json['id'],
|
|
710
|
+
};
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Client configuration for TestApi
|
|
717
|
+
*/
|
|
718
|
+
export interface TestApiConfig {
|
|
719
|
+
/**
|
|
720
|
+
* Base URL for the API
|
|
721
|
+
*/
|
|
722
|
+
url: string;
|
|
723
|
+
/**
|
|
724
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
725
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
726
|
+
*/
|
|
727
|
+
fetch?: typeof fetch;
|
|
728
|
+
/**
|
|
729
|
+
* Additional configuration
|
|
730
|
+
*/
|
|
731
|
+
options?: {
|
|
732
|
+
/**
|
|
733
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
734
|
+
* the request in the OpenAPI specification.
|
|
735
|
+
* Set this to false to omit this header.
|
|
736
|
+
*/
|
|
737
|
+
omitContentTypeHeader?: boolean;
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* API Client for TestApi
|
|
743
|
+
*/
|
|
744
|
+
export class TestApi {
|
|
745
|
+
private $config: TestApiConfig;
|
|
746
|
+
|
|
747
|
+
constructor(config: TestApiConfig) {
|
|
748
|
+
this.$config = config;
|
|
749
|
+
|
|
750
|
+
this.getThing = this.getThing.bind(this);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
754
|
+
csv: ',',
|
|
755
|
+
ssv: ' ',
|
|
756
|
+
pipes: '|',
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
760
|
+
if (value === undefined || value === null) {
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
763
|
+
if (typeof value !== 'object') {
|
|
764
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
765
|
+
}
|
|
766
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
767
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
768
|
+
);
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
private $url = (
|
|
772
|
+
path: string,
|
|
773
|
+
pathParameters: { [key: string]: any },
|
|
774
|
+
queryParameters: { [key: string]: any },
|
|
775
|
+
collectionFormats?: {
|
|
776
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
777
|
+
},
|
|
778
|
+
): string => {
|
|
779
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
780
|
+
? this.$config.url.slice(0, -1)
|
|
781
|
+
: this.$config.url;
|
|
782
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
783
|
+
(withParams, [key, value]) =>
|
|
784
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
785
|
+
path,
|
|
786
|
+
);
|
|
787
|
+
const queryString = Object.entries(queryParameters)
|
|
788
|
+
.flatMap(([key, value]) => {
|
|
789
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
790
|
+
return value.map(
|
|
791
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
if (
|
|
795
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
796
|
+
value !== null &&
|
|
797
|
+
typeof value === 'object'
|
|
798
|
+
) {
|
|
799
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
800
|
+
}
|
|
801
|
+
const delimiter =
|
|
802
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
803
|
+
return [
|
|
804
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
805
|
+
];
|
|
806
|
+
})
|
|
807
|
+
.join('&');
|
|
808
|
+
return (
|
|
809
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
810
|
+
);
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
private $headers = (
|
|
814
|
+
headerParameters: { [key: string]: any },
|
|
815
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
816
|
+
): [string, string][] => {
|
|
817
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
818
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
819
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
820
|
+
}
|
|
821
|
+
const delimiter =
|
|
822
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
823
|
+
return [
|
|
824
|
+
[
|
|
825
|
+
key,
|
|
826
|
+
Array.isArray(value)
|
|
827
|
+
? value.map(String).join(delimiter)
|
|
828
|
+
: String(value),
|
|
829
|
+
],
|
|
830
|
+
];
|
|
831
|
+
});
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
private $fetch: typeof fetch = (...args) =>
|
|
835
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
836
|
+
|
|
837
|
+
public async getThing(input: GetThingRequest): Promise<string> {
|
|
838
|
+
const pathParameters: { [key: string]: any } =
|
|
839
|
+
$IO.GetThingRequestPathParameters.toJson(input);
|
|
840
|
+
const queryParameters: { [key: string]: any } = {};
|
|
841
|
+
const headerParameters: { [key: string]: any } = {};
|
|
842
|
+
|
|
843
|
+
const body = undefined;
|
|
844
|
+
|
|
845
|
+
const response = await this.$fetch(
|
|
846
|
+
this.$url('/things/{id}', pathParameters, queryParameters),
|
|
847
|
+
{
|
|
848
|
+
headers: this.$headers(headerParameters),
|
|
849
|
+
method: 'GET',
|
|
850
|
+
body,
|
|
851
|
+
},
|
|
852
|
+
);
|
|
853
|
+
|
|
854
|
+
if (response.status === 200) {
|
|
855
|
+
return await response.json();
|
|
856
|
+
}
|
|
857
|
+
if (response.status >= 400 && response.status < 500) {
|
|
858
|
+
throw {
|
|
859
|
+
status: response.status,
|
|
860
|
+
error: $IO.GetThing4XXResponse.fromJson(await response.json()),
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
if (response.status >= 500 && response.status < 600) {
|
|
864
|
+
throw {
|
|
865
|
+
status: response.status,
|
|
866
|
+
error: await response.text(),
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
throw new Error(
|
|
870
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
"
|
|
875
|
+
`;
|
|
876
|
+
|
|
877
|
+
exports[`openApiTsClientGenerator - spec compliance > should parse 4XX range responses as typed errors and 5XX text as raw text > types.gen.ts 1`] = `
|
|
878
|
+
"export type GetThing4XXResponse = {
|
|
879
|
+
reason: string;
|
|
880
|
+
};
|
|
881
|
+
export type GetThingRequestPathParameters = {
|
|
882
|
+
id: string;
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
export type GetThingRequest = GetThingRequestPathParameters;
|
|
886
|
+
export type GetThing4XXError = {
|
|
887
|
+
status: _4XX;
|
|
888
|
+
error: GetThing4XXResponse;
|
|
889
|
+
};
|
|
890
|
+
export type GetThing5XXError = {
|
|
891
|
+
status: _5XX;
|
|
892
|
+
error: string;
|
|
893
|
+
};
|
|
894
|
+
export type GetThingError = GetThing4XXError | GetThing5XXError;
|
|
895
|
+
export type _4XX =
|
|
896
|
+
| 400
|
|
897
|
+
| 401
|
|
898
|
+
| 402
|
|
899
|
+
| 403
|
|
900
|
+
| 404
|
|
901
|
+
| 405
|
|
902
|
+
| 406
|
|
903
|
+
| 407
|
|
904
|
+
| 408
|
|
905
|
+
| 409
|
|
906
|
+
| 410
|
|
907
|
+
| 411
|
|
908
|
+
| 412
|
|
909
|
+
| 413
|
|
910
|
+
| 414
|
|
911
|
+
| 415
|
|
912
|
+
| 416
|
|
913
|
+
| 417
|
|
914
|
+
| 418
|
|
915
|
+
| 419
|
|
916
|
+
| 420
|
|
917
|
+
| 421
|
|
918
|
+
| 422
|
|
919
|
+
| 423
|
|
920
|
+
| 424
|
|
921
|
+
| 425
|
|
922
|
+
| 426
|
|
923
|
+
| 427
|
|
924
|
+
| 428
|
|
925
|
+
| 429
|
|
926
|
+
| 430
|
|
927
|
+
| 431
|
|
928
|
+
| 432
|
|
929
|
+
| 433
|
|
930
|
+
| 434
|
|
931
|
+
| 435
|
|
932
|
+
| 436
|
|
933
|
+
| 437
|
|
934
|
+
| 438
|
|
935
|
+
| 439
|
|
936
|
+
| 440
|
|
937
|
+
| 441
|
|
938
|
+
| 442
|
|
939
|
+
| 443
|
|
940
|
+
| 444
|
|
941
|
+
| 445
|
|
942
|
+
| 446
|
|
943
|
+
| 447
|
|
944
|
+
| 448
|
|
945
|
+
| 449
|
|
946
|
+
| 450
|
|
947
|
+
| 451
|
|
948
|
+
| 452
|
|
949
|
+
| 453
|
|
950
|
+
| 454
|
|
951
|
+
| 455
|
|
952
|
+
| 456
|
|
953
|
+
| 457
|
|
954
|
+
| 458
|
|
955
|
+
| 459
|
|
956
|
+
| 460
|
|
957
|
+
| 461
|
|
958
|
+
| 462
|
|
959
|
+
| 463
|
|
960
|
+
| 464
|
|
961
|
+
| 465
|
|
962
|
+
| 466
|
|
963
|
+
| 467
|
|
964
|
+
| 468
|
|
965
|
+
| 469
|
|
966
|
+
| 470
|
|
967
|
+
| 471
|
|
968
|
+
| 472
|
|
969
|
+
| 473
|
|
970
|
+
| 474
|
|
971
|
+
| 475
|
|
972
|
+
| 476
|
|
973
|
+
| 477
|
|
974
|
+
| 478
|
|
975
|
+
| 479
|
|
976
|
+
| 480
|
|
977
|
+
| 481
|
|
978
|
+
| 482
|
|
979
|
+
| 483
|
|
980
|
+
| 484
|
|
981
|
+
| 485
|
|
982
|
+
| 486
|
|
983
|
+
| 487
|
|
984
|
+
| 488
|
|
985
|
+
| 489
|
|
986
|
+
| 490
|
|
987
|
+
| 491
|
|
988
|
+
| 492
|
|
989
|
+
| 493
|
|
990
|
+
| 494
|
|
991
|
+
| 495
|
|
992
|
+
| 496
|
|
993
|
+
| 497
|
|
994
|
+
| 498
|
|
995
|
+
| 499;
|
|
996
|
+
export type _5XX =
|
|
997
|
+
| 500
|
|
998
|
+
| 501
|
|
999
|
+
| 502
|
|
1000
|
+
| 503
|
|
1001
|
+
| 504
|
|
1002
|
+
| 505
|
|
1003
|
+
| 506
|
|
1004
|
+
| 507
|
|
1005
|
+
| 508
|
|
1006
|
+
| 509
|
|
1007
|
+
| 510
|
|
1008
|
+
| 511
|
|
1009
|
+
| 512
|
|
1010
|
+
| 513
|
|
1011
|
+
| 514
|
|
1012
|
+
| 515
|
|
1013
|
+
| 516
|
|
1014
|
+
| 517
|
|
1015
|
+
| 518
|
|
1016
|
+
| 519
|
|
1017
|
+
| 520
|
|
1018
|
+
| 521
|
|
1019
|
+
| 522
|
|
1020
|
+
| 523
|
|
1021
|
+
| 524
|
|
1022
|
+
| 525
|
|
1023
|
+
| 526
|
|
1024
|
+
| 527
|
|
1025
|
+
| 528
|
|
1026
|
+
| 529
|
|
1027
|
+
| 530
|
|
1028
|
+
| 531
|
|
1029
|
+
| 532
|
|
1030
|
+
| 533
|
|
1031
|
+
| 534
|
|
1032
|
+
| 535
|
|
1033
|
+
| 536
|
|
1034
|
+
| 537
|
|
1035
|
+
| 538
|
|
1036
|
+
| 539
|
|
1037
|
+
| 540
|
|
1038
|
+
| 541
|
|
1039
|
+
| 542
|
|
1040
|
+
| 543
|
|
1041
|
+
| 544
|
|
1042
|
+
| 545
|
|
1043
|
+
| 546
|
|
1044
|
+
| 547
|
|
1045
|
+
| 548
|
|
1046
|
+
| 549
|
|
1047
|
+
| 550
|
|
1048
|
+
| 551
|
|
1049
|
+
| 552
|
|
1050
|
+
| 553
|
|
1051
|
+
| 554
|
|
1052
|
+
| 555
|
|
1053
|
+
| 556
|
|
1054
|
+
| 557
|
|
1055
|
+
| 558
|
|
1056
|
+
| 559
|
|
1057
|
+
| 560
|
|
1058
|
+
| 561
|
|
1059
|
+
| 562
|
|
1060
|
+
| 563
|
|
1061
|
+
| 564
|
|
1062
|
+
| 565
|
|
1063
|
+
| 566
|
|
1064
|
+
| 567
|
|
1065
|
+
| 568
|
|
1066
|
+
| 569
|
|
1067
|
+
| 570
|
|
1068
|
+
| 571
|
|
1069
|
+
| 572
|
|
1070
|
+
| 573
|
|
1071
|
+
| 574
|
|
1072
|
+
| 575
|
|
1073
|
+
| 576
|
|
1074
|
+
| 577
|
|
1075
|
+
| 578
|
|
1076
|
+
| 579
|
|
1077
|
+
| 580
|
|
1078
|
+
| 581
|
|
1079
|
+
| 582
|
|
1080
|
+
| 583
|
|
1081
|
+
| 584
|
|
1082
|
+
| 585
|
|
1083
|
+
| 586
|
|
1084
|
+
| 587
|
|
1085
|
+
| 588
|
|
1086
|
+
| 589
|
|
1087
|
+
| 590
|
|
1088
|
+
| 591
|
|
1089
|
+
| 592
|
|
1090
|
+
| 593
|
|
1091
|
+
| 594
|
|
1092
|
+
| 595
|
|
1093
|
+
| 596
|
|
1094
|
+
| 597
|
|
1095
|
+
| 598
|
|
1096
|
+
| 599;
|
|
1097
|
+
"
|
|
1098
|
+
`;
|
|
1099
|
+
|
|
1100
|
+
exports[`openApiTsClientGenerator - spec compliance > should send multipart parts with content types declared by the encoding object > client.gen.ts 1`] = `
|
|
1101
|
+
"import type {
|
|
1102
|
+
CreateDocumentRequestContent,
|
|
1103
|
+
CreateDocumentRequestContentMetadata,
|
|
1104
|
+
CreateDocumentRequest,
|
|
1105
|
+
} from './types.gen.js';
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1109
|
+
*/
|
|
1110
|
+
export class $IO {
|
|
1111
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1112
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1113
|
+
|
|
1114
|
+
public static CreateDocumentRequestContent = {
|
|
1115
|
+
toJson: (model: CreateDocumentRequestContent): any => {
|
|
1116
|
+
if (model === undefined || model === null) {
|
|
1117
|
+
return model;
|
|
1118
|
+
}
|
|
1119
|
+
return {
|
|
1120
|
+
...(model.metadata === undefined
|
|
1121
|
+
? {}
|
|
1122
|
+
: {
|
|
1123
|
+
metadata: $IO.CreateDocumentRequestContentMetadata.toJson(
|
|
1124
|
+
model.metadata,
|
|
1125
|
+
),
|
|
1126
|
+
}),
|
|
1127
|
+
...(model.file === undefined
|
|
1128
|
+
? {}
|
|
1129
|
+
: {
|
|
1130
|
+
file: model.file,
|
|
1131
|
+
}),
|
|
1132
|
+
};
|
|
1133
|
+
},
|
|
1134
|
+
fromJson: (json: any): CreateDocumentRequestContent => {
|
|
1135
|
+
if (json === undefined || json === null) {
|
|
1136
|
+
return json;
|
|
1137
|
+
}
|
|
1138
|
+
return {
|
|
1139
|
+
metadata: $IO.CreateDocumentRequestContentMetadata.fromJson(
|
|
1140
|
+
json['metadata'],
|
|
1141
|
+
),
|
|
1142
|
+
file: json['file'],
|
|
1143
|
+
};
|
|
1144
|
+
},
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
public static CreateDocumentRequestContentMetadata = {
|
|
1148
|
+
toJson: (model: CreateDocumentRequestContentMetadata): any => {
|
|
1149
|
+
if (model === undefined || model === null) {
|
|
1150
|
+
return model;
|
|
1151
|
+
}
|
|
1152
|
+
return {
|
|
1153
|
+
...(model.title === undefined
|
|
1154
|
+
? {}
|
|
1155
|
+
: {
|
|
1156
|
+
title: model.title,
|
|
1157
|
+
}),
|
|
1158
|
+
};
|
|
1159
|
+
},
|
|
1160
|
+
fromJson: (json: any): CreateDocumentRequestContentMetadata => {
|
|
1161
|
+
if (json === undefined || json === null) {
|
|
1162
|
+
return json;
|
|
1163
|
+
}
|
|
1164
|
+
return {
|
|
1165
|
+
title: json['title'],
|
|
1166
|
+
};
|
|
1167
|
+
},
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Client configuration for TestApi
|
|
1173
|
+
*/
|
|
1174
|
+
export interface TestApiConfig {
|
|
1175
|
+
/**
|
|
1176
|
+
* Base URL for the API
|
|
1177
|
+
*/
|
|
1178
|
+
url: string;
|
|
1179
|
+
/**
|
|
1180
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1181
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1182
|
+
*/
|
|
1183
|
+
fetch?: typeof fetch;
|
|
1184
|
+
/**
|
|
1185
|
+
* Additional configuration
|
|
1186
|
+
*/
|
|
1187
|
+
options?: {
|
|
1188
|
+
/**
|
|
1189
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1190
|
+
* the request in the OpenAPI specification.
|
|
1191
|
+
* Set this to false to omit this header.
|
|
1192
|
+
*/
|
|
1193
|
+
omitContentTypeHeader?: boolean;
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* API Client for TestApi
|
|
1199
|
+
*/
|
|
1200
|
+
export class TestApi {
|
|
1201
|
+
private $config: TestApiConfig;
|
|
1202
|
+
|
|
1203
|
+
constructor(config: TestApiConfig) {
|
|
1204
|
+
this.$config = config;
|
|
1205
|
+
|
|
1206
|
+
this.createDocument = this.createDocument.bind(this);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
1210
|
+
csv: ',',
|
|
1211
|
+
ssv: ' ',
|
|
1212
|
+
pipes: '|',
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
1216
|
+
if (value === undefined || value === null) {
|
|
1217
|
+
return [];
|
|
1218
|
+
}
|
|
1219
|
+
if (typeof value !== 'object') {
|
|
1220
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
1221
|
+
}
|
|
1222
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
1223
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
1224
|
+
);
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
private $url = (
|
|
1228
|
+
path: string,
|
|
1229
|
+
pathParameters: { [key: string]: any },
|
|
1230
|
+
queryParameters: { [key: string]: any },
|
|
1231
|
+
collectionFormats?: {
|
|
1232
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
1233
|
+
},
|
|
1234
|
+
): string => {
|
|
1235
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1236
|
+
? this.$config.url.slice(0, -1)
|
|
1237
|
+
: this.$config.url;
|
|
1238
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1239
|
+
(withParams, [key, value]) =>
|
|
1240
|
+
withParams.replace(\`{\${key}}\`, encodeURIComponent(\`\${value}\`)),
|
|
1241
|
+
path,
|
|
1242
|
+
);
|
|
1243
|
+
const queryString = Object.entries(queryParameters)
|
|
1244
|
+
.flatMap(([key, value]) => {
|
|
1245
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1246
|
+
return value.map(
|
|
1247
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
if (
|
|
1251
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
1252
|
+
value !== null &&
|
|
1253
|
+
typeof value === 'object'
|
|
1254
|
+
) {
|
|
1255
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
1256
|
+
}
|
|
1257
|
+
const delimiter =
|
|
1258
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1259
|
+
return [
|
|
1260
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
1261
|
+
];
|
|
1262
|
+
})
|
|
1263
|
+
.join('&');
|
|
1264
|
+
return (
|
|
1265
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1266
|
+
);
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
private $headers = (
|
|
1270
|
+
headerParameters: { [key: string]: any },
|
|
1271
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
1272
|
+
): [string, string][] => {
|
|
1273
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1274
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1275
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1276
|
+
}
|
|
1277
|
+
const delimiter =
|
|
1278
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1279
|
+
return [
|
|
1280
|
+
[
|
|
1281
|
+
key,
|
|
1282
|
+
Array.isArray(value)
|
|
1283
|
+
? value.map(String).join(delimiter)
|
|
1284
|
+
: String(value),
|
|
1285
|
+
],
|
|
1286
|
+
];
|
|
1287
|
+
});
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
private $formData = (
|
|
1291
|
+
model: { [key: string]: any },
|
|
1292
|
+
partContentTypes?: { [key: string]: string },
|
|
1293
|
+
): FormData => {
|
|
1294
|
+
const formData = new FormData();
|
|
1295
|
+
const append = (key: string, value: any): void => {
|
|
1296
|
+
if (value === undefined || value === null) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const partContentType = partContentTypes?.[key];
|
|
1300
|
+
if (value instanceof Blob || typeof value === 'string') {
|
|
1301
|
+
// A declared part content type overrides the default (text/plain for
|
|
1302
|
+
// strings, the Blob's own type otherwise)
|
|
1303
|
+
if (partContentType) {
|
|
1304
|
+
formData.append(key, new Blob([value], { type: partContentType }));
|
|
1305
|
+
} else {
|
|
1306
|
+
formData.append(key, value);
|
|
1307
|
+
}
|
|
1308
|
+
} else if (Array.isArray(value)) {
|
|
1309
|
+
value.forEach((v) => append(key, v));
|
|
1310
|
+
} else if (typeof value === 'object') {
|
|
1311
|
+
const serialized = JSON.stringify(value);
|
|
1312
|
+
if (partContentType) {
|
|
1313
|
+
formData.append(
|
|
1314
|
+
key,
|
|
1315
|
+
new Blob([serialized], { type: partContentType }),
|
|
1316
|
+
);
|
|
1317
|
+
} else {
|
|
1318
|
+
formData.append(key, serialized);
|
|
1319
|
+
}
|
|
1320
|
+
} else {
|
|
1321
|
+
formData.append(key, String(value));
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
Object.entries(model).forEach(([key, value]) => append(key, value));
|
|
1325
|
+
return formData;
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1329
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1330
|
+
|
|
1331
|
+
public async createDocument(input: CreateDocumentRequest): Promise<string> {
|
|
1332
|
+
const pathParameters: { [key: string]: any } = {};
|
|
1333
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1334
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1335
|
+
const body = this.$formData(
|
|
1336
|
+
$IO.CreateDocumentRequestContent.toJson(input),
|
|
1337
|
+
{ metadata: 'application/json' },
|
|
1338
|
+
);
|
|
1339
|
+
|
|
1340
|
+
const response = await this.$fetch(
|
|
1341
|
+
this.$url('/documents', pathParameters, queryParameters),
|
|
1342
|
+
{
|
|
1343
|
+
headers: this.$headers(headerParameters),
|
|
1344
|
+
method: 'POST',
|
|
1345
|
+
body,
|
|
1346
|
+
},
|
|
1347
|
+
);
|
|
1348
|
+
|
|
1349
|
+
if (response.status === 200) {
|
|
1350
|
+
return await response.json();
|
|
1351
|
+
}
|
|
1352
|
+
throw new Error(
|
|
1353
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
"
|
|
1358
|
+
`;
|
|
1359
|
+
|
|
1360
|
+
exports[`openApiTsClientGenerator - spec compliance > should send multipart parts with content types declared by the encoding object > types.gen.ts 1`] = `
|
|
1361
|
+
"export type CreateDocumentRequestContent = {
|
|
1362
|
+
metadata: CreateDocumentRequestContentMetadata;
|
|
1363
|
+
file: Blob;
|
|
1364
|
+
};
|
|
1365
|
+
export type CreateDocumentRequestContentMetadata = {
|
|
1366
|
+
title: string;
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1369
|
+
export type CreateDocumentRequest = CreateDocumentRequestContent;
|
|
1370
|
+
export type CreateDocumentError = never;
|
|
1371
|
+
"
|
|
1372
|
+
`;
|
|
1373
|
+
|
|
1374
|
+
exports[`openApiTsClientGenerator - spec compliance > should serialise exploded matrix and label path styles > client.gen.ts 1`] = `
|
|
1375
|
+
"import type {
|
|
1376
|
+
StyledRequestPathParameters,
|
|
1377
|
+
StyledRequest,
|
|
1378
|
+
} from './types.gen.js';
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1382
|
+
*/
|
|
1383
|
+
export class $IO {
|
|
1384
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1385
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1386
|
+
|
|
1387
|
+
public static StyledRequestPathParameters = {
|
|
1388
|
+
toJson: (model: StyledRequestPathParameters): any => {
|
|
1389
|
+
if (model === undefined || model === null) {
|
|
1390
|
+
return model;
|
|
1391
|
+
}
|
|
1392
|
+
return {
|
|
1393
|
+
...(model.coords === undefined
|
|
1394
|
+
? {}
|
|
1395
|
+
: {
|
|
1396
|
+
coords: model.coords,
|
|
1397
|
+
}),
|
|
1398
|
+
...(model.tags === undefined
|
|
1399
|
+
? {}
|
|
1400
|
+
: {
|
|
1401
|
+
tags: model.tags,
|
|
1402
|
+
}),
|
|
1403
|
+
};
|
|
1404
|
+
},
|
|
1405
|
+
fromJson: (json: any): StyledRequestPathParameters => {
|
|
1406
|
+
if (json === undefined || json === null) {
|
|
1407
|
+
return json;
|
|
1408
|
+
}
|
|
1409
|
+
return {
|
|
1410
|
+
coords: json['coords'],
|
|
1411
|
+
tags: json['tags'],
|
|
1412
|
+
};
|
|
1413
|
+
},
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/**
|
|
1418
|
+
* Client configuration for TestApi
|
|
1419
|
+
*/
|
|
1420
|
+
export interface TestApiConfig {
|
|
1421
|
+
/**
|
|
1422
|
+
* Base URL for the API
|
|
1423
|
+
*/
|
|
1424
|
+
url: string;
|
|
1425
|
+
/**
|
|
1426
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1427
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1428
|
+
*/
|
|
1429
|
+
fetch?: typeof fetch;
|
|
1430
|
+
/**
|
|
1431
|
+
* Additional configuration
|
|
1432
|
+
*/
|
|
1433
|
+
options?: {
|
|
1434
|
+
/**
|
|
1435
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1436
|
+
* the request in the OpenAPI specification.
|
|
1437
|
+
* Set this to false to omit this header.
|
|
1438
|
+
*/
|
|
1439
|
+
omitContentTypeHeader?: boolean;
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* API Client for TestApi
|
|
1445
|
+
*/
|
|
1446
|
+
export class TestApi {
|
|
1447
|
+
private $config: TestApiConfig;
|
|
1448
|
+
|
|
1449
|
+
constructor(config: TestApiConfig) {
|
|
1450
|
+
this.$config = config;
|
|
1451
|
+
|
|
1452
|
+
this.styled = this.styled.bind(this);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
1456
|
+
csv: ',',
|
|
1457
|
+
ssv: ' ',
|
|
1458
|
+
pipes: '|',
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1461
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
1462
|
+
if (value === undefined || value === null) {
|
|
1463
|
+
return [];
|
|
1464
|
+
}
|
|
1465
|
+
if (typeof value !== 'object') {
|
|
1466
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
1467
|
+
}
|
|
1468
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
1469
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
1470
|
+
);
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
private $url = (
|
|
1474
|
+
path: string,
|
|
1475
|
+
pathParameters: { [key: string]: any },
|
|
1476
|
+
queryParameters: { [key: string]: any },
|
|
1477
|
+
collectionFormats?: {
|
|
1478
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
1479
|
+
},
|
|
1480
|
+
pathStyles?: {
|
|
1481
|
+
[key: string]: { style: 'matrix' | 'label'; explode: boolean };
|
|
1482
|
+
},
|
|
1483
|
+
): string => {
|
|
1484
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1485
|
+
? this.$config.url.slice(0, -1)
|
|
1486
|
+
: this.$config.url;
|
|
1487
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1488
|
+
(withParams, [key, value]) => {
|
|
1489
|
+
const pathStyle = pathStyles?.[key];
|
|
1490
|
+
let rendered: string;
|
|
1491
|
+
if (pathStyle?.style === 'matrix') {
|
|
1492
|
+
// RFC 6570 path-style expansion: ;key=a,b (explode: ;key=a;key=b)
|
|
1493
|
+
rendered =
|
|
1494
|
+
Array.isArray(value) && pathStyle.explode
|
|
1495
|
+
? value
|
|
1496
|
+
.map((v) => \`;\${key}=\${encodeURIComponent(\`\${v}\`)}\`)
|
|
1497
|
+
.join('')
|
|
1498
|
+
: \`;\${key}=\${(Array.isArray(value) ? value : [value]).map((v) => encodeURIComponent(\`\${v}\`)).join(',')}\`;
|
|
1499
|
+
} else if (pathStyle?.style === 'label') {
|
|
1500
|
+
// RFC 6570 label expansion: .a,b (explode: .a.b)
|
|
1501
|
+
rendered = \`.\${(Array.isArray(value) ? value : [value]).map((v) => encodeURIComponent(\`\${v}\`)).join(pathStyle.explode ? '.' : ',')}\`;
|
|
1502
|
+
} else {
|
|
1503
|
+
rendered = encodeURIComponent(\`\${value}\`);
|
|
1504
|
+
}
|
|
1505
|
+
return withParams.replace(\`{\${key}}\`, rendered);
|
|
1506
|
+
},
|
|
1507
|
+
path,
|
|
1508
|
+
);
|
|
1509
|
+
const queryString = Object.entries(queryParameters)
|
|
1510
|
+
.flatMap(([key, value]) => {
|
|
1511
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1512
|
+
return value.map(
|
|
1513
|
+
(v) => \`\${encodeURIComponent(key)}=\${encodeURIComponent(\`\${v}\`)}\`,
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
if (
|
|
1517
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
1518
|
+
value !== null &&
|
|
1519
|
+
typeof value === 'object'
|
|
1520
|
+
) {
|
|
1521
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
1522
|
+
}
|
|
1523
|
+
const delimiter =
|
|
1524
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1525
|
+
return [
|
|
1526
|
+
\`\${encodeURIComponent(key)}=\${encodeURIComponent(Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
1527
|
+
];
|
|
1528
|
+
})
|
|
1529
|
+
.join('&');
|
|
1530
|
+
return (
|
|
1531
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1532
|
+
);
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
private $headers = (
|
|
1536
|
+
headerParameters: { [key: string]: any },
|
|
1537
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
1538
|
+
): [string, string][] => {
|
|
1539
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1540
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1541
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1542
|
+
}
|
|
1543
|
+
const delimiter =
|
|
1544
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1545
|
+
return [
|
|
1546
|
+
[
|
|
1547
|
+
key,
|
|
1548
|
+
Array.isArray(value)
|
|
1549
|
+
? value.map(String).join(delimiter)
|
|
1550
|
+
: String(value),
|
|
1551
|
+
],
|
|
1552
|
+
];
|
|
1553
|
+
});
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1556
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1557
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1558
|
+
|
|
1559
|
+
public async styled(input: StyledRequest): Promise<string> {
|
|
1560
|
+
const pathParameters: { [key: string]: any } =
|
|
1561
|
+
$IO.StyledRequestPathParameters.toJson(input);
|
|
1562
|
+
const queryParameters: { [key: string]: any } = {};
|
|
1563
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1564
|
+
const pathParameterStyles = {
|
|
1565
|
+
coords: { style: 'matrix', explode: true },
|
|
1566
|
+
tags: { style: 'label', explode: true },
|
|
1567
|
+
} as const;
|
|
1568
|
+
|
|
1569
|
+
const body = undefined;
|
|
1570
|
+
|
|
1571
|
+
const response = await this.$fetch(
|
|
1572
|
+
this.$url(
|
|
1573
|
+
'/m/{coords}/l/{tags}',
|
|
1574
|
+
pathParameters,
|
|
1575
|
+
queryParameters,
|
|
1576
|
+
undefined,
|
|
1577
|
+
pathParameterStyles,
|
|
1578
|
+
),
|
|
1579
|
+
{
|
|
1580
|
+
headers: this.$headers(headerParameters),
|
|
1581
|
+
method: 'GET',
|
|
1582
|
+
body,
|
|
1583
|
+
},
|
|
1584
|
+
);
|
|
1585
|
+
|
|
1586
|
+
if (response.status === 200) {
|
|
1587
|
+
return await response.json();
|
|
1588
|
+
}
|
|
1589
|
+
throw new Error(
|
|
1590
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
"
|
|
1595
|
+
`;
|
|
1596
|
+
|
|
1597
|
+
exports[`openApiTsClientGenerator - spec compliance > should serialise exploded matrix and label path styles > types.gen.ts 1`] = `
|
|
1598
|
+
"export type StyledRequestPathParameters = {
|
|
1599
|
+
coords: Array<number>;
|
|
1600
|
+
tags: Array<string>;
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
export type StyledRequest = StyledRequestPathParameters;
|
|
1604
|
+
export type StyledError = never;
|
|
1605
|
+
"
|
|
1606
|
+
`;
|
|
1607
|
+
|
|
1608
|
+
exports[`openApiTsClientGenerator - spec compliance > should serialise matrix and label path styles and allowReserved query parameters > client.gen.ts 1`] = `
|
|
1609
|
+
"import type {
|
|
1610
|
+
StyledRequestPathParameters,
|
|
1611
|
+
StyledRequestQueryParameters,
|
|
1612
|
+
StyledRequest,
|
|
1613
|
+
} from './types.gen.js';
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Utility for serialisation and deserialisation of API types.
|
|
1617
|
+
*/
|
|
1618
|
+
export class $IO {
|
|
1619
|
+
public static $mapValues = (data: any, fn: (item: any) => any) =>
|
|
1620
|
+
Object.fromEntries(Object.entries(data).map(([k, v]) => [k, fn(v)]));
|
|
1621
|
+
|
|
1622
|
+
public static StyledRequestPathParameters = {
|
|
1623
|
+
toJson: (model: StyledRequestPathParameters): any => {
|
|
1624
|
+
if (model === undefined || model === null) {
|
|
1625
|
+
return model;
|
|
1626
|
+
}
|
|
1627
|
+
return {
|
|
1628
|
+
...(model.coords === undefined
|
|
1629
|
+
? {}
|
|
1630
|
+
: {
|
|
1631
|
+
coords: model.coords,
|
|
1632
|
+
}),
|
|
1633
|
+
...(model.tags === undefined
|
|
1634
|
+
? {}
|
|
1635
|
+
: {
|
|
1636
|
+
tags: model.tags,
|
|
1637
|
+
}),
|
|
1638
|
+
};
|
|
1639
|
+
},
|
|
1640
|
+
fromJson: (json: any): StyledRequestPathParameters => {
|
|
1641
|
+
if (json === undefined || json === null) {
|
|
1642
|
+
return json;
|
|
1643
|
+
}
|
|
1644
|
+
return {
|
|
1645
|
+
coords: json['coords'],
|
|
1646
|
+
tags: json['tags'],
|
|
1647
|
+
};
|
|
1648
|
+
},
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
public static StyledRequestQueryParameters = {
|
|
1652
|
+
toJson: (model: StyledRequestQueryParameters): any => {
|
|
1653
|
+
if (model === undefined || model === null) {
|
|
1654
|
+
return model;
|
|
1655
|
+
}
|
|
1656
|
+
return {
|
|
1657
|
+
...(model.filter === undefined
|
|
1658
|
+
? {}
|
|
1659
|
+
: {
|
|
1660
|
+
filter: model.filter,
|
|
1661
|
+
}),
|
|
1662
|
+
};
|
|
1663
|
+
},
|
|
1664
|
+
fromJson: (json: any): StyledRequestQueryParameters => {
|
|
1665
|
+
if (json === undefined || json === null) {
|
|
1666
|
+
return json;
|
|
1667
|
+
}
|
|
1668
|
+
return {
|
|
1669
|
+
filter: json['filter'],
|
|
1670
|
+
};
|
|
1671
|
+
},
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
/**
|
|
1676
|
+
* Client configuration for TestApi
|
|
1677
|
+
*/
|
|
1678
|
+
export interface TestApiConfig {
|
|
1679
|
+
/**
|
|
1680
|
+
* Base URL for the API
|
|
1681
|
+
*/
|
|
1682
|
+
url: string;
|
|
1683
|
+
/**
|
|
1684
|
+
* Custom instance of fetch. By default the global 'fetch' is used.
|
|
1685
|
+
* You can override this to add custom middleware for use cases such as adding authentication headers.
|
|
1686
|
+
*/
|
|
1687
|
+
fetch?: typeof fetch;
|
|
1688
|
+
/**
|
|
1689
|
+
* Additional configuration
|
|
1690
|
+
*/
|
|
1691
|
+
options?: {
|
|
1692
|
+
/**
|
|
1693
|
+
* By default, the client will add a Content-Type header, set to the media type defined for
|
|
1694
|
+
* the request in the OpenAPI specification.
|
|
1695
|
+
* Set this to false to omit this header.
|
|
1696
|
+
*/
|
|
1697
|
+
omitContentTypeHeader?: boolean;
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
/**
|
|
1702
|
+
* API Client for TestApi
|
|
1703
|
+
*/
|
|
1704
|
+
export class TestApi {
|
|
1705
|
+
private $config: TestApiConfig;
|
|
1706
|
+
|
|
1707
|
+
constructor(config: TestApiConfig) {
|
|
1708
|
+
this.$config = config;
|
|
1709
|
+
|
|
1710
|
+
this.styled = this.styled.bind(this);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
private $collectionDelimiters: { [format: string]: string } = {
|
|
1714
|
+
csv: ',',
|
|
1715
|
+
ssv: ' ',
|
|
1716
|
+
pipes: '|',
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1719
|
+
private $deepObject = (key: string, value: any): string[] => {
|
|
1720
|
+
if (value === undefined || value === null) {
|
|
1721
|
+
return [];
|
|
1722
|
+
}
|
|
1723
|
+
if (typeof value !== 'object') {
|
|
1724
|
+
return [\`\${key}=\${encodeURIComponent(String(value))}\`];
|
|
1725
|
+
}
|
|
1726
|
+
return Object.entries(value).flatMap(([prop, v]) =>
|
|
1727
|
+
this.$deepObject(\`\${key}[\${encodeURIComponent(prop)}]\`, v),
|
|
1728
|
+
);
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
private $url = (
|
|
1732
|
+
path: string,
|
|
1733
|
+
pathParameters: { [key: string]: any },
|
|
1734
|
+
queryParameters: { [key: string]: any },
|
|
1735
|
+
collectionFormats?: {
|
|
1736
|
+
[key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' | 'deepObject';
|
|
1737
|
+
},
|
|
1738
|
+
pathStyles?: {
|
|
1739
|
+
[key: string]: { style: 'matrix' | 'label'; explode: boolean };
|
|
1740
|
+
},
|
|
1741
|
+
allowReserved?: string[],
|
|
1742
|
+
): string => {
|
|
1743
|
+
const baseUrl = this.$config.url.endsWith('/')
|
|
1744
|
+
? this.$config.url.slice(0, -1)
|
|
1745
|
+
: this.$config.url;
|
|
1746
|
+
// Reserved characters stay literal when a query parameter declares allowReserved
|
|
1747
|
+
const encodeQueryValue = (key: string, v: string): string =>
|
|
1748
|
+
allowReserved?.includes(key)
|
|
1749
|
+
? encodeURIComponent(v).replace(
|
|
1750
|
+
/%(2F|3A|3F|23|5B|5D|40|21|24|26|27|28|29|2A|2B|2C|3B|3D)/gi,
|
|
1751
|
+
(m) => decodeURIComponent(m),
|
|
1752
|
+
)
|
|
1753
|
+
: encodeURIComponent(v);
|
|
1754
|
+
const pathWithParameters = Object.entries(pathParameters).reduce(
|
|
1755
|
+
(withParams, [key, value]) => {
|
|
1756
|
+
const pathStyle = pathStyles?.[key];
|
|
1757
|
+
let rendered: string;
|
|
1758
|
+
if (pathStyle?.style === 'matrix') {
|
|
1759
|
+
// RFC 6570 path-style expansion: ;key=a,b (explode: ;key=a;key=b)
|
|
1760
|
+
rendered =
|
|
1761
|
+
Array.isArray(value) && pathStyle.explode
|
|
1762
|
+
? value
|
|
1763
|
+
.map((v) => \`;\${key}=\${encodeURIComponent(\`\${v}\`)}\`)
|
|
1764
|
+
.join('')
|
|
1765
|
+
: \`;\${key}=\${(Array.isArray(value) ? value : [value]).map((v) => encodeURIComponent(\`\${v}\`)).join(',')}\`;
|
|
1766
|
+
} else if (pathStyle?.style === 'label') {
|
|
1767
|
+
// RFC 6570 label expansion: .a,b (explode: .a.b)
|
|
1768
|
+
rendered = \`.\${(Array.isArray(value) ? value : [value]).map((v) => encodeURIComponent(\`\${v}\`)).join(pathStyle.explode ? '.' : ',')}\`;
|
|
1769
|
+
} else {
|
|
1770
|
+
rendered = encodeURIComponent(\`\${value}\`);
|
|
1771
|
+
}
|
|
1772
|
+
return withParams.replace(\`{\${key}}\`, rendered);
|
|
1773
|
+
},
|
|
1774
|
+
path,
|
|
1775
|
+
);
|
|
1776
|
+
const queryString = Object.entries(queryParameters)
|
|
1777
|
+
.flatMap(([key, value]) => {
|
|
1778
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1779
|
+
return value.map(
|
|
1780
|
+
(v) =>
|
|
1781
|
+
\`\${encodeURIComponent(key)}=\${encodeQueryValue(key, \`\${v}\`)}\`,
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
if (
|
|
1785
|
+
collectionFormats?.[key] === 'deepObject' &&
|
|
1786
|
+
value !== null &&
|
|
1787
|
+
typeof value === 'object'
|
|
1788
|
+
) {
|
|
1789
|
+
return this.$deepObject(encodeURIComponent(key), value);
|
|
1790
|
+
}
|
|
1791
|
+
const delimiter =
|
|
1792
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1793
|
+
return [
|
|
1794
|
+
\`\${encodeURIComponent(key)}=\${encodeQueryValue(key, Array.isArray(value) ? value.map(String).join(delimiter) : String(value))}\`,
|
|
1795
|
+
];
|
|
1796
|
+
})
|
|
1797
|
+
.join('&');
|
|
1798
|
+
return (
|
|
1799
|
+
baseUrl + pathWithParameters + (queryString ? \`?\${queryString}\` : '')
|
|
1800
|
+
);
|
|
1801
|
+
};
|
|
1802
|
+
|
|
1803
|
+
private $headers = (
|
|
1804
|
+
headerParameters: { [key: string]: any },
|
|
1805
|
+
collectionFormats?: { [key: string]: 'multi' | 'csv' | 'ssv' | 'pipes' },
|
|
1806
|
+
): [string, string][] => {
|
|
1807
|
+
return Object.entries(headerParameters).flatMap(([key, value]) => {
|
|
1808
|
+
if (Array.isArray(value) && collectionFormats?.[key] === 'multi') {
|
|
1809
|
+
return value.map((v) => [key, String(v)]) as [string, string][];
|
|
1810
|
+
}
|
|
1811
|
+
const delimiter =
|
|
1812
|
+
this.$collectionDelimiters[collectionFormats?.[key] ?? 'csv'] ?? ',';
|
|
1813
|
+
return [
|
|
1814
|
+
[
|
|
1815
|
+
key,
|
|
1816
|
+
Array.isArray(value)
|
|
1817
|
+
? value.map(String).join(delimiter)
|
|
1818
|
+
: String(value),
|
|
1819
|
+
],
|
|
1820
|
+
];
|
|
1821
|
+
});
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
private $fetch: typeof fetch = (...args) =>
|
|
1825
|
+
(this.$config.fetch ?? fetch)(...args);
|
|
1826
|
+
|
|
1827
|
+
public async styled(input: StyledRequest): Promise<string> {
|
|
1828
|
+
const pathParameters: { [key: string]: any } =
|
|
1829
|
+
$IO.StyledRequestPathParameters.toJson(input);
|
|
1830
|
+
const queryParameters: { [key: string]: any } =
|
|
1831
|
+
$IO.StyledRequestQueryParameters.toJson(input);
|
|
1832
|
+
const headerParameters: { [key: string]: any } = {};
|
|
1833
|
+
const queryCollectionFormats = {
|
|
1834
|
+
filter: 'multi',
|
|
1835
|
+
} as const;
|
|
1836
|
+
const pathParameterStyles = {
|
|
1837
|
+
coords: { style: 'matrix', explode: false },
|
|
1838
|
+
tags: { style: 'label', explode: false },
|
|
1839
|
+
} as const;
|
|
1840
|
+
|
|
1841
|
+
const body = undefined;
|
|
1842
|
+
|
|
1843
|
+
const response = await this.$fetch(
|
|
1844
|
+
this.$url(
|
|
1845
|
+
'/m/{coords}/l/{tags}',
|
|
1846
|
+
pathParameters,
|
|
1847
|
+
queryParameters,
|
|
1848
|
+
queryCollectionFormats,
|
|
1849
|
+
pathParameterStyles,
|
|
1850
|
+
['filter'],
|
|
1851
|
+
),
|
|
1852
|
+
{
|
|
1853
|
+
headers: this.$headers(headerParameters),
|
|
1854
|
+
method: 'GET',
|
|
1855
|
+
body,
|
|
1856
|
+
},
|
|
1857
|
+
);
|
|
1858
|
+
|
|
1859
|
+
if (response.status === 200) {
|
|
1860
|
+
return await response.json();
|
|
1861
|
+
}
|
|
1862
|
+
throw new Error(
|
|
1863
|
+
\`Unknown response status \${response.status} returned by API\`,
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
"
|
|
1868
|
+
`;
|
|
1869
|
+
|
|
1870
|
+
exports[`openApiTsClientGenerator - spec compliance > should serialise matrix and label path styles and allowReserved query parameters > types.gen.ts 1`] = `
|
|
1871
|
+
"export type StyledRequestPathParameters = {
|
|
1872
|
+
coords: Array<number>;
|
|
1873
|
+
tags: Array<string>;
|
|
1874
|
+
};
|
|
1875
|
+
export type StyledRequestQueryParameters = {
|
|
1876
|
+
filter: string;
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
export type StyledRequest = StyledRequestPathParameters &
|
|
1880
|
+
StyledRequestQueryParameters;
|
|
1881
|
+
export type StyledError = never;
|
|
1882
|
+
"
|
|
1883
|
+
`;
|