@typespec/http-client-js 0.1.0
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/.testignore +2 -0
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/babel.config.js +4 -0
- package/dist/src/components/client-context/client-context-declaration.d.ts +8 -0
- package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-declaration.js +21 -0
- package/dist/src/components/client-context/client-context-declaration.js.map +1 -0
- package/dist/src/components/client-context/client-context-factory.d.ts +8 -0
- package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-factory.js +154 -0
- package/dist/src/components/client-context/client-context-factory.js.map +1 -0
- package/dist/src/components/client-context/client-context-options.d.ts +8 -0
- package/dist/src/components/client-context/client-context-options.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context-options.js +42 -0
- package/dist/src/components/client-context/client-context-options.js.map +1 -0
- package/dist/src/components/client-context/client-context.d.ts +8 -0
- package/dist/src/components/client-context/client-context.d.ts.map +1 -0
- package/dist/src/components/client-context/client-context.js +33 -0
- package/dist/src/components/client-context/client-context.js.map +1 -0
- package/dist/src/components/client-context/parametrized-endpoint.d.ts +9 -0
- package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -0
- package/dist/src/components/client-context/parametrized-endpoint.js +48 -0
- package/dist/src/components/client-context/parametrized-endpoint.js.map +1 -0
- package/dist/src/components/client-directory.d.ts +11 -0
- package/dist/src/components/client-directory.d.ts.map +1 -0
- package/dist/src/components/client-directory.js +39 -0
- package/dist/src/components/client-directory.js.map +1 -0
- package/dist/src/components/client-operation.d.ts +11 -0
- package/dist/src/components/client-operation.d.ts.map +1 -0
- package/dist/src/components/client-operation.js +74 -0
- package/dist/src/components/client-operation.js.map +1 -0
- package/dist/src/components/client.d.ts +15 -0
- package/dist/src/components/client.d.ts.map +1 -0
- package/dist/src/components/client.js +153 -0
- package/dist/src/components/client.js.map +1 -0
- package/dist/src/components/encoding-provider.d.ts +8 -0
- package/dist/src/components/encoding-provider.d.ts.map +1 -0
- package/dist/src/components/encoding-provider.js +17 -0
- package/dist/src/components/encoding-provider.js.map +1 -0
- package/dist/src/components/external-packages/ts-http-runtime.d.ts +13 -0
- package/dist/src/components/external-packages/ts-http-runtime.d.ts.map +1 -0
- package/dist/src/components/external-packages/ts-http-runtime.js +11 -0
- package/dist/src/components/external-packages/ts-http-runtime.js.map +1 -0
- package/dist/src/components/external-packages/uri-template.d.ts +4 -0
- package/dist/src/components/external-packages/uri-template.d.ts.map +1 -0
- package/dist/src/components/external-packages/uri-template.js +11 -0
- package/dist/src/components/external-packages/uri-template.js.map +1 -0
- package/dist/src/components/http-request-options.d.ts +25 -0
- package/dist/src/components/http-request-options.d.ts.map +1 -0
- package/dist/src/components/http-request-options.js +74 -0
- package/dist/src/components/http-request-options.js.map +1 -0
- package/dist/src/components/http-request-parameters-expression.d.ts +10 -0
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -0
- package/dist/src/components/http-request-parameters-expression.js +62 -0
- package/dist/src/components/http-request-parameters-expression.js.map +1 -0
- package/dist/src/components/http-request.d.ts +16 -0
- package/dist/src/components/http-request.d.ts.map +1 -0
- package/dist/src/components/http-request.js +70 -0
- package/dist/src/components/http-request.js.map +1 -0
- package/dist/src/components/http-response.d.ts +14 -0
- package/dist/src/components/http-response.d.ts.map +1 -0
- package/dist/src/components/http-response.js +61 -0
- package/dist/src/components/http-response.js.map +1 -0
- package/dist/src/components/models.d.ts +5 -0
- package/dist/src/components/models.d.ts.map +1 -0
- package/dist/src/components/models.js +41 -0
- package/dist/src/components/models.js.map +1 -0
- package/dist/src/components/operation-options.d.ts +8 -0
- package/dist/src/components/operation-options.d.ts.map +1 -0
- package/dist/src/components/operation-options.js +41 -0
- package/dist/src/components/operation-options.js.map +1 -0
- package/dist/src/components/operation-parameters.d.ts +9 -0
- package/dist/src/components/operation-parameters.d.ts.map +1 -0
- package/dist/src/components/operation-parameters.js +33 -0
- package/dist/src/components/operation-parameters.js.map +1 -0
- package/dist/src/components/output.d.ts +6 -0
- package/dist/src/components/output.d.ts.map +1 -0
- package/dist/src/components/output.js +35 -0
- package/dist/src/components/output.js.map +1 -0
- package/dist/src/components/serializers.d.ts +5 -0
- package/dist/src/components/serializers.d.ts.map +1 -0
- package/dist/src/components/serializers.js +43 -0
- package/dist/src/components/serializers.js.map +1 -0
- package/dist/src/components/static-helpers/bytes-encoding.d.ts +6 -0
- package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -0
- package/dist/src/components/static-helpers/bytes-encoding.js +68 -0
- package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -0
- package/dist/src/components/static-helpers/interfaces.d.ts +5 -0
- package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -0
- package/dist/src/components/static-helpers/interfaces.js +41 -0
- package/dist/src/components/static-helpers/interfaces.js.map +1 -0
- package/dist/src/components/static-helpers/multipart-helpers.d.ts +8 -0
- package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -0
- package/dist/src/components/static-helpers/multipart-helpers.js +83 -0
- package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -0
- package/dist/src/components/static-helpers/rest-error.d.ts +5 -0
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -0
- package/dist/src/components/static-helpers/rest-error.js +127 -0
- package/dist/src/components/static-helpers/rest-error.js.map +1 -0
- package/dist/src/components/testing/client-options.d.ts +8 -0
- package/dist/src/components/testing/client-options.d.ts.map +1 -0
- package/dist/src/components/testing/client-options.js +27 -0
- package/dist/src/components/testing/client-options.js.map +1 -0
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts +7 -0
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -0
- package/dist/src/components/transforms/content-type-encoding-provider.js +25 -0
- package/dist/src/components/transforms/content-type-encoding-provider.js.map +1 -0
- package/dist/src/components/transforms/data-transform.d.ts +9 -0
- package/dist/src/components/transforms/data-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/data-transform.js +31 -0
- package/dist/src/components/transforms/data-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-array-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-array-transform.js +71 -0
- package/dist/src/components/transforms/json/json-array-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +35 -0
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-base-transform.js +13 -0
- package/dist/src/components/transforms/json/json-model-base-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts +9 -0
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-property-transform.js +44 -0
- package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-model-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-model-transform.js +96 -0
- package/dist/src/components/transforms/json/json-model-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-record-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-record-transform.js +71 -0
- package/dist/src/components/transforms/json/json-record-transform.js.map +1 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts +16 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.js +82 -0
- package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -0
- package/dist/src/components/transforms/json/json-transform.d.ts +14 -0
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/json-transform.js +149 -0
- package/dist/src/components/transforms/json/json-transform.js.map +1 -0
- package/dist/src/components/transforms/json/union-transform.d.ts +15 -0
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/json/union-transform.js +67 -0
- package/dist/src/components/transforms/json/union-transform.js.map +1 -0
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts +3 -0
- package/dist/src/components/transforms/json/utils/transport-namer.d.ts.map +1 -0
- package/dist/src/components/transforms/json/utils/transport-namer.js +13 -0
- package/dist/src/components/transforms/json/utils/transport-namer.js.map +1 -0
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/array-part-transform.js +29 -0
- package/dist/src/components/transforms/multipart/array-part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/file-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/file-part-transform.js +40 -0
- package/dist/src/components/transforms/multipart/file-part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts +7 -0
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/multipart-transform.js +26 -0
- package/dist/src/components/transforms/multipart/multipart-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/part-transform.js +35 -0
- package/dist/src/components/transforms/multipart/part-transform.js.map +1 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts +8 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.js +48 -0
- package/dist/src/components/transforms/multipart/simple-part-transform.js.map +1 -0
- package/dist/src/components/transforms/operation-transform-declaration.d.ts +17 -0
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -0
- package/dist/src/components/transforms/operation-transform-declaration.js +74 -0
- package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -0
- package/dist/src/components/transforms/operation-transform-expression.d.ts +6 -0
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -0
- package/dist/src/components/transforms/operation-transform-expression.js +60 -0
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -0
- package/dist/src/components/transforms/scalar-transform.d.ts +15 -0
- package/dist/src/components/transforms/scalar-transform.d.ts.map +1 -0
- package/dist/src/components/transforms/scalar-transform.js +317 -0
- package/dist/src/components/transforms/scalar-transform.js.map +1 -0
- package/dist/src/components/transforms/transform-name-policy.d.ts +71 -0
- package/dist/src/components/transforms/transform-name-policy.d.ts.map +1 -0
- package/dist/src/components/transforms/transform-name-policy.js +111 -0
- package/dist/src/components/transforms/transform-name-policy.js.map +1 -0
- package/dist/src/components/utils/unpack-model-property.d.ts +8 -0
- package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -0
- package/dist/src/components/utils/unpack-model-property.js +33 -0
- package/dist/src/components/utils/unpack-model-property.js.map +1 -0
- package/dist/src/components/utils/url-template.d.ts +7 -0
- package/dist/src/components/utils/url-template.d.ts.map +1 -0
- package/dist/src/components/utils/url-template.js +23 -0
- package/dist/src/components/utils/url-template.js.map +1 -0
- package/dist/src/context/encoding/encoding-context.d.ts +6 -0
- package/dist/src/context/encoding/encoding-context.d.ts.map +1 -0
- package/dist/src/context/encoding/encoding-context.js +20 -0
- package/dist/src/context/encoding/encoding-context.js.map +1 -0
- package/dist/src/context/encoding/types.d.ts +6 -0
- package/dist/src/context/encoding/types.d.ts.map +1 -0
- package/dist/src/context/encoding/types.js +1 -0
- package/dist/src/context/encoding/types.js.map +1 -0
- package/dist/src/emitter.d.ts +8 -0
- package/dist/src/emitter.d.ts.map +1 -0
- package/dist/src/emitter.js +68 -0
- package/dist/src/emitter.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +206 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +107 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +8 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/utils/client-discovery.d.ts +7 -0
- package/dist/src/utils/client-discovery.d.ts.map +1 -0
- package/dist/src/utils/client-discovery.js +26 -0
- package/dist/src/utils/client-discovery.js.map +1 -0
- package/dist/src/utils/multipart.d.ts +3 -0
- package/dist/src/utils/multipart.d.ts.map +1 -0
- package/dist/src/utils/multipart.js +26 -0
- package/dist/src/utils/multipart.js.map +1 -0
- package/dist/src/utils/operations.d.ts +3 -0
- package/dist/src/utils/operations.d.ts.map +1 -0
- package/dist/src/utils/operations.js +11 -0
- package/dist/src/utils/operations.js.map +1 -0
- package/dist/src/utils/parameters.d.ts +14 -0
- package/dist/src/utils/parameters.d.ts.map +1 -0
- package/dist/src/utils/parameters.js +98 -0
- package/dist/src/utils/parameters.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/eng/scripts/calculate-coverage.js +36 -0
- package/eng/scripts/emit-e2e.js +329 -0
- package/eng/scripts/run-e2e-tests.js +162 -0
- package/eng/scripts/tspconfig.yaml +6 -0
- package/eng/scripts/upload-spector-results.js +120 -0
- package/package.json +83 -0
- package/src/components/client-context/client-context-declaration.tsx +19 -0
- package/src/components/client-context/client-context-factory.tsx +142 -0
- package/src/components/client-context/client-context-options.tsx +28 -0
- package/src/components/client-context/client-context.tsx +21 -0
- package/src/components/client-context/parametrized-endpoint.tsx +39 -0
- package/src/components/client-directory.tsx +40 -0
- package/src/components/client-operation.tsx +52 -0
- package/src/components/client.tsx +137 -0
- package/src/components/encoding-provider.tsx +19 -0
- package/src/components/external-packages/ts-http-runtime.ts +22 -0
- package/src/components/external-packages/uri-template.ts +11 -0
- package/src/components/http-request-options.tsx +69 -0
- package/src/components/http-request-parameters-expression.tsx +69 -0
- package/src/components/http-request.tsx +58 -0
- package/src/components/http-response.tsx +68 -0
- package/src/components/models.tsx +29 -0
- package/src/components/operation-options.tsx +26 -0
- package/src/components/operation-parameters.tsx +43 -0
- package/src/components/output.tsx +26 -0
- package/src/components/serializers.tsx +47 -0
- package/src/components/static-helpers/bytes-encoding.tsx +41 -0
- package/src/components/static-helpers/interfaces.tsx +26 -0
- package/src/components/static-helpers/multipart-helpers.tsx +59 -0
- package/src/components/static-helpers/rest-error.tsx +61 -0
- package/src/components/testing/client-options.tsx +32 -0
- package/src/components/transforms/content-type-encoding-provider.tsx +28 -0
- package/src/components/transforms/data-transform.tsx +39 -0
- package/src/components/transforms/json/json-array-transform.tsx +83 -0
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +47 -0
- package/src/components/transforms/json/json-model-base-transform.tsx +19 -0
- package/src/components/transforms/json/json-model-property-transform.tsx +41 -0
- package/src/components/transforms/json/json-model-transform.tsx +87 -0
- package/src/components/transforms/json/json-record-transform.tsx +84 -0
- package/src/components/transforms/json/json-transform-discriminator.tsx +114 -0
- package/src/components/transforms/json/json-transform.tsx +113 -0
- package/src/components/transforms/json/union-transform.tsx +73 -0
- package/src/components/transforms/json/utils/transport-namer.ts +12 -0
- package/src/components/transforms/multipart/array-part-transform.tsx +40 -0
- package/src/components/transforms/multipart/file-part-transform.tsx +44 -0
- package/src/components/transforms/multipart/multipart-transform.tsx +32 -0
- package/src/components/transforms/multipart/part-transform.tsx +22 -0
- package/src/components/transforms/multipart/simple-part-transform.tsx +49 -0
- package/src/components/transforms/operation-transform-declaration.tsx +64 -0
- package/src/components/transforms/operation-transform-expression.tsx +54 -0
- package/src/components/transforms/scalar-transform.tsx +289 -0
- package/src/components/transforms/transform-name-policy.ts +133 -0
- package/src/components/utils/unpack-model-property.ts +31 -0
- package/src/components/utils/url-template.tsx +21 -0
- package/src/context/encoding/encoding-context.tsx +26 -0
- package/src/context/encoding/types.ts +6 -0
- package/src/emitter.tsx +53 -0
- package/src/index.ts +5 -0
- package/src/lib.ts +108 -0
- package/src/testing/index.ts +8 -0
- package/src/utils/client-discovery.ts +28 -0
- package/src/utils/multipart.ts +28 -0
- package/src/utils/operations.ts +14 -0
- package/src/utils/parameters.tsx +129 -0
- 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 +38 -0
- package/test/e2e/http/authentication/oauth2/main.test.ts +41 -0
- package/test/e2e/http/authentication/union/main.test.ts +29 -0
- package/test/e2e/http/encode/bytes/main.test.ts +191 -0
- package/test/e2e/http/encode/datetime/main.test.ts +176 -0
- package/test/e2e/http/encode/duration/main.test.ts +126 -0
- package/test/e2e/http/encode/numeric/main.test.ts +26 -0
- package/test/e2e/http/parameters/basic/main.test.ts +35 -0
- package/test/e2e/http/parameters/body-optionality/main.test.ts +43 -0
- package/test/e2e/http/parameters/collection-format/main.test.ts +45 -0
- package/test/e2e/http/parameters/spread/main.test.ts +56 -0
- package/test/e2e/http/payload/content-negotiation/main.test.ts +40 -0
- package/test/e2e/http/payload/json-merge-patch/main.test.ts +122 -0
- package/test/e2e/http/payload/media-type/main.test.ts +28 -0
- package/test/e2e/http/payload/multipart/main.test.ts +164 -0
- package/test/e2e/http/payload/pageable/main.test.ts +24 -0
- package/test/e2e/http/payload/xml/main.test.ts +287 -0
- package/test/e2e/http/routes/main.test.ts +284 -0
- package/test/e2e/http/serialization/encoded-name/json/main.test.ts +20 -0
- package/test/e2e/http/server/endpoint/not-defined/main.test.ts +11 -0
- package/test/e2e/http/server/path/multiple/main.test.ts +22 -0
- package/test/e2e/http/server/path/single/main.test.ts +11 -0
- package/test/e2e/http/server/versions/not-versioned/main.test.ts +22 -0
- package/test/e2e/http/server/versions/versioned/main.test.ts +28 -0
- package/test/e2e/http/special-headers/conditional-request/main.test.ts +35 -0
- package/test/e2e/http/special-headers/repeatability/main.test.ts +18 -0
- package/test/e2e/http/special-words/main.test.ts +434 -0
- package/test/e2e/http/type/array/array.test.ts +256 -0
- package/test/e2e/http/type/dictionary/main.test.ts +229 -0
- package/test/e2e/http/type/enum/extensible/main.test.ts +34 -0
- package/test/e2e/http/type/enum/fixed/main.test.ts +29 -0
- package/test/e2e/http/type/model/empty/main.test.ts +21 -0
- package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +51 -0
- package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +168 -0
- package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +42 -0
- package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +46 -0
- package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +101 -0
- package/test/e2e/http/type/model/visibility/main.test.ts +64 -0
- package/test/e2e/http/type/property/additional-properties/main.test.ts +185 -0
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +470 -0
- package/test/e2e/http/type/property/nullable/main.test.ts +275 -0
- package/test/e2e/http/type/property/optionality/main.test.ts +256 -0
- package/test/e2e/http/type/property/value-types/main.test.ts +193 -0
- package/test/e2e/http/type/scalar/main.test.ts +133 -0
- package/test/e2e/http/type/scalar/scalar.test.ts +95 -0
- package/test/e2e/http/type/union/main.test.ts +207 -0
- package/test/e2e/http/versioning/added/main.test.ts +61 -0
- package/test/e2e/http/versioning/madeOptional/main.test.ts +34 -0
- package/test/e2e/http/versioning/removed/main.test.ts +75 -0
- package/test/e2e/http/versioning/renamedFrom/main.test.ts +52 -0
- package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +22 -0
- package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +31 -0
- package/test/scenarios/additional-properties/extends.md +71 -0
- package/test/scenarios/additional-properties/is.md +46 -0
- package/test/scenarios/additional-properties/spread.md +72 -0
- package/test/scenarios/auth/basic_auth.md +67 -0
- package/test/scenarios/auth/bearer.md +67 -0
- package/test/scenarios/auth/client_parameters.md +68 -0
- package/test/scenarios/auth/client_structure.md +38 -0
- package/test/scenarios/auth/key_credential.md +67 -0
- package/test/scenarios/auth/sub_client_override.md +114 -0
- package/test/scenarios/client/client_context.md +36 -0
- package/test/scenarios/client/dotted_namespace.md +30 -0
- package/test/scenarios/client/global_namespace.md +74 -0
- package/test/scenarios/client/multiple_top_level_clients.md +74 -0
- package/test/scenarios/client/nested_client.md +106 -0
- package/test/scenarios/client/wrapping_namespace.md +43 -0
- package/test/scenarios/encoding/bytes_body.md +48 -0
- package/test/scenarios/encoding/bytes_json_property.md +60 -0
- package/test/scenarios/encoding/bytes_nullable.md +153 -0
- package/test/scenarios/encoding/header_bytes.md +142 -0
- package/test/scenarios/encoding/header_date.md +236 -0
- package/test/scenarios/encoding/model_with_bytes_property.md +50 -0
- package/test/scenarios/encoding/query_bytes.md +46 -0
- package/test/scenarios/encoding/query_date.md +236 -0
- package/test/scenarios/http-operations/basic-request.md +162 -0
- package/test/scenarios/http-operations/basic-response.md +246 -0
- package/test/scenarios/http-operations/basic.md +134 -0
- package/test/scenarios/http-operations/constant-header.md +37 -0
- package/test/scenarios/http-operations/create-operation.md +62 -0
- package/test/scenarios/http-operations/on_response.md +56 -0
- package/test/scenarios/http-operations/optional-request-body.md +55 -0
- package/test/scenarios/http-operations/path-parameter-in-model.md +59 -0
- package/test/scenarios/http-operations/path-parameter.md +54 -0
- package/test/scenarios/http-operations/scalar-payload.md +63 -0
- package/test/scenarios/http-operations/with-parameters.md +85 -0
- package/test/scenarios/models/array-properties.md +47 -0
- package/test/scenarios/models/basic.md +118 -0
- package/test/scenarios/models/dictionary-properties.md +44 -0
- package/test/scenarios/models/inheritance_2_discriminators.md +370 -0
- package/test/scenarios/models/inheritance_discriminator.md +92 -0
- package/test/scenarios/models/inline-models.md +29 -0
- package/test/scenarios/models/model_additional_properties.md +79 -0
- package/test/scenarios/models/model_extends.md +101 -0
- package/test/scenarios/models/model_spread.md +65 -0
- package/test/scenarios/models/nested_property.md +45 -0
- package/test/scenarios/models/property_references_property.md +156 -0
- package/test/scenarios/multipart/anonymous_part.md +57 -0
- package/test/scenarios/multipart/file.md +166 -0
- package/test/scenarios/multipart/file_content_type.md +67 -0
- package/test/scenarios/multipart/simple_part.md +69 -0
- package/test/scenarios/operation-parameters/body_root_anonymous.md +92 -0
- package/test/scenarios/operation-parameters/constant_as_optional.md +59 -0
- package/test/scenarios/operation-parameters/default_value_as_optional.md +59 -0
- package/test/scenarios/operation-parameters/no_content_type.md +67 -0
- package/test/scenarios/operation-parameters/no_parameters.md +55 -0
- package/test/scenarios/operation-parameters/only_optional.md +67 -0
- package/test/scenarios/operation-parameters/only_required.md +63 -0
- package/test/scenarios/operation-parameters/reserved_names.md +65 -0
- package/test/scenarios/operation-parameters/spread_body.md +75 -0
- package/test/scenarios/operation-parameters/spread_with_nested.md +87 -0
- package/test/scenarios/operation-parameters/union_body.md +92 -0
- package/test/scenarios/operation-parameters/with_body_property.md +72 -0
- package/test/scenarios/operation-parameters/with_body_root.md +74 -0
- package/test/scenarios/serializers/arrays.md +199 -0
- package/test/scenarios/serializers/basic_model.md +115 -0
- package/test/scenarios/serializers/basic_model_wire_name.md +50 -0
- package/test/scenarios/serializers/discriminated_union.md +86 -0
- package/test/scenarios/serializers/discriminated_union_spread.md +119 -0
- package/test/scenarios/serializers/model_date_time.md +65 -0
- package/test/scenarios/serializers/multipart.md +66 -0
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +164 -0
- package/test/scenarios/serializers/record.md +101 -0
- package/test/scenarios/serializers/scalars.md +33 -0
- package/test/scenarios/serializers/spread.md +75 -0
- package/test/scenarios/serializers/string_union.md +61 -0
- package/test/scenarios/server/default_url.md +45 -0
- package/test/scenarios/server/multiple-parameters.md +57 -0
- package/test/scenarios/server/no-server.md +37 -0
- package/test/scenarios/server/parametrized-endpoint.md +53 -0
- package/test/scenarios.test.ts +18 -0
- package/test/test-host.ts +76 -0
- package/tsconfig.json +16 -0
- package/tsconfig.test.json +7 -0
- package/vitest.config.js +23 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# **Generating a Basic HTTP Operation**
|
|
2
|
+
|
|
3
|
+
This test verifies that a simple HTTP `GET` operation with no request payload or parameters correctly generates a **client class, model, serializer, context, and operation function**. The operation returns a `Widget` model, ensuring proper TypeScript type generation and serialization.
|
|
4
|
+
|
|
5
|
+
## **TypeSpec**
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service
|
|
9
|
+
namespace Test;
|
|
10
|
+
model Widget {
|
|
11
|
+
id: string;
|
|
12
|
+
total_weight: int32;
|
|
13
|
+
color: "red" | "blue";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
op foo(): Widget;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## **TypeScript**
|
|
20
|
+
|
|
21
|
+
### **Client Generation**
|
|
22
|
+
|
|
23
|
+
A class named `TestClient` is generated, encapsulating API operations. It includes a single method, `foo`, which internally calls the corresponding operation function.
|
|
24
|
+
|
|
25
|
+
```ts src/testClient.ts
|
|
26
|
+
import { FooOptions, foo } from "./api/testClientOperations.js";
|
|
27
|
+
import {
|
|
28
|
+
TestClientContext,
|
|
29
|
+
TestClientOptions,
|
|
30
|
+
createTestClientContext,
|
|
31
|
+
} from "./api/testClientContext.js";
|
|
32
|
+
|
|
33
|
+
export class TestClient {
|
|
34
|
+
#context: TestClientContext;
|
|
35
|
+
|
|
36
|
+
constructor(endpoint: string, options?: TestClientOptions) {
|
|
37
|
+
this.#context = createTestClientContext(endpoint, options);
|
|
38
|
+
}
|
|
39
|
+
async foo(options?: FooOptions) {
|
|
40
|
+
return foo(this.#context, options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### **Model Definition**
|
|
46
|
+
|
|
47
|
+
A TypeScript interface for the `Widget` model is generated in `src/models/models.ts`. The field `total_weight` is renamed to `totalWeight` to align with TypeScript naming conventions.
|
|
48
|
+
|
|
49
|
+
```ts src/models/models.ts interface Widget
|
|
50
|
+
export interface Widget {
|
|
51
|
+
id: string;
|
|
52
|
+
totalWeight: number;
|
|
53
|
+
color: "red" | "blue";
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### **Serializer Generation**
|
|
58
|
+
|
|
59
|
+
A serializer function, `jsonWidgetToTransportTransform`, is generated to transform the `Widget` model into its transport format. It converts TypeScript-friendly property names (`totalWeight`) back to their wire format (`total_weight`).
|
|
60
|
+
|
|
61
|
+
```ts src/models/serializers.ts function jsonWidgetToTransportTransform
|
|
62
|
+
export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
|
|
63
|
+
if (!input_) {
|
|
64
|
+
return input_ as any;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
id: input_.id,
|
|
69
|
+
total_weight: input_.totalWeight,
|
|
70
|
+
color: input_.color,
|
|
71
|
+
}!;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### **Context Generation**
|
|
76
|
+
|
|
77
|
+
The generated `createTestClientContext` function initializes the API client context with the required endpoint. Since no authentication or additional parameters are used, only the endpoint is required.
|
|
78
|
+
|
|
79
|
+
```ts src/api/testClientContext.ts function createTestClientContext
|
|
80
|
+
export function createTestClientContext(
|
|
81
|
+
endpoint: string,
|
|
82
|
+
options?: TestClientOptions,
|
|
83
|
+
): TestClientContext {
|
|
84
|
+
const params: Record<string, any> = {
|
|
85
|
+
endpoint: endpoint,
|
|
86
|
+
};
|
|
87
|
+
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
88
|
+
key in params
|
|
89
|
+
? String(params[key])
|
|
90
|
+
: (() => {
|
|
91
|
+
throw new Error(`Missing parameter: ${key}`);
|
|
92
|
+
})(),
|
|
93
|
+
);
|
|
94
|
+
return getClient(resolvedEndpoint, {
|
|
95
|
+
...options,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
An interface, `TestClientContext`, is also generated to define the shape of the context.
|
|
101
|
+
|
|
102
|
+
```ts src/api/testClientContext.ts interface TestClientContext
|
|
103
|
+
export interface TestClientContext extends Client {}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### **Operation Function**
|
|
107
|
+
|
|
108
|
+
A function named `foo` is generated to handle the HTTP request. It prepares the request, sends it using the client context, and processes the response.
|
|
109
|
+
|
|
110
|
+
- The request has **no query, path, or header parameters**.
|
|
111
|
+
- The expected response body is a `Widget`, requiring transformation from wire format using `jsonWidgetToApplication`.
|
|
112
|
+
- If the response status code is unexpected, an exception is thrown.
|
|
113
|
+
|
|
114
|
+
```ts src/api/testClientOperations.ts function foo
|
|
115
|
+
export async function foo(client: TestClientContext, options?: FooOptions): Promise<Widget> {
|
|
116
|
+
const path = parse("/").expand({});
|
|
117
|
+
|
|
118
|
+
const httpRequestOptions = {
|
|
119
|
+
headers: {},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
123
|
+
|
|
124
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
125
|
+
options?.operationOptions?.onResponse(response);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
129
|
+
return jsonWidgetToApplicationTransform(response.body)!;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw createRestError(response);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Should handle when provided a constant header
|
|
2
|
+
|
|
3
|
+
```tsp
|
|
4
|
+
@service
|
|
5
|
+
namespace Test;
|
|
6
|
+
model Foo {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@get op foo(@header accept: "application/xml"): Foo;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Operation
|
|
14
|
+
|
|
15
|
+
```ts src/api/testClientOperations.ts function foo
|
|
16
|
+
export async function foo(client: TestClientContext, options?: FooOptions): Promise<Foo> {
|
|
17
|
+
const path = parse("/").expand({});
|
|
18
|
+
|
|
19
|
+
const httpRequestOptions = {
|
|
20
|
+
headers: {
|
|
21
|
+
accept: options?.accept ?? "application/xml",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
26
|
+
|
|
27
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
28
|
+
options?.operationOptions?.onResponse(response);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
32
|
+
return jsonFooToApplicationTransform(response.body)!;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw createRestError(response);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Should generate a basic create http operation
|
|
2
|
+
|
|
3
|
+
This is a simple get operation with no request payload or parameters and a simple model return.
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service
|
|
9
|
+
namespace Test;
|
|
10
|
+
model Widget {
|
|
11
|
+
id: string;
|
|
12
|
+
total_weight: int32;
|
|
13
|
+
color: "red" | "blue";
|
|
14
|
+
is_required?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@post op foo(...Widget): void;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## TypeScript
|
|
21
|
+
|
|
22
|
+
### Operation
|
|
23
|
+
|
|
24
|
+
Generates the operation function which prepares the request options. In this case it has not query, path or header parameters. No body either so headers is empty.
|
|
25
|
+
|
|
26
|
+
The response body is of type Widget so the right transform should be imported to transform the widget from its wire format to the application form.
|
|
27
|
+
|
|
28
|
+
It should throw an exception if an unexpected status code is received
|
|
29
|
+
|
|
30
|
+
```ts src/api/testClientOperations.ts function foo
|
|
31
|
+
export async function foo(
|
|
32
|
+
client: TestClientContext,
|
|
33
|
+
id: string,
|
|
34
|
+
totalWeight: number,
|
|
35
|
+
color: "red" | "blue",
|
|
36
|
+
options?: FooOptions,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const path = parse("/").expand({});
|
|
39
|
+
|
|
40
|
+
const httpRequestOptions = {
|
|
41
|
+
headers: {},
|
|
42
|
+
body: {
|
|
43
|
+
id: id,
|
|
44
|
+
total_weight: totalWeight,
|
|
45
|
+
color: color,
|
|
46
|
+
is_required: options?.isRequired,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
51
|
+
|
|
52
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
53
|
+
options?.operationOptions?.onResponse(response);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (+response.status === 204 && !response.body) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
throw createRestError(response);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Should call on response after receiving the response from the service.
|
|
2
|
+
|
|
3
|
+
## TypeSpec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
@service
|
|
7
|
+
namespace Test;
|
|
8
|
+
model Widget {
|
|
9
|
+
id: string;
|
|
10
|
+
total_weight: int32;
|
|
11
|
+
color: "red" | "blue";
|
|
12
|
+
is_required?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@post op foo(...Widget): void;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## TypeScript
|
|
19
|
+
|
|
20
|
+
### Operation
|
|
21
|
+
|
|
22
|
+
Generates a function that call the onResponse callback
|
|
23
|
+
|
|
24
|
+
```ts src/api/testClientOperations.ts function foo
|
|
25
|
+
export async function foo(
|
|
26
|
+
client: TestClientContext,
|
|
27
|
+
id: string,
|
|
28
|
+
totalWeight: number,
|
|
29
|
+
color: "red" | "blue",
|
|
30
|
+
options?: FooOptions,
|
|
31
|
+
): Promise<void> {
|
|
32
|
+
const path = parse("/").expand({});
|
|
33
|
+
|
|
34
|
+
const httpRequestOptions = {
|
|
35
|
+
headers: {},
|
|
36
|
+
body: {
|
|
37
|
+
id: id,
|
|
38
|
+
total_weight: totalWeight,
|
|
39
|
+
color: color,
|
|
40
|
+
is_required: options?.isRequired,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
45
|
+
|
|
46
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
47
|
+
options?.operationOptions?.onResponse(response);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (+response.status === 204 && !response.body) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw createRestError(response);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Should handle a request with an optional body
|
|
2
|
+
|
|
3
|
+
```tsp
|
|
4
|
+
namespace Test;
|
|
5
|
+
model BodyModel {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@route("/set")
|
|
10
|
+
@post
|
|
11
|
+
op set(@body body?: BodyModel): NoContentResponse;
|
|
12
|
+
|
|
13
|
+
@route("/omit")
|
|
14
|
+
@post
|
|
15
|
+
op omit(@body body?: BodyModel): NoContentResponse;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Operations
|
|
19
|
+
|
|
20
|
+
```ts src/api/testClientOperations.ts function set
|
|
21
|
+
export async function set(client: TestClientContext, options?: SetOptions): Promise<void> {
|
|
22
|
+
const path = parse("/set").expand({});
|
|
23
|
+
|
|
24
|
+
const httpRequestOptions = {
|
|
25
|
+
headers: {},
|
|
26
|
+
body: jsonBodyModelToTransportTransform(options?.body),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
30
|
+
|
|
31
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
32
|
+
options?.operationOptions?.onResponse(response);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (+response.status === 204 && !response.body) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw createRestError(response);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Transform
|
|
44
|
+
|
|
45
|
+
```ts src/models/serializers.ts function jsonBodyModelToTransportTransform
|
|
46
|
+
export function jsonBodyModelToTransportTransform(input_?: BodyModel | null): any {
|
|
47
|
+
if (!input_) {
|
|
48
|
+
return input_ as any;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: input_.name,
|
|
53
|
+
}!;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Request with that has a path parameter directly on the operation
|
|
2
|
+
|
|
3
|
+
A request that sends a request with a path parameter as a property of the input model
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
The path parameter is a property of a spread model input in the operation signature
|
|
8
|
+
|
|
9
|
+
```tsp
|
|
10
|
+
@service({
|
|
11
|
+
title: "Widget Service",
|
|
12
|
+
})
|
|
13
|
+
namespace DemoService;
|
|
14
|
+
|
|
15
|
+
model ReadParams {
|
|
16
|
+
@path
|
|
17
|
+
id: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@route("/widgets")
|
|
21
|
+
@tag("Widgets")
|
|
22
|
+
interface Widgets {
|
|
23
|
+
@test @get read(...ReadParams): void;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## TyeScript
|
|
28
|
+
|
|
29
|
+
### Operations
|
|
30
|
+
|
|
31
|
+
It should generate an operation that places the path parameter in the url template.
|
|
32
|
+
|
|
33
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
34
|
+
export async function read(
|
|
35
|
+
client: WidgetsClientContext,
|
|
36
|
+
id: string,
|
|
37
|
+
options?: ReadOptions,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const path = parse("/widgets/{id}").expand({
|
|
40
|
+
id: id,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const httpRequestOptions = {
|
|
44
|
+
headers: {},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
48
|
+
|
|
49
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
50
|
+
options?.operationOptions?.onResponse(response);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (+response.status === 204 && !response.body) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw createRestError(response);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Request with that has a path parameter directly on the operation
|
|
2
|
+
|
|
3
|
+
A request that sends a request with a path parameter directly on the operation signature
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
The path parameter is a positional parameter in the operation signature
|
|
8
|
+
|
|
9
|
+
```tsp
|
|
10
|
+
@service({
|
|
11
|
+
title: "Widget Service",
|
|
12
|
+
})
|
|
13
|
+
namespace DemoService;
|
|
14
|
+
|
|
15
|
+
@route("/widgets")
|
|
16
|
+
@tag("Widgets")
|
|
17
|
+
interface Widgets {
|
|
18
|
+
@test @get read(@path id: string): void;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## TyeScript
|
|
23
|
+
|
|
24
|
+
### Operations
|
|
25
|
+
|
|
26
|
+
It should generate an operation that places the path parameter in the url template.
|
|
27
|
+
|
|
28
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
29
|
+
export async function read(
|
|
30
|
+
client: WidgetsClientContext,
|
|
31
|
+
id: string,
|
|
32
|
+
options?: ReadOptions,
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const path = parse("/widgets/{id}").expand({
|
|
35
|
+
id: id,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const httpRequestOptions = {
|
|
39
|
+
headers: {},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
43
|
+
|
|
44
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
45
|
+
options?.operationOptions?.onResponse(response);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (+response.status === 204 && !response.body) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
throw createRestError(response);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Request with a scalar body
|
|
2
|
+
|
|
3
|
+
A request that sends a body payload of scalar type
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
The body is modeled as an explicit body property of type int32
|
|
8
|
+
|
|
9
|
+
```tsp
|
|
10
|
+
@service({
|
|
11
|
+
title: "Widget Service",
|
|
12
|
+
})
|
|
13
|
+
namespace DemoService;
|
|
14
|
+
|
|
15
|
+
@route("/widgets")
|
|
16
|
+
@tag("Widgets")
|
|
17
|
+
interface Widgets {
|
|
18
|
+
@test @post create(@body count: int32): void;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## TyeScript
|
|
23
|
+
|
|
24
|
+
### Operations
|
|
25
|
+
|
|
26
|
+
It should generate an operation that sends the body as number. Since the body is an explicit property, a serializer function for the operation is created
|
|
27
|
+
|
|
28
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function create
|
|
29
|
+
export async function create(
|
|
30
|
+
client: WidgetsClientContext,
|
|
31
|
+
count: number,
|
|
32
|
+
options?: CreateOptions,
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const path = parse("/widgets").expand({});
|
|
35
|
+
|
|
36
|
+
const httpRequestOptions = {
|
|
37
|
+
headers: {},
|
|
38
|
+
body: count,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
42
|
+
|
|
43
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
44
|
+
options?.operationOptions?.onResponse(response);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (+response.status === 204 && !response.body) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw createRestError(response);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Serializers
|
|
56
|
+
|
|
57
|
+
The correct serializer function is created, since this is a number payload, no additional serialization is needed.
|
|
58
|
+
|
|
59
|
+
```ts src/models/serializers.ts function createPayloadToTransport
|
|
60
|
+
export function createPayloadToTransport(payload: number) {
|
|
61
|
+
return payload!;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Request with headers, body and query parameters
|
|
2
|
+
|
|
3
|
+
A typical request with path, query header and body parameters. The body is modeled as a spread model to the operation
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service({
|
|
9
|
+
title: "Widget Service",
|
|
10
|
+
})
|
|
11
|
+
namespace DemoService;
|
|
12
|
+
|
|
13
|
+
@test
|
|
14
|
+
model Widget {
|
|
15
|
+
@path id: string;
|
|
16
|
+
@header etag: string;
|
|
17
|
+
@query foo: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@route("/widgets")
|
|
22
|
+
interface Widgets {
|
|
23
|
+
@post read(...Widget): void;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## TyeScript
|
|
28
|
+
|
|
29
|
+
### Operations
|
|
30
|
+
|
|
31
|
+
It should generate an operation placing the parameters in the right place. The path and query parameters as part of the url template, the headers in the request options and correctly place the body payload into the body within the http request options
|
|
32
|
+
|
|
33
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
34
|
+
export async function read(
|
|
35
|
+
client: WidgetsClientContext,
|
|
36
|
+
id: string,
|
|
37
|
+
etag: string,
|
|
38
|
+
foo: string,
|
|
39
|
+
name: string,
|
|
40
|
+
options?: ReadOptions,
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
const path = parse("/widgets/{id}{?foo}").expand({
|
|
43
|
+
id: id,
|
|
44
|
+
foo: foo,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const httpRequestOptions = {
|
|
48
|
+
headers: {
|
|
49
|
+
etag: etag,
|
|
50
|
+
},
|
|
51
|
+
body: {
|
|
52
|
+
name: name,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
57
|
+
|
|
58
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
59
|
+
options?.operationOptions?.onResponse(response);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (+response.status === 204 && !response.body) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw createRestError(response);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Client Class
|
|
71
|
+
|
|
72
|
+
It should generate the client class with the read operation that calls the operation under api
|
|
73
|
+
|
|
74
|
+
```ts src/demoServiceClient.ts class WidgetsClient
|
|
75
|
+
export class WidgetsClient {
|
|
76
|
+
#context: WidgetsClientContext;
|
|
77
|
+
|
|
78
|
+
constructor(endpoint: string, options?: WidgetsClientOptions) {
|
|
79
|
+
this.#context = createWidgetsClientContext(endpoint, options);
|
|
80
|
+
}
|
|
81
|
+
async read(id: string, etag: string, foo: string, name: string, options?: ReadOptions) {
|
|
82
|
+
return read(this.#context, id, etag, foo, name, options);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Should generate a model with a property with array
|
|
2
|
+
|
|
3
|
+
## TypeSpec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
namespace Test;
|
|
7
|
+
model Widget {
|
|
8
|
+
id: string[];
|
|
9
|
+
weight: int32[];
|
|
10
|
+
color: ("red" | "blue")[];
|
|
11
|
+
}
|
|
12
|
+
op foo(): Widget;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## TypeScript
|
|
16
|
+
|
|
17
|
+
Should generate a model with name `Widget` that contains array properties
|
|
18
|
+
|
|
19
|
+
```ts src/models/models.ts interface Widget
|
|
20
|
+
export interface Widget {
|
|
21
|
+
id: Array<string>;
|
|
22
|
+
weight: Array<number>;
|
|
23
|
+
color: Array<"red" | "blue">;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# Should generate a model with a property with array of record
|
|
28
|
+
|
|
29
|
+
## TypeSpec
|
|
30
|
+
|
|
31
|
+
```tsp
|
|
32
|
+
namespace Test;
|
|
33
|
+
model Widget {
|
|
34
|
+
id: Record<int32>[];
|
|
35
|
+
}
|
|
36
|
+
op foo(): Widget;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## TypeScript
|
|
40
|
+
|
|
41
|
+
Should generate a model with name `Widget` that contains array properties of record type
|
|
42
|
+
|
|
43
|
+
```ts src/models/models.ts interface Widget
|
|
44
|
+
export interface Widget {
|
|
45
|
+
id: Array<Record<string, number>>;
|
|
46
|
+
}
|
|
47
|
+
```
|