@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,236 @@
|
|
|
1
|
+
# Should populate a Date query parameter
|
|
2
|
+
|
|
3
|
+
This scenario tests that a Date query parameter is sent correctly to the wire. Without any explicit encoding, the default is to encode as rfc3339
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service
|
|
9
|
+
namespace Test;
|
|
10
|
+
|
|
11
|
+
@route("/default")
|
|
12
|
+
op defaultEncoding(
|
|
13
|
+
@query
|
|
14
|
+
value: utcDateTime,
|
|
15
|
+
): NoContentResponse;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## TypeScript
|
|
19
|
+
|
|
20
|
+
```ts src/api/testClientOperations.ts function defaultEncoding
|
|
21
|
+
export async function defaultEncoding(
|
|
22
|
+
client: TestClientContext,
|
|
23
|
+
value: Date,
|
|
24
|
+
options?: DefaultEncodingOptions,
|
|
25
|
+
): Promise<void> {
|
|
26
|
+
const path = parse("/default{?value}").expand({
|
|
27
|
+
value: dateRfc3339Serializer(value),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const httpRequestOptions = {
|
|
31
|
+
headers: {},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
35
|
+
|
|
36
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
37
|
+
options?.operationOptions?.onResponse(response);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (+response.status === 204 && !response.body) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw createRestError(response);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
# Should populate a Date query parameter when the param is optional
|
|
49
|
+
|
|
50
|
+
This scenario tests that a Date query parameter which is optional, is sent correctly to the wire. Without any explicit encoding, the default is to encode as rfc3339
|
|
51
|
+
|
|
52
|
+
## TypeSpec
|
|
53
|
+
|
|
54
|
+
```tsp
|
|
55
|
+
@service
|
|
56
|
+
namespace Test;
|
|
57
|
+
|
|
58
|
+
@route("/default")
|
|
59
|
+
op defaultEncoding(
|
|
60
|
+
@query
|
|
61
|
+
value?: utcDateTime,
|
|
62
|
+
): NoContentResponse;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## TypeScript
|
|
66
|
+
|
|
67
|
+
```ts src/api/testClientOperations.ts function defaultEncoding
|
|
68
|
+
export async function defaultEncoding(
|
|
69
|
+
client: TestClientContext,
|
|
70
|
+
options?: DefaultEncodingOptions,
|
|
71
|
+
): Promise<void> {
|
|
72
|
+
const path = parse("/default{?value}").expand({
|
|
73
|
+
...(options?.value && { value: dateRfc3339Serializer(options?.value) }),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const httpRequestOptions = {
|
|
77
|
+
headers: {},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
81
|
+
|
|
82
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
83
|
+
options?.operationOptions?.onResponse(response);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (+response.status === 204 && !response.body) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw createRestError(response);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Should populate a Date query parameter with explicit encoding rfc3339
|
|
95
|
+
|
|
96
|
+
This scenario tests that a Date query parameter is sent correctly to the wire. Explicitly setting encoding to rfc3339
|
|
97
|
+
|
|
98
|
+
## TypeSpec
|
|
99
|
+
|
|
100
|
+
```tsp
|
|
101
|
+
@service
|
|
102
|
+
namespace Test;
|
|
103
|
+
|
|
104
|
+
@route("/default")
|
|
105
|
+
op get(
|
|
106
|
+
@query
|
|
107
|
+
@encode(DateTimeKnownEncoding.rfc3339)
|
|
108
|
+
value: utcDateTime,
|
|
109
|
+
): NoContentResponse;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## TypeScript
|
|
113
|
+
|
|
114
|
+
```ts src/api/testClientOperations.ts function get
|
|
115
|
+
export async function get(
|
|
116
|
+
client: TestClientContext,
|
|
117
|
+
value: Date,
|
|
118
|
+
options?: GetOptions,
|
|
119
|
+
): Promise<void> {
|
|
120
|
+
const path = parse("/default{?value}").expand({
|
|
121
|
+
value: dateRfc3339Serializer(value),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const httpRequestOptions = {
|
|
125
|
+
headers: {},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
129
|
+
|
|
130
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
131
|
+
options?.operationOptions?.onResponse(response);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (+response.status === 204 && !response.body) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
throw createRestError(response);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
# onlyShould populate a Date query parameter with explicit encoding rfc7231
|
|
143
|
+
|
|
144
|
+
This scenario tests that a Date query parameter is sent correctly to the wire. Explicit encode set to rfc7231
|
|
145
|
+
|
|
146
|
+
## TypeSpec
|
|
147
|
+
|
|
148
|
+
```tsp
|
|
149
|
+
@service
|
|
150
|
+
namespace Test;
|
|
151
|
+
|
|
152
|
+
@route("/default")
|
|
153
|
+
op get(
|
|
154
|
+
@query
|
|
155
|
+
@encode(DateTimeKnownEncoding.rfc7231)
|
|
156
|
+
value: utcDateTime,
|
|
157
|
+
): NoContentResponse;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## TypeScript
|
|
161
|
+
|
|
162
|
+
```ts src/api/testClientOperations.ts function get
|
|
163
|
+
export async function get(
|
|
164
|
+
client: TestClientContext,
|
|
165
|
+
value: Date,
|
|
166
|
+
options?: GetOptions,
|
|
167
|
+
): Promise<void> {
|
|
168
|
+
const path = parse("/default{?value}").expand({
|
|
169
|
+
value: dateRfc7231Serializer(value),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const httpRequestOptions = {
|
|
173
|
+
headers: {},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
177
|
+
|
|
178
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
179
|
+
options?.operationOptions?.onResponse(response);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (+response.status === 204 && !response.body) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
throw createRestError(response);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
# Should populate a Date query parameter with explicit encoding Unix Timestamp
|
|
191
|
+
|
|
192
|
+
This scenario tests that a Date query parameter is sent correctly to the wire. Explicit encode set to unix timestamp
|
|
193
|
+
|
|
194
|
+
## TypeSpec
|
|
195
|
+
|
|
196
|
+
```tsp
|
|
197
|
+
@service
|
|
198
|
+
namespace Test;
|
|
199
|
+
|
|
200
|
+
@route("/default")
|
|
201
|
+
op get(
|
|
202
|
+
@query
|
|
203
|
+
@encode("unixTimestamp", int64)
|
|
204
|
+
value: utcDateTime,
|
|
205
|
+
): NoContentResponse;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## TypeScript
|
|
209
|
+
|
|
210
|
+
```ts src/api/testClientOperations.ts function get
|
|
211
|
+
export async function get(
|
|
212
|
+
client: TestClientContext,
|
|
213
|
+
value: Date,
|
|
214
|
+
options?: GetOptions,
|
|
215
|
+
): Promise<void> {
|
|
216
|
+
const path = parse("/default{?value}").expand({
|
|
217
|
+
value: dateUnixTimestampSerializer(value),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const httpRequestOptions = {
|
|
221
|
+
headers: {},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
225
|
+
|
|
226
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
227
|
+
options?.operationOptions?.onResponse(response);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (+response.status === 204 && !response.body) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
throw createRestError(response);
|
|
235
|
+
}
|
|
236
|
+
```
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Should handle a basic request
|
|
2
|
+
|
|
3
|
+
This test verifies that a basic `GET` request with no headers, body, or parameters is correctly handled.
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service({
|
|
9
|
+
title: "Widget Service",
|
|
10
|
+
})
|
|
11
|
+
namespace DemoService;
|
|
12
|
+
|
|
13
|
+
@route("/widgets")
|
|
14
|
+
@tag("Widgets")
|
|
15
|
+
interface Widgets {
|
|
16
|
+
@test @get read(): void;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## TypeScript
|
|
21
|
+
|
|
22
|
+
### Request
|
|
23
|
+
|
|
24
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
25
|
+
export async function read(client: WidgetsClientContext, options?: ReadOptions): Promise<void> {
|
|
26
|
+
const path = parse("/widgets").expand({});
|
|
27
|
+
|
|
28
|
+
const httpRequestOptions = {
|
|
29
|
+
headers: {},
|
|
30
|
+
};
|
|
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
|
+
|
|
38
|
+
if (+response.status === 204 && !response.body) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw createRestError(response);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
# Should handle a request with headers, body, and query parameters
|
|
47
|
+
|
|
48
|
+
This test verifies that a `POST` request with headers, a body, and query parameters is correctly handled.
|
|
49
|
+
|
|
50
|
+
## TypeSpec
|
|
51
|
+
|
|
52
|
+
```tsp
|
|
53
|
+
@service({
|
|
54
|
+
title: "Widget Service",
|
|
55
|
+
})
|
|
56
|
+
namespace DemoService;
|
|
57
|
+
|
|
58
|
+
@test
|
|
59
|
+
model Widget {
|
|
60
|
+
@path id: string;
|
|
61
|
+
@header etag: string;
|
|
62
|
+
@query foo: string;
|
|
63
|
+
name: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@route("/widgets")
|
|
67
|
+
@tag("Widgets")
|
|
68
|
+
interface Widgets {
|
|
69
|
+
@test @post read(...Widget): void;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## TypeScript
|
|
74
|
+
|
|
75
|
+
### Request
|
|
76
|
+
|
|
77
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
78
|
+
export async function read(
|
|
79
|
+
client: WidgetsClientContext,
|
|
80
|
+
id: string,
|
|
81
|
+
etag: string,
|
|
82
|
+
foo: string,
|
|
83
|
+
name: string,
|
|
84
|
+
options?: ReadOptions,
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
const path = parse("/widgets/{id}{?foo}").expand({
|
|
87
|
+
id: id,
|
|
88
|
+
foo: foo,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const httpRequestOptions = {
|
|
92
|
+
headers: {
|
|
93
|
+
etag: etag,
|
|
94
|
+
},
|
|
95
|
+
body: {
|
|
96
|
+
name: name,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
101
|
+
|
|
102
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
103
|
+
options?.operationOptions?.onResponse(response);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (+response.status === 204 && !response.body) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
throw createRestError(response);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
# Should handle a scalar body
|
|
115
|
+
|
|
116
|
+
This test verifies that a `GET` request with a scalar body is correctly handled.
|
|
117
|
+
|
|
118
|
+
## TypeSpec
|
|
119
|
+
|
|
120
|
+
```tsp
|
|
121
|
+
@service({
|
|
122
|
+
title: "Widget Service",
|
|
123
|
+
})
|
|
124
|
+
namespace DemoService;
|
|
125
|
+
|
|
126
|
+
@route("/widgets")
|
|
127
|
+
@tag("Widgets")
|
|
128
|
+
interface Widgets {
|
|
129
|
+
@test @get read(@body count: int32): void;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## TypeScript
|
|
134
|
+
|
|
135
|
+
### Request
|
|
136
|
+
|
|
137
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
138
|
+
export async function read(
|
|
139
|
+
client: WidgetsClientContext,
|
|
140
|
+
count: number,
|
|
141
|
+
options?: ReadOptions,
|
|
142
|
+
): Promise<void> {
|
|
143
|
+
const path = parse("/widgets").expand({});
|
|
144
|
+
|
|
145
|
+
const httpRequestOptions = {
|
|
146
|
+
headers: {},
|
|
147
|
+
body: count,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
151
|
+
|
|
152
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
153
|
+
options?.operationOptions?.onResponse(response);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (+response.status === 204 && !response.body) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
throw createRestError(response);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# **Handling a Response with No Body (204 No Content)**
|
|
2
|
+
|
|
3
|
+
This test verifies that a response with status `204` and no body is correctly handled. The generated TypeScript function should recognize an empty response and return `void` without errors.
|
|
4
|
+
|
|
5
|
+
## **TypeSpec**
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service({
|
|
9
|
+
title: "Widget Service",
|
|
10
|
+
})
|
|
11
|
+
namespace DemoService;
|
|
12
|
+
|
|
13
|
+
@route("/widgets")
|
|
14
|
+
@tag("Widgets")
|
|
15
|
+
interface Widgets {
|
|
16
|
+
@test @get read(): void;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## **TypeScript**
|
|
21
|
+
|
|
22
|
+
### **Response Handling**
|
|
23
|
+
|
|
24
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
25
|
+
export async function read(client: WidgetsClientContext, options?: ReadOptions): Promise<void> {
|
|
26
|
+
const path = parse("/widgets").expand({});
|
|
27
|
+
|
|
28
|
+
const httpRequestOptions = {
|
|
29
|
+
headers: {},
|
|
30
|
+
};
|
|
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
|
+
|
|
38
|
+
if (+response.status === 204 && !response.body) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw createRestError(response);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# **Handling a Response with a JSON Body**
|
|
49
|
+
|
|
50
|
+
This test verifies that a response with a body containing a `Widget` model is correctly handled. The generated TypeScript function should deserialize the response body into a `Widget` instance.
|
|
51
|
+
|
|
52
|
+
## **TypeSpec**
|
|
53
|
+
|
|
54
|
+
```tsp
|
|
55
|
+
@service({
|
|
56
|
+
title: "Widget Service",
|
|
57
|
+
})
|
|
58
|
+
namespace DemoService;
|
|
59
|
+
|
|
60
|
+
@test
|
|
61
|
+
model Widget {
|
|
62
|
+
name: string;
|
|
63
|
+
age: int32;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@route("/widgets")
|
|
67
|
+
@tag("Widgets")
|
|
68
|
+
interface Widgets {
|
|
69
|
+
@test @get read(): Widget;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## **TypeScript**
|
|
74
|
+
|
|
75
|
+
### **Deserializer**
|
|
76
|
+
|
|
77
|
+
This function converts the received JSON response into a `Widget` instance.
|
|
78
|
+
|
|
79
|
+
```ts src/models/serializers.ts function jsonWidgetToApplicationTransform
|
|
80
|
+
export function jsonWidgetToApplicationTransform(input_?: any): Widget {
|
|
81
|
+
if (!input_) {
|
|
82
|
+
return input_ as any;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
name: input_.name,
|
|
87
|
+
age: input_.age,
|
|
88
|
+
}!;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### **Response Handling**
|
|
93
|
+
|
|
94
|
+
The function reads a `Widget` instance from the response body, ensuring it only processes JSON responses with a `200` status.
|
|
95
|
+
|
|
96
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
97
|
+
export async function read(client: WidgetsClientContext, options?: ReadOptions): Promise<Widget> {
|
|
98
|
+
const path = parse("/widgets").expand({});
|
|
99
|
+
|
|
100
|
+
const httpRequestOptions = {
|
|
101
|
+
headers: {},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
105
|
+
|
|
106
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
107
|
+
options?.operationOptions?.onResponse(response);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
111
|
+
return jsonWidgetToApplicationTransform(response.body)!;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
throw createRestError(response);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
# **Handling a Response with Multiple Status Codes (200 & 204)**
|
|
121
|
+
|
|
122
|
+
This test verifies that a response with multiple status codes (`200` and `204`) is correctly handled. If the response is `200`, it should deserialize a `Widget`; if `204`, it should return `void`.
|
|
123
|
+
|
|
124
|
+
## **TypeSpec**
|
|
125
|
+
|
|
126
|
+
```tsp
|
|
127
|
+
@service({
|
|
128
|
+
title: "Widget Service",
|
|
129
|
+
})
|
|
130
|
+
namespace DemoService;
|
|
131
|
+
|
|
132
|
+
@test
|
|
133
|
+
model Widget {
|
|
134
|
+
name: string;
|
|
135
|
+
age: int32;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@route("/widgets")
|
|
139
|
+
@tag("Widgets")
|
|
140
|
+
interface Widgets {
|
|
141
|
+
@test @get read(): Widget | void;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## **TypeScript**
|
|
146
|
+
|
|
147
|
+
### **Response Handling**
|
|
148
|
+
|
|
149
|
+
The function determines the response type based on the status code. If `200`, it deserializes a `Widget`; if `204`, it returns `void`.
|
|
150
|
+
|
|
151
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
152
|
+
export async function read(
|
|
153
|
+
client: WidgetsClientContext,
|
|
154
|
+
options?: ReadOptions,
|
|
155
|
+
): Promise<Widget | void> {
|
|
156
|
+
const path = parse("/widgets").expand({});
|
|
157
|
+
|
|
158
|
+
const httpRequestOptions = {
|
|
159
|
+
headers: {},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
163
|
+
|
|
164
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
165
|
+
options?.operationOptions?.onResponse(response);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
169
|
+
return jsonWidgetToApplicationTransform(response.body)!;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (+response.status === 204 && !response.body) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
throw createRestError(response);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
# **Handling a Response with Multiple Content Types**
|
|
183
|
+
|
|
184
|
+
This test verifies that a response with multiple content types is correctly handled. The response can be in JSON or XML format, both containing a `Widget` model.
|
|
185
|
+
|
|
186
|
+
## **TypeSpec**
|
|
187
|
+
|
|
188
|
+
```tsp
|
|
189
|
+
@service({
|
|
190
|
+
title: "Widget Service",
|
|
191
|
+
})
|
|
192
|
+
namespace DemoService;
|
|
193
|
+
|
|
194
|
+
model Widget {
|
|
195
|
+
name: string;
|
|
196
|
+
age: int32;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
model JsonResponse {
|
|
200
|
+
@body body: Widget;
|
|
201
|
+
@header contentType: "application/json";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
model XmlResponse {
|
|
205
|
+
@body body: Widget;
|
|
206
|
+
@header contentType: "application/xml";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@route("/widgets")
|
|
210
|
+
interface Widgets {
|
|
211
|
+
@get read(): JsonResponse | XmlResponse;
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## **TypeScript**
|
|
216
|
+
|
|
217
|
+
### **Response Handling**
|
|
218
|
+
|
|
219
|
+
This function ensures that the response is correctly processed based on its `content-type` header. It supports both JSON and XML responses, deserializing them into `Widget` instances.
|
|
220
|
+
TODO: need to implement xml serialization
|
|
221
|
+
|
|
222
|
+
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
223
|
+
export async function read(client: WidgetsClientContext, options?: ReadOptions): Promise<Widget> {
|
|
224
|
+
const path = parse("/widgets").expand({});
|
|
225
|
+
|
|
226
|
+
const httpRequestOptions = {
|
|
227
|
+
headers: {},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
231
|
+
|
|
232
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
233
|
+
options?.operationOptions?.onResponse(response);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
237
|
+
return jsonWidgetToApplicationTransform(response.body)!;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/xml")) {
|
|
241
|
+
return jsonWidgetToApplicationTransform(response.body)!;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
throw createRestError(response);
|
|
245
|
+
}
|
|
246
|
+
```
|