@typespec/http-client-js 0.16.2-dev.1 → 0.16.2
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/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -20
- package/.github/copilot-instructions.md +0 -180
- package/.testignore +0 -19
- package/.turbo/turbo-build.log +0 -3
- package/CHANGELOG.md +0 -159
- package/eng/scripts/calculate-coverage.ts +0 -33
- package/eng/scripts/emit-e2e.ts +0 -317
- package/eng/scripts/run-e2e-tests.ts +0 -166
- package/eng/scripts/tspconfig.yaml +0 -6
- package/eng/scripts/upload-spector-results.ts +0 -139
- package/src/components/client-context/client-context-declaration.tsx +0 -26
- package/src/components/client-context/client-context-factory.tsx +0 -218
- package/src/components/client-context/client-context-options.tsx +0 -36
- package/src/components/client-context/client-context.tsx +0 -23
- package/src/components/client-context/parametrized-endpoint.tsx +0 -51
- package/src/components/client-directory.tsx +0 -51
- package/src/components/client-operation.tsx +0 -102
- package/src/components/client.tsx +0 -177
- package/src/components/encoding-provider.tsx +0 -17
- package/src/components/external-packages/ts-http-runtime.ts +0 -28
- package/src/components/external-packages/uri-template.ts +0 -11
- package/src/components/http-request-options.tsx +0 -88
- package/src/components/http-request-parameters-expression.tsx +0 -191
- package/src/components/http-request.tsx +0 -80
- package/src/components/http-response.tsx +0 -74
- package/src/components/index.ts +0 -12
- package/src/components/models.tsx +0 -26
- package/src/components/operation-handlers/index.tsx +0 -2
- package/src/components/operation-handlers/operation-pipeline.tsx +0 -33
- package/src/components/operation-handlers/paging/page-item.tsx +0 -14
- package/src/components/operation-handlers/paging/page-response.tsx +0 -57
- package/src/components/operation-handlers/paging/page-settings.tsx +0 -53
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +0 -200
- package/src/components/operation-handlers/paging/request-send.tsx +0 -85
- package/src/components/operation-handlers/paging/response-deserialize.tsx +0 -60
- package/src/components/operation-handlers/paging/util.ts +0 -70
- package/src/components/operation-handlers/types.tsx +0 -18
- package/src/components/operation-options.tsx +0 -42
- package/src/components/operation-parameters.tsx +0 -44
- package/src/components/output.tsx +0 -32
- package/src/components/serializers.tsx +0 -74
- package/src/components/static-helpers/bytes-encoding.tsx +0 -61
- package/src/components/static-helpers/interfaces.tsx +0 -31
- package/src/components/static-helpers/multipart-helpers.tsx +0 -80
- package/src/components/static-helpers/paging-helper.tsx +0 -202
- package/src/components/static-helpers/rest-error.tsx +0 -102
- package/src/components/testing/client-options.tsx +0 -30
- package/src/components/transforms/content-type-encoding-provider.tsx +0 -26
- package/src/components/transforms/data-transform.tsx +0 -40
- package/src/components/transforms/json/json-array-transform.tsx +0 -87
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +0 -54
- package/src/components/transforms/json/json-model-base-transform.tsx +0 -24
- package/src/components/transforms/json/json-model-property-transform.tsx +0 -53
- package/src/components/transforms/json/json-model-transform.tsx +0 -115
- package/src/components/transforms/json/json-record-transform.tsx +0 -88
- package/src/components/transforms/json/json-transform-discriminator.tsx +0 -111
- package/src/components/transforms/json/json-transform.tsx +0 -120
- package/src/components/transforms/json/union-transform.tsx +0 -87
- package/src/components/transforms/json/utils/transport-namer.ts +0 -12
- package/src/components/transforms/multipart/array-part-transform.tsx +0 -44
- package/src/components/transforms/multipart/file-part-transform.tsx +0 -45
- package/src/components/transforms/multipart/multipart-transform.tsx +0 -30
- package/src/components/transforms/multipart/part-transform.tsx +0 -22
- package/src/components/transforms/multipart/simple-part-transform.tsx +0 -42
- package/src/components/transforms/operation-transform-declaration.tsx +0 -83
- package/src/components/transforms/operation-transform-expression.tsx +0 -62
- package/src/components/transforms/scalar-transform.tsx +0 -301
- package/src/components/transforms/transform-name-policy.ts +0 -134
- package/src/components/utils/unpack-model-property.ts +0 -44
- package/src/components/utils/url-template.tsx +0 -25
- package/src/context/encoding/encoding-context.tsx +0 -28
- package/src/context/encoding/types.ts +0 -6
- package/src/emitter.tsx +0 -85
- package/src/index.ts +0 -5
- package/src/lib.ts +0 -120
- package/src/testing/index.ts +0 -11
- package/src/utils/client-discovery.ts +0 -28
- package/src/utils/multipart.ts +0 -29
- package/src/utils/operations.ts +0 -112
- package/src/utils/parameters.tsx +0 -155
- package/test/e2e/assets/image.jpg +0 -0
- package/test/e2e/assets/image.png +0 -0
- package/test/e2e/http/authentication/api-key/main.test.ts +0 -38
- package/test/e2e/http/authentication/oauth2/main.test.ts +0 -31
- package/test/e2e/http/authentication/union/main.test.ts +0 -26
- package/test/e2e/http/encode/bytes/main.test.ts +0 -191
- package/test/e2e/http/encode/datetime/main.test.ts +0 -176
- package/test/e2e/http/encode/duration/main.test.ts +0 -126
- package/test/e2e/http/encode/numeric/main.test.ts +0 -26
- package/test/e2e/http/parameters/basic/main.test.ts +0 -35
- package/test/e2e/http/parameters/body-optionality/main.test.ts +0 -43
- package/test/e2e/http/parameters/collection-format/main.test.ts +0 -40
- package/test/e2e/http/parameters/spread/main.test.ts +0 -56
- package/test/e2e/http/payload/content-negotiation/main.test.ts +0 -40
- package/test/e2e/http/payload/json-merge-patch/main.test.ts +0 -122
- package/test/e2e/http/payload/media-type/main.test.ts +0 -28
- package/test/e2e/http/payload/multipart/main.test.ts +0 -200
- package/test/e2e/http/payload/pageable/main.test.ts +0 -78
- package/test/e2e/http/payload/xml/main.test.ts +0 -287
- package/test/e2e/http/routes/main.test.ts +0 -284
- package/test/e2e/http/serialization/encoded-name/json/main.test.ts +0 -20
- package/test/e2e/http/server/endpoint/not-defined/main.test.ts +0 -11
- package/test/e2e/http/server/path/multiple/main.test.ts +0 -22
- package/test/e2e/http/server/path/single/main.test.ts +0 -11
- package/test/e2e/http/server/versions/not-versioned/main.test.ts +0 -22
- package/test/e2e/http/server/versions/versioned/main.test.ts +0 -28
- package/test/e2e/http/special-headers/conditional-request/main.test.ts +0 -35
- package/test/e2e/http/special-headers/repeatability/main.test.ts +0 -18
- package/test/e2e/http/special-words/main.test.ts +0 -434
- package/test/e2e/http/type/array/array.test.ts +0 -256
- package/test/e2e/http/type/dictionary/main.test.ts +0 -229
- package/test/e2e/http/type/enum/extensible/main.test.ts +0 -34
- package/test/e2e/http/type/enum/fixed/main.test.ts +0 -29
- package/test/e2e/http/type/model/empty/main.test.ts +0 -21
- package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +0 -51
- package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +0 -168
- package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +0 -42
- package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +0 -46
- package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +0 -99
- package/test/e2e/http/type/model/visibility/main.test.ts +0 -64
- package/test/e2e/http/type/property/additional-properties/main.test.ts +0 -185
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -448
- package/test/e2e/http/type/property/nullable/main.test.ts +0 -275
- package/test/e2e/http/type/property/optionality/main.test.ts +0 -256
- package/test/e2e/http/type/property/value-types/main.test.ts +0 -193
- package/test/e2e/http/type/scalar/main.test.ts +0 -133
- package/test/e2e/http/type/scalar/scalar.test.ts +0 -95
- package/test/e2e/http/type/union/main.test.ts +0 -207
- package/test/e2e/http/versioning/added/main.test.ts +0 -60
- package/test/e2e/http/versioning/madeOptional/main.test.ts +0 -34
- package/test/e2e/http/versioning/removed/main.test.ts +0 -75
- package/test/e2e/http/versioning/renamedFrom/main.test.ts +0 -52
- package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +0 -22
- package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +0 -31
- package/test/scenarios/additional-properties/extends.md +0 -67
- package/test/scenarios/additional-properties/is.md +0 -42
- package/test/scenarios/additional-properties/spread.md +0 -68
- package/test/scenarios/auth/basic_auth.md +0 -68
- package/test/scenarios/auth/bearer.md +0 -68
- package/test/scenarios/auth/client_parameters.md +0 -78
- package/test/scenarios/auth/client_structure.md +0 -36
- package/test/scenarios/auth/key_credential.md +0 -69
- package/test/scenarios/auth/oauth2.md +0 -90
- package/test/scenarios/auth/sub_client_override.md +0 -114
- package/test/scenarios/client/client_context.md +0 -34
- package/test/scenarios/client/dotted_namespace.md +0 -27
- package/test/scenarios/client/global_namespace.md +0 -69
- package/test/scenarios/client/multiple_top_level_clients.md +0 -72
- package/test/scenarios/client/nested_client.md +0 -102
- package/test/scenarios/client/wrapping_namespace.md +0 -41
- package/test/scenarios/encoding/bytes_body.md +0 -44
- package/test/scenarios/encoding/bytes_json_property.md +0 -55
- package/test/scenarios/encoding/bytes_nullable.md +0 -139
- package/test/scenarios/encoding/header_bytes.md +0 -130
- package/test/scenarios/encoding/header_date.md +0 -216
- package/test/scenarios/encoding/model_with_bytes_property.md +0 -45
- package/test/scenarios/encoding/query_bytes.md +0 -42
- package/test/scenarios/encoding/query_date.md +0 -216
- package/test/scenarios/http-operations/basic-request.md +0 -144
- package/test/scenarios/http-operations/basic-response.md +0 -219
- package/test/scenarios/http-operations/basic.md +0 -128
- package/test/scenarios/http-operations/constant-header.md +0 -33
- package/test/scenarios/http-operations/create-operation.md +0 -58
- package/test/scenarios/http-operations/on_response.md +0 -52
- package/test/scenarios/http-operations/optional-request-body.md +0 -50
- package/test/scenarios/http-operations/paging.md +0 -242
- package/test/scenarios/http-operations/path-parameter-in-model.md +0 -53
- package/test/scenarios/http-operations/path-parameter.md +0 -48
- package/test/scenarios/http-operations/query-parameter.md +0 -41
- package/test/scenarios/http-operations/scalar-payload.md +0 -57
- package/test/scenarios/http-operations/with-parameters.md +0 -78
- package/test/scenarios/models/array-properties.md +0 -47
- package/test/scenarios/models/basic.md +0 -118
- package/test/scenarios/models/dictionary-properties.md +0 -44
- package/test/scenarios/models/inheritance_2_discriminators.md +0 -346
- package/test/scenarios/models/inheritance_discriminator.md +0 -88
- package/test/scenarios/models/inline-models.md +0 -29
- package/test/scenarios/models/model_additional_properties.md +0 -75
- package/test/scenarios/models/model_extends.md +0 -97
- package/test/scenarios/models/model_spread.md +0 -63
- package/test/scenarios/models/nested_property.md +0 -41
- package/test/scenarios/models/property_references_property.md +0 -150
- package/test/scenarios/multipart/anonymous_part.md +0 -53
- package/test/scenarios/multipart/file.md +0 -154
- package/test/scenarios/multipart/file_content_type.md +0 -92
- package/test/scenarios/multipart/non-string-float.md +0 -55
- package/test/scenarios/multipart/simple_part.md +0 -65
- package/test/scenarios/operation-parameters/body_root_anonymous.md +0 -87
- package/test/scenarios/operation-parameters/constant_as_optional.md +0 -54
- package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -54
- package/test/scenarios/operation-parameters/no_content_type.md +0 -62
- package/test/scenarios/operation-parameters/no_parameters.md +0 -50
- package/test/scenarios/operation-parameters/only_optional.md +0 -62
- package/test/scenarios/operation-parameters/only_required.md +0 -58
- package/test/scenarios/operation-parameters/reserved_names.md +0 -60
- package/test/scenarios/operation-parameters/spread_body.md +0 -70
- package/test/scenarios/operation-parameters/spread_with_nested.md +0 -82
- package/test/scenarios/operation-parameters/union_body.md +0 -86
- package/test/scenarios/operation-parameters/with_body_property.md +0 -67
- package/test/scenarios/operation-parameters/with_body_root.md +0 -69
- package/test/scenarios/serializers/arrays.md +0 -191
- package/test/scenarios/serializers/basic_model.md +0 -111
- package/test/scenarios/serializers/basic_model_wire_name.md +0 -48
- package/test/scenarios/serializers/discriminated_union.md +0 -86
- package/test/scenarios/serializers/discriminated_union_spread.md +0 -115
- package/test/scenarios/serializers/file.md +0 -67
- package/test/scenarios/serializers/model_date_time.md +0 -65
- package/test/scenarios/serializers/multipart.md +0 -62
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +0 -157
- package/test/scenarios/serializers/property_references_property.md +0 -72
- package/test/scenarios/serializers/record.md +0 -97
- package/test/scenarios/serializers/scalars.md +0 -34
- package/test/scenarios/serializers/spread.md +0 -69
- package/test/scenarios/serializers/string_union.md +0 -55
- package/test/scenarios/server/default_url.md +0 -45
- package/test/scenarios/server/multiple-parameters.md +0 -55
- package/test/scenarios/server/no-server.md +0 -37
- package/test/scenarios/server/parametrized-endpoint.md +0 -51
- package/test/scenarios.test.ts +0 -24
- package/test/test-host.ts +0 -22
- package/tsconfig.json +0 -16
- package/tsconfig.test.json +0 -9
- package/vitest.config.e2e.ts +0 -16
- package/vitest.config.ts +0 -15
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
MadeOptionalClient,
|
|
4
|
-
Versions,
|
|
5
|
-
} from "../../../generated/versioning/madeOptional/src/index.js";
|
|
6
|
-
|
|
7
|
-
describe("Versioning.MadeOptional", () => {
|
|
8
|
-
const endpoint = "http://localhost:3000";
|
|
9
|
-
|
|
10
|
-
describe("v1", () => {
|
|
11
|
-
const client = new MadeOptionalClient(endpoint, Versions.V1);
|
|
12
|
-
|
|
13
|
-
it("should send the request body and handle the response for v1", async () => {
|
|
14
|
-
const requestBody = { prop: "foo" };
|
|
15
|
-
|
|
16
|
-
const response = await client.test(requestBody);
|
|
17
|
-
|
|
18
|
-
expect(response).toEqual(requestBody); // Mock API expected value
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("v2", () => {
|
|
23
|
-
const client = new MadeOptionalClient(endpoint, Versions.V2);
|
|
24
|
-
|
|
25
|
-
it("should send the request body, additional query param, and handle the response for v2", async () => {
|
|
26
|
-
const requestBody = { prop: "foo" };
|
|
27
|
-
const queryParam = "exampleParam";
|
|
28
|
-
|
|
29
|
-
const response = await client.test(requestBody, { param: queryParam });
|
|
30
|
-
|
|
31
|
-
expect(response).toEqual(requestBody); // Mock API expected value
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { ModelV3 } from "../../../generated/versioning/removed/src/index.js";
|
|
3
|
-
import {
|
|
4
|
-
EnumV2,
|
|
5
|
-
EnumV3,
|
|
6
|
-
RemovedClient,
|
|
7
|
-
Versions,
|
|
8
|
-
} from "../../../generated/versioning/removed/src/index.js";
|
|
9
|
-
|
|
10
|
-
describe("Versioning.Removed", () => {
|
|
11
|
-
const client = new RemovedClient("http://localhost:3000", Versions.V2, {
|
|
12
|
-
allowInsecureConnection: true,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("v2 operation", () => {
|
|
16
|
-
it("should send and receive ModelV2 with the correct signature", async () => {
|
|
17
|
-
const body = {
|
|
18
|
-
prop: "foo",
|
|
19
|
-
enumProp: EnumV2.EnumMemberV2,
|
|
20
|
-
unionProp: "bar",
|
|
21
|
-
};
|
|
22
|
-
const response = await client.v2(body as any, "");
|
|
23
|
-
expect(response).toEqual(body); // Mock API expected value
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("modelV3 operation", () => {
|
|
28
|
-
it("should handle ModelV3 for v1", async () => {
|
|
29
|
-
const client = new RemovedClient("http://localhost:3000", Versions.V1, {
|
|
30
|
-
allowInsecureConnection: true,
|
|
31
|
-
retryOptions: {
|
|
32
|
-
maxRetries: 1,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
const body: ModelV3 = {
|
|
36
|
-
id: "123",
|
|
37
|
-
enumProp: EnumV3.EnumMemberV1,
|
|
38
|
-
};
|
|
39
|
-
const response = await client.modelV3(body);
|
|
40
|
-
expect(response).toEqual(body); // Mock API expected value
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it.skip("should handle ModelV3 for v2preview", async () => {
|
|
44
|
-
const client = new RemovedClient("http://localhost:3000", Versions.V2preview, {
|
|
45
|
-
allowInsecureConnection: true,
|
|
46
|
-
retryOptions: {
|
|
47
|
-
maxRetries: 1,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const body = {
|
|
52
|
-
id: "123",
|
|
53
|
-
};
|
|
54
|
-
// Support versioning projections.s
|
|
55
|
-
const response = await client.modelV3(body as any);
|
|
56
|
-
expect(response).toEqual(body); // Mock API expected value
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should handle ModelV3 for v2", async () => {
|
|
60
|
-
const client = new RemovedClient("http://localhost:3000", Versions.V2, {
|
|
61
|
-
allowInsecureConnection: true,
|
|
62
|
-
retryOptions: {
|
|
63
|
-
maxRetries: 1,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const body = {
|
|
68
|
-
id: "123",
|
|
69
|
-
enumProp: EnumV3.EnumMemberV1,
|
|
70
|
-
};
|
|
71
|
-
const response = await client.modelV3(body);
|
|
72
|
-
expect(response).toEqual(body); // Mock API expected value
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
NewEnum,
|
|
4
|
-
NewInterfaceClient,
|
|
5
|
-
RenamedFromClient,
|
|
6
|
-
Versions,
|
|
7
|
-
} from "../../../generated/versioning/renamedFrom/src/index.js";
|
|
8
|
-
|
|
9
|
-
describe("Versioning.RenamedFrom", () => {
|
|
10
|
-
describe("RenamedFromClient", () => {
|
|
11
|
-
const client = new RenamedFromClient("http://localhost:3000", Versions.V2, {
|
|
12
|
-
allowInsecureConnection: true,
|
|
13
|
-
retryOptions: {
|
|
14
|
-
maxRetries: 1,
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should handle 'newOp' with renamed properties and return the expected response", async () => {
|
|
19
|
-
const body = {
|
|
20
|
-
enumProp: NewEnum.NewEnumMember,
|
|
21
|
-
newProp: "foo",
|
|
22
|
-
unionProp: 10,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const response = await client.newOp(body, "bar");
|
|
26
|
-
expect(response).toEqual(body); // Mock API expected to return the same body
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("NewInterfaceClient", () => {
|
|
31
|
-
const client = new NewInterfaceClient("http://localhost:3000", Versions.V2, {
|
|
32
|
-
allowInsecureConnection: true,
|
|
33
|
-
retryOptions: {
|
|
34
|
-
maxRetries: 1,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should handle 'newOpInNewInterface' with renamed properties and return the expected response", async () => {
|
|
39
|
-
const body = {
|
|
40
|
-
newProp: "foo",
|
|
41
|
-
enumProp: "newEnumMember",
|
|
42
|
-
unionProp: 10,
|
|
43
|
-
};
|
|
44
|
-
const response = await client.newOpInNewInterface({
|
|
45
|
-
enumProp: NewEnum.NewEnumMember,
|
|
46
|
-
newProp: "foo",
|
|
47
|
-
unionProp: 10,
|
|
48
|
-
});
|
|
49
|
-
expect(response).toEqual(body); // Mock API expected to return the same body
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
ReturnTypeChangedFromClient,
|
|
4
|
-
Versions,
|
|
5
|
-
} from "../../../generated/versioning/returnTypeChangedFrom/src/index.js";
|
|
6
|
-
|
|
7
|
-
// Issue with mockapi expecting plain text
|
|
8
|
-
describe.skip("Versioning.ReturnTypeChangedFrom", () => {
|
|
9
|
-
describe("TestClient", () => {
|
|
10
|
-
const client = new ReturnTypeChangedFromClient("http://localhost:3000", Versions.V2, {
|
|
11
|
-
allowInsecureConnection: true,
|
|
12
|
-
retryOptions: {
|
|
13
|
-
maxRetries: 1,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should send the request body and return the expected response body for version 'v2'", async () => {
|
|
18
|
-
const response = await client.test("test");
|
|
19
|
-
expect(response).toBe("test"); // Mock API expected value
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
TypeChangedFromClient,
|
|
4
|
-
Versions,
|
|
5
|
-
} from "../../../generated/versioning/typeChangedFrom/src/index.js";
|
|
6
|
-
|
|
7
|
-
describe("Versioning.TypeChangedFrom", () => {
|
|
8
|
-
const endpoint = "http://localhost:3000";
|
|
9
|
-
|
|
10
|
-
describe("v1", () => {
|
|
11
|
-
const client = new TypeChangedFromClient(endpoint, Versions.V2);
|
|
12
|
-
|
|
13
|
-
it("should send and receive data using v1 API signature", async () => {
|
|
14
|
-
const requestBody = { prop: "foo", changedProp: "bar" };
|
|
15
|
-
const response = await client.test(requestBody, "baz");
|
|
16
|
-
expect(response).toEqual(requestBody); // Mock API behavior
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("v2", () => {
|
|
21
|
-
const client = new TypeChangedFromClient(endpoint, Versions.V2);
|
|
22
|
-
|
|
23
|
-
it("should send and receive data using v2 API signature", async () => {
|
|
24
|
-
const requestBody = { prop: "foo", changedProp: "bar" };
|
|
25
|
-
const queryParam = "baz";
|
|
26
|
-
|
|
27
|
-
const response = await client.test(requestBody, queryParam);
|
|
28
|
-
expect(response).toEqual(requestBody); // Mock API behavior
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Should generate a model with an additional properties defined as extending a Record
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
Defines a model with Additional Properties modeled as externding a Record
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
namespace Test;
|
|
9
|
-
|
|
10
|
-
model Widget extends Record<unknown> {
|
|
11
|
-
name: string;
|
|
12
|
-
age: int32;
|
|
13
|
-
optional?: string;
|
|
14
|
-
}
|
|
15
|
-
op foo(): Widget;
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Models
|
|
19
|
-
|
|
20
|
-
Should generate a model with name `Widget` with the known properties in the root and an evelop property called `additionalProperties`
|
|
21
|
-
|
|
22
|
-
```ts src/models/models.ts interface Widget
|
|
23
|
-
export interface Widget {
|
|
24
|
-
name: string;
|
|
25
|
-
age: number;
|
|
26
|
-
optional?: string;
|
|
27
|
-
additionalProperties?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Serializer
|
|
32
|
-
|
|
33
|
-
The deserializer flattens the additional property envelope into the root of the payload
|
|
34
|
-
|
|
35
|
-
```ts src/models/internal/serializers.ts function jsonWidgetToTransportTransform
|
|
36
|
-
export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
|
|
37
|
-
if (!input_) {
|
|
38
|
-
return input_ as any;
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
...jsonRecordUnknownToTransportTransform(input_.additionalProperties),
|
|
42
|
-
name: input_.name,
|
|
43
|
-
age: input_.age,
|
|
44
|
-
optional: input_.optional,
|
|
45
|
-
}!;
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Deserializer
|
|
50
|
-
|
|
51
|
-
Deserializer puts the known properties in the root of the object and creates an additional Properties envelope.
|
|
52
|
-
|
|
53
|
-
```ts src/models/internal/serializers.ts function jsonWidgetToApplicationTransform
|
|
54
|
-
export function jsonWidgetToApplicationTransform(input_?: any): Widget {
|
|
55
|
-
if (!input_) {
|
|
56
|
-
return input_ as any;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
additionalProperties: jsonRecordUnknownToApplicationTransform(
|
|
60
|
-
(({ name, age, optional, ...rest }) => rest)(input_),
|
|
61
|
-
),
|
|
62
|
-
name: input_.name,
|
|
63
|
-
age: input_.age,
|
|
64
|
-
optional: input_.optional,
|
|
65
|
-
}!;
|
|
66
|
-
}
|
|
67
|
-
```
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# Should generate a model with an additional properties defined with model is Record<>
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
Defines a model with Additional Properties modeled as model is Record<>
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
namespace Test;
|
|
9
|
-
|
|
10
|
-
model Widget is Record<string>;
|
|
11
|
-
|
|
12
|
-
op foo(): Widget;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Models
|
|
16
|
-
|
|
17
|
-
Should not create model and treat it as a Record.
|
|
18
|
-
|
|
19
|
-
## Operation
|
|
20
|
-
|
|
21
|
-
Should just treat it as a Record
|
|
22
|
-
|
|
23
|
-
```ts src/api/testClientOperations.ts function foo
|
|
24
|
-
export async function foo(
|
|
25
|
-
client: TestClientContext,
|
|
26
|
-
options?: FooOptions,
|
|
27
|
-
): Promise<Record<string, string>> {
|
|
28
|
-
const path = parse("/").expand({});
|
|
29
|
-
const httpRequestOptions = {
|
|
30
|
-
headers: {},
|
|
31
|
-
};
|
|
32
|
-
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
33
|
-
|
|
34
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
35
|
-
options?.operationOptions?.onResponse(response);
|
|
36
|
-
}
|
|
37
|
-
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
38
|
-
return jsonRecordStringToApplicationTransform(response.body)!;
|
|
39
|
-
}
|
|
40
|
-
throw createRestError(response);
|
|
41
|
-
}
|
|
42
|
-
```
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Should generate a model with an additional properties defined as spread
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
Defines a model with Additional Properties modeled as spreading a Record
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
namespace Test;
|
|
9
|
-
|
|
10
|
-
model Widget {
|
|
11
|
-
name: string;
|
|
12
|
-
age: int32;
|
|
13
|
-
optional?: string;
|
|
14
|
-
...Record<string>;
|
|
15
|
-
}
|
|
16
|
-
op foo(): Widget;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Models
|
|
20
|
-
|
|
21
|
-
Should generate a model with name `Widget` with the known properties in the root and an evelop property called `additionalProperties`
|
|
22
|
-
|
|
23
|
-
```ts src/models/models.ts interface Widget
|
|
24
|
-
export interface Widget {
|
|
25
|
-
name: string;
|
|
26
|
-
age: number;
|
|
27
|
-
optional?: string;
|
|
28
|
-
additionalProperties?: Record<string, string>;
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Serializer
|
|
33
|
-
|
|
34
|
-
The deserializer flattens the additional property envelope into the root of the payload
|
|
35
|
-
|
|
36
|
-
```ts src/models/internal/serializers.ts function jsonWidgetToTransportTransform
|
|
37
|
-
export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
|
|
38
|
-
if (!input_) {
|
|
39
|
-
return input_ as any;
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
...jsonRecordStringToTransportTransform(input_.additionalProperties),
|
|
43
|
-
name: input_.name,
|
|
44
|
-
age: input_.age,
|
|
45
|
-
optional: input_.optional,
|
|
46
|
-
}!;
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Deserializer
|
|
51
|
-
|
|
52
|
-
Deserializer puts the known properties in the root of the object and creates an additional Properties envelope.
|
|
53
|
-
|
|
54
|
-
```ts src/models/internal/serializers.ts function jsonWidgetToApplicationTransform
|
|
55
|
-
export function jsonWidgetToApplicationTransform(input_?: any): Widget {
|
|
56
|
-
if (!input_) {
|
|
57
|
-
return input_ as any;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
additionalProperties: jsonRecordStringToApplicationTransform(
|
|
61
|
-
(({ name, age, optional, ...rest }) => rest)(input_),
|
|
62
|
-
),
|
|
63
|
-
name: input_.name,
|
|
64
|
-
age: input_.age,
|
|
65
|
-
optional: input_.optional,
|
|
66
|
-
}!;
|
|
67
|
-
}
|
|
68
|
-
```
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Handles a basic authentication scheme
|
|
2
|
-
|
|
3
|
-
This test validates that the emitter can handle a basic authentication scheme correctly, including the client signature and its initialization
|
|
4
|
-
|
|
5
|
-
## Typespec
|
|
6
|
-
|
|
7
|
-
The spec contains a simple service with a Bearer authentication scheme
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Test Service" })
|
|
11
|
-
@useAuth(BasicAuth)
|
|
12
|
-
namespace Test;
|
|
13
|
-
|
|
14
|
-
@route("/valid")
|
|
15
|
-
@get
|
|
16
|
-
op valid(): NoContentResponse;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## TypeScript
|
|
20
|
-
|
|
21
|
-
### Client
|
|
22
|
-
|
|
23
|
-
The client signature should include a positional parameter for credential of type BasicCredential. A basic auth token consists of a username and password which are concatenated with a colon and base64 encoded. The resulting string is then put into the Authorization header.
|
|
24
|
-
|
|
25
|
-
```ts src/testClient.ts class TestClient
|
|
26
|
-
export class TestClient {
|
|
27
|
-
#context: TestClientContext;
|
|
28
|
-
constructor(endpoint: string, credential: BasicCredential, options?: TestClientOptions) {
|
|
29
|
-
this.#context = createTestClientContext(endpoint, credential, options);
|
|
30
|
-
}
|
|
31
|
-
async valid(options?: ValidOptions) {
|
|
32
|
-
return valid(this.#context, options);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### ClientContext
|
|
38
|
-
|
|
39
|
-
The client context should setup the pipeline to use the credential in the Authorization header.
|
|
40
|
-
|
|
41
|
-
```ts src/api/testClientContext.ts function createTestClientContext
|
|
42
|
-
export function createTestClientContext(
|
|
43
|
-
endpoint: string,
|
|
44
|
-
credential: BasicCredential,
|
|
45
|
-
options?: TestClientOptions,
|
|
46
|
-
): TestClientContext {
|
|
47
|
-
const params: Record<string, any> = {
|
|
48
|
-
endpoint: endpoint,
|
|
49
|
-
};
|
|
50
|
-
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
51
|
-
key in params
|
|
52
|
-
? String(params[key])
|
|
53
|
-
: (() => {
|
|
54
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
55
|
-
})(),
|
|
56
|
-
);
|
|
57
|
-
return getClient(resolvedEndpoint, {
|
|
58
|
-
...options,
|
|
59
|
-
credential,
|
|
60
|
-
authSchemes: [
|
|
61
|
-
{
|
|
62
|
-
kind: "http",
|
|
63
|
-
scheme: "basic",
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
```
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Handles a simple bearer authentication scheme
|
|
2
|
-
|
|
3
|
-
This test validates that the emitter can handle a simple bearer authentication scheme correctly, including the client signature and its initialization
|
|
4
|
-
|
|
5
|
-
## Typespec
|
|
6
|
-
|
|
7
|
-
The spec contains a simple service with a Bearer authentication scheme
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Test Service" })
|
|
11
|
-
@useAuth(BearerAuth)
|
|
12
|
-
namespace Test;
|
|
13
|
-
|
|
14
|
-
@route("/valid")
|
|
15
|
-
@get
|
|
16
|
-
op valid(): NoContentResponse;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## TypeScript
|
|
20
|
-
|
|
21
|
-
### Client
|
|
22
|
-
|
|
23
|
-
The client signature should include a positional parameter for credential of type BearerTokenCredential. A Bearer token is a token credential that gets put into the Authorization header
|
|
24
|
-
|
|
25
|
-
```ts src/testClient.ts class TestClient
|
|
26
|
-
export class TestClient {
|
|
27
|
-
#context: TestClientContext;
|
|
28
|
-
constructor(endpoint: string, credential: BasicCredential, options?: TestClientOptions) {
|
|
29
|
-
this.#context = createTestClientContext(endpoint, credential, options);
|
|
30
|
-
}
|
|
31
|
-
async valid(options?: ValidOptions) {
|
|
32
|
-
return valid(this.#context, options);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### ClientContext
|
|
38
|
-
|
|
39
|
-
The client context should setup the pipeline to use the credential in the Authorization header.
|
|
40
|
-
|
|
41
|
-
```ts src/api/testClientContext.ts function createTestClientContext
|
|
42
|
-
export function createTestClientContext(
|
|
43
|
-
endpoint: string,
|
|
44
|
-
credential: BasicCredential,
|
|
45
|
-
options?: TestClientOptions,
|
|
46
|
-
): TestClientContext {
|
|
47
|
-
const params: Record<string, any> = {
|
|
48
|
-
endpoint: endpoint,
|
|
49
|
-
};
|
|
50
|
-
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
51
|
-
key in params
|
|
52
|
-
? String(params[key])
|
|
53
|
-
: (() => {
|
|
54
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
55
|
-
})(),
|
|
56
|
-
);
|
|
57
|
-
return getClient(resolvedEndpoint, {
|
|
58
|
-
...options,
|
|
59
|
-
credential,
|
|
60
|
-
authSchemes: [
|
|
61
|
-
{
|
|
62
|
-
kind: "http",
|
|
63
|
-
scheme: "bearer",
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
```
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Handle multiple auth schemas
|
|
2
|
-
|
|
3
|
-
This test validates that the emitter can generate the correct client signature when more than one schema is used.
|
|
4
|
-
|
|
5
|
-
## Typespec
|
|
6
|
-
|
|
7
|
-
The spec contains 2 Schemas Bearer and ApiKey
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Test Service" })
|
|
11
|
-
@useAuth(BearerAuth | ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
|
|
12
|
-
namespace Test;
|
|
13
|
-
|
|
14
|
-
@route("/valid")
|
|
15
|
-
@get
|
|
16
|
-
op valid(): NoContentResponse;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## TypeScript
|
|
20
|
-
|
|
21
|
-
### Client
|
|
22
|
-
|
|
23
|
-
The client signature should include a positional parameter for credential of type KeyCredential. Internally both translate to the same type KeyCredential.
|
|
24
|
-
TODO: Revisit if we need additional types since it will be difficult at runtime to differentiate
|
|
25
|
-
|
|
26
|
-
```ts src/testClient.ts class TestClient
|
|
27
|
-
export class TestClient {
|
|
28
|
-
#context: TestClientContext;
|
|
29
|
-
constructor(
|
|
30
|
-
endpoint: string,
|
|
31
|
-
credential: BearerTokenCredential | ApiKeyCredential,
|
|
32
|
-
options?: TestClientOptions,
|
|
33
|
-
) {
|
|
34
|
-
this.#context = createTestClientContext(endpoint, credential, options);
|
|
35
|
-
}
|
|
36
|
-
async valid(options?: ValidOptions) {
|
|
37
|
-
return valid(this.#context, options);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### ClientContext
|
|
43
|
-
|
|
44
|
-
The client context should setup the pipeline to use the credential in the Authorization header.
|
|
45
|
-
|
|
46
|
-
```ts src/api/testClientContext.ts function createTestClientContext
|
|
47
|
-
export function createTestClientContext(
|
|
48
|
-
endpoint: string,
|
|
49
|
-
credential: BearerTokenCredential | ApiKeyCredential,
|
|
50
|
-
options?: TestClientOptions,
|
|
51
|
-
): TestClientContext {
|
|
52
|
-
const params: Record<string, any> = {
|
|
53
|
-
endpoint: endpoint,
|
|
54
|
-
};
|
|
55
|
-
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
56
|
-
key in params
|
|
57
|
-
? String(params[key])
|
|
58
|
-
: (() => {
|
|
59
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
60
|
-
})(),
|
|
61
|
-
);
|
|
62
|
-
return getClient(resolvedEndpoint, {
|
|
63
|
-
...options,
|
|
64
|
-
credential,
|
|
65
|
-
authSchemes: [
|
|
66
|
-
{
|
|
67
|
-
kind: "http",
|
|
68
|
-
scheme: "bearer",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
kind: "apiKey",
|
|
72
|
-
apiKeyLocation: "header",
|
|
73
|
-
name: "X-API-KEY",
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
```
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# The presence of @useAuth decorator shouldn't impact the client hierarchy
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service(#{ title: "My API" })
|
|
7
|
-
@useAuth(BearerAuth)
|
|
8
|
-
namespace MyApi;
|
|
9
|
-
|
|
10
|
-
@route("/foo")
|
|
11
|
-
namespace Foo {
|
|
12
|
-
@get op getfoo(): string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@route("/bar")
|
|
16
|
-
namespace Bar {
|
|
17
|
-
@get op getBar(): string;
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## TypeScript
|
|
22
|
-
|
|
23
|
-
The client structure should be MyApi class with no operations and 2 members, BarClient and FooClient.
|
|
24
|
-
|
|
25
|
-
```ts src/myApiClient.ts class MyApiClient
|
|
26
|
-
export class MyApiClient {
|
|
27
|
-
#context: MyApiClientContext;
|
|
28
|
-
fooClient: FooClient;
|
|
29
|
-
barClient: BarClient;
|
|
30
|
-
constructor(endpoint: string, credential: BasicCredential, options?: MyApiClientOptions) {
|
|
31
|
-
this.#context = createMyApiClientContext(endpoint, credential, options);
|
|
32
|
-
this.fooClient = new FooClient(endpoint, credential, options);
|
|
33
|
-
this.barClient = new BarClient(endpoint, credential, options);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
```
|