@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,50 @@
|
|
|
1
|
+
# Should generate the correct properties and handle deserialization for models with different client than wire names
|
|
2
|
+
|
|
3
|
+
## TypeSpec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
model Foo {
|
|
7
|
+
element_name: string;
|
|
8
|
+
age: int32;
|
|
9
|
+
}
|
|
10
|
+
op foo(): Foo;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## TypeScript
|
|
14
|
+
|
|
15
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
16
|
+
The generated model should have property names using camelCasing. Serializer should return these properties with the same name defined in the spec while the deserializer
|
|
17
|
+
should return these properties with the same name as the generated model (camelCase)
|
|
18
|
+
|
|
19
|
+
```ts src/models/models.ts interface Foo
|
|
20
|
+
export interface Foo {
|
|
21
|
+
elementName: string;
|
|
22
|
+
age: number;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
27
|
+
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
28
|
+
if (!input_) {
|
|
29
|
+
return input_ as any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
element_name: input_.elementName,
|
|
34
|
+
age: input_.age,
|
|
35
|
+
}!;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
40
|
+
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
41
|
+
if (!input_) {
|
|
42
|
+
return input_ as any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
elementName: input_.element_name,
|
|
47
|
+
age: input_.age,
|
|
48
|
+
}!;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Should handle a discriminated union
|
|
2
|
+
|
|
3
|
+
## Typespec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
@service
|
|
7
|
+
namespace Test;
|
|
8
|
+
@discriminator("kind")
|
|
9
|
+
union WidgetData {
|
|
10
|
+
kind0: WidgetData0,
|
|
11
|
+
kind1: WidgetData1,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
model WidgetData0 {
|
|
15
|
+
kind: "kind0";
|
|
16
|
+
fooProp: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
model WidgetData1 {
|
|
20
|
+
kind: "kind1";
|
|
21
|
+
start: utcDateTime;
|
|
22
|
+
end?: utcDateTime;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@get
|
|
26
|
+
op get(): WidgetData;
|
|
27
|
+
|
|
28
|
+
@put
|
|
29
|
+
op put(@body body: WidgetData): void;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Typescript
|
|
33
|
+
|
|
34
|
+
```ts src/models/serializers.ts function jsonWidgetDataToTransportTransform
|
|
35
|
+
export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null): any {
|
|
36
|
+
if (!input_) {
|
|
37
|
+
return input_ as any;
|
|
38
|
+
}
|
|
39
|
+
return jsonWidgetDataToTransportDiscriminator(input_);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts src/models/serializers.ts function jsonWidgetDataToApplicationTransform
|
|
44
|
+
export function jsonWidgetDataToApplicationTransform(input_?: any): WidgetData {
|
|
45
|
+
if (!input_) {
|
|
46
|
+
return input_ as any;
|
|
47
|
+
}
|
|
48
|
+
return jsonWidgetDataToApplicationDiscriminator(input_);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts src/models/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
53
|
+
export function jsonWidgetDataToTransportDiscriminator(input_?: WidgetData): any {
|
|
54
|
+
if (!input_) {
|
|
55
|
+
return input_ as any;
|
|
56
|
+
}
|
|
57
|
+
const discriminatorValue = input_.kind;
|
|
58
|
+
if (discriminatorValue === "kind0") {
|
|
59
|
+
return jsonWidgetData0ToTransportTransform(input_ as any)!;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (discriminatorValue === "kind1") {
|
|
63
|
+
return jsonWidgetData1ToTransportTransform(input_ as any)!;
|
|
64
|
+
}
|
|
65
|
+
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
66
|
+
return input_ as any;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts src/models/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
71
|
+
export function jsonWidgetDataToApplicationDiscriminator(input_?: any): WidgetData {
|
|
72
|
+
if (!input_) {
|
|
73
|
+
return input_ as any;
|
|
74
|
+
}
|
|
75
|
+
const discriminatorValue = input_.kind;
|
|
76
|
+
if (discriminatorValue === "kind0") {
|
|
77
|
+
return jsonWidgetData0ToApplicationTransform(input_ as any)!;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (discriminatorValue === "kind1") {
|
|
81
|
+
return jsonWidgetData1ToApplicationTransform(input_ as any)!;
|
|
82
|
+
}
|
|
83
|
+
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
84
|
+
return input_ as any;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Should handle a discriminated union
|
|
2
|
+
|
|
3
|
+
## Typespec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
@service
|
|
7
|
+
namespace Test;
|
|
8
|
+
@discriminator("kind")
|
|
9
|
+
union WidgetData {
|
|
10
|
+
kind0: WidgetData0,
|
|
11
|
+
kind1: WidgetData1,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
model WidgetData0 {
|
|
15
|
+
kind: "kind0";
|
|
16
|
+
fooProp: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
model WidgetData1 {
|
|
20
|
+
kind: "kind1";
|
|
21
|
+
start: utcDateTime;
|
|
22
|
+
end?: utcDateTime;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@doc("The model spread Record<WidgetData>")
|
|
26
|
+
model SpreadRecordForDiscriminatedUnion {
|
|
27
|
+
@doc("The name property")
|
|
28
|
+
name: string;
|
|
29
|
+
|
|
30
|
+
...Record<WidgetData>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@get
|
|
34
|
+
op get(): SpreadRecordForDiscriminatedUnion;
|
|
35
|
+
|
|
36
|
+
@put
|
|
37
|
+
op put(@body body: SpreadRecordForDiscriminatedUnion): void;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Typescript
|
|
41
|
+
|
|
42
|
+
```ts src/models/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToTransportTransform
|
|
43
|
+
export function jsonSpreadRecordForDiscriminatedUnionToTransportTransform(
|
|
44
|
+
input_?: SpreadRecordForDiscriminatedUnion | null,
|
|
45
|
+
): any {
|
|
46
|
+
if (!input_) {
|
|
47
|
+
return input_ as any;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...jsonRecordWidgetDataToTransportTransform(input_.additionalProperties),
|
|
52
|
+
|
|
53
|
+
name: input_.name,
|
|
54
|
+
}!;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```ts src/models/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform
|
|
59
|
+
export function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform(
|
|
60
|
+
input_?: any,
|
|
61
|
+
): SpreadRecordForDiscriminatedUnion {
|
|
62
|
+
if (!input_) {
|
|
63
|
+
return input_ as any;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
additionalProperties: jsonRecordWidgetDataToApplicationTransform(
|
|
68
|
+
(({ name, ...rest }) => rest)(input_),
|
|
69
|
+
),
|
|
70
|
+
|
|
71
|
+
name: input_.name,
|
|
72
|
+
}!;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```ts src/models/serializers.ts function jsonWidgetDataToTransportTransform
|
|
77
|
+
export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null): any {
|
|
78
|
+
if (!input_) {
|
|
79
|
+
return input_ as any;
|
|
80
|
+
}
|
|
81
|
+
return jsonWidgetDataToTransportDiscriminator(input_);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```ts src/models/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
86
|
+
export function jsonWidgetDataToApplicationDiscriminator(input_?: any): WidgetData {
|
|
87
|
+
if (!input_) {
|
|
88
|
+
return input_ as any;
|
|
89
|
+
}
|
|
90
|
+
const discriminatorValue = input_.kind;
|
|
91
|
+
if (discriminatorValue === "kind0") {
|
|
92
|
+
return jsonWidgetData0ToApplicationTransform(input_ as any)!;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (discriminatorValue === "kind1") {
|
|
96
|
+
return jsonWidgetData1ToApplicationTransform(input_ as any)!;
|
|
97
|
+
}
|
|
98
|
+
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
99
|
+
return input_ as any;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```ts src/models/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
104
|
+
export function jsonWidgetDataToTransportDiscriminator(input_?: WidgetData): any {
|
|
105
|
+
if (!input_) {
|
|
106
|
+
return input_ as any;
|
|
107
|
+
}
|
|
108
|
+
const discriminatorValue = input_.kind;
|
|
109
|
+
if (discriminatorValue === "kind0") {
|
|
110
|
+
return jsonWidgetData0ToTransportTransform(input_ as any)!;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (discriminatorValue === "kind1") {
|
|
114
|
+
return jsonWidgetData1ToTransportTransform(input_ as any)!;
|
|
115
|
+
}
|
|
116
|
+
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
117
|
+
return input_ as any;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# skip:Should generate the correct properties and handle deserialization for models with utcDateTime type
|
|
2
|
+
|
|
3
|
+
Defaults to rfc7231 encoding
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
model Foo {
|
|
9
|
+
created_on: utcDateTime;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
op foo(): Foo;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## TypeScript
|
|
16
|
+
|
|
17
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
18
|
+
The generated model should have a property `createdOn` of type `Date`, the generated serializer `jsonFooToTransportTransform` should convert a Date into a string.
|
|
19
|
+
|
|
20
|
+
```ts src/models/models.ts interface Foo
|
|
21
|
+
export interface Foo {
|
|
22
|
+
createdOn: Date;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
27
|
+
export function jsonFooToTransportTransform(item: Foo): any {
|
|
28
|
+
return {
|
|
29
|
+
created_on: dateRfc3339Serializer(item.createdOn),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
35
|
+
export function jsonFooToApplicationTransform(item: any): Foo {
|
|
36
|
+
return {
|
|
37
|
+
createdOn: dateDeserializer(item.created_on),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
# skip:Should generate the correct properties and handle deserialization for models with utcDateTime type with rfc7231 encoding
|
|
43
|
+
|
|
44
|
+
## TypeSpec
|
|
45
|
+
|
|
46
|
+
```tsp
|
|
47
|
+
model Foo {
|
|
48
|
+
@encode("rfc7231")
|
|
49
|
+
created_on: utcDateTime;
|
|
50
|
+
}
|
|
51
|
+
op foo(): Foo;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## TypeScript
|
|
55
|
+
|
|
56
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
57
|
+
The generated model should have a property `createdOn` of type `Date`, the generated serializer `jsonFooToTransportTransform` should convert a Date into a string using `toUTCString()`
|
|
58
|
+
|
|
59
|
+
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
60
|
+
export function jsonFooToTransportTransform(item: Foo): any {
|
|
61
|
+
return {
|
|
62
|
+
created_on: dateRfc7231Serializer(item.createdOn),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Should emit serializer and deserializer correctly for properties with primitive array type
|
|
2
|
+
|
|
3
|
+
## Typespec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
namespace Test;
|
|
7
|
+
model FileSpecificContentType extends File {
|
|
8
|
+
filename: string;
|
|
9
|
+
contentType: "image/jpg";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
model FileWithHttpPartSpecificContentTypeRequest {
|
|
13
|
+
profileImage: HttpPart<FileSpecificContentType>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@post op create(
|
|
17
|
+
@header contentType: "multipart/form-data",
|
|
18
|
+
@multipartBody body: FileWithHttpPartSpecificContentTypeRequest,
|
|
19
|
+
): NoContentResponse;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## TypeScript
|
|
23
|
+
|
|
24
|
+
Should generate a model `FileWithHttpPartSpecificContentTypeRequest` and also a `fileWithHttpPartSpecificContentTypeRequestToTransport` and `fileWithHttpPartSpecificContentTypeRequestToApplication`.
|
|
25
|
+
|
|
26
|
+
```ts src/models/models.ts interface FileSpecificContentType
|
|
27
|
+
export interface FileSpecificContentType extends File {
|
|
28
|
+
filename: string;
|
|
29
|
+
contentType: "image/jpg";
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts src/models/models.ts interface FileWithHttpPartSpecificContentTypeRequest
|
|
34
|
+
export interface FileWithHttpPartSpecificContentTypeRequest {
|
|
35
|
+
profileImage: FileSpecificContentType;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts src/api/testClientOperations.ts function create
|
|
40
|
+
export async function create(
|
|
41
|
+
client: TestClientContext,
|
|
42
|
+
body: FileWithHttpPartSpecificContentTypeRequest,
|
|
43
|
+
options?: CreateOptions,
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
const path = parse("/").expand({});
|
|
46
|
+
|
|
47
|
+
const httpRequestOptions = {
|
|
48
|
+
headers: {
|
|
49
|
+
"content-type": options?.contentType ?? "multipart/form-data",
|
|
50
|
+
},
|
|
51
|
+
body: [createFilePartDescriptor("profileImage", body.profileImage, "image/jpg")],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
55
|
+
|
|
56
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
57
|
+
options?.operationOptions?.onResponse(response);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (+response.status === 204 && !response.body) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw createRestError(response);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Should Emit Correct Serializers and Deserializers for Polymorphic Models with Records, Arrays, and References"
|
|
2
|
+
|
|
3
|
+
## Typespec
|
|
4
|
+
|
|
5
|
+
The following TypeSpec block defines a service and several data models that serve as the foundation for our serializer tests. It starts with a base model, Bird, which uses a discriminator (kind) to support polymorphic behavior. Several derived models—SeaGull, Sparrow, Goose, and Eagle—are declared, each with a specific kind value to enable precise runtime type dispatching. Notably, the Eagle model includes additional complex properties (an array, a record, and a singular instance of Bird) to thoroughly test serialization of nested and compound types. This specification also exposes an HTTP GET endpoint returning a polymorphic Bird instance, ensuring that the generated TypeScript serializers handle these scenarios correctly.
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
@service({
|
|
9
|
+
title: "Test Service",
|
|
10
|
+
})
|
|
11
|
+
namespace Test;
|
|
12
|
+
|
|
13
|
+
@doc("This is base model for polymorphic single level inheritance with a discriminator.")
|
|
14
|
+
@discriminator("kind")
|
|
15
|
+
model Bird {
|
|
16
|
+
kind: string;
|
|
17
|
+
wingspan: int32;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@doc("The second level model in polymorphic single level inheritance.")
|
|
21
|
+
model SeaGull extends Bird {
|
|
22
|
+
kind: "seagull";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@doc("The second level model in polymorphic single level inheritance.")
|
|
26
|
+
model Sparrow extends Bird {
|
|
27
|
+
kind: "sparrow";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@doc("The second level model in polymorphic single level inheritance.")
|
|
31
|
+
model Goose extends Bird {
|
|
32
|
+
kind: "goose";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@doc("The second level model in polymorphic single levels inheritance which contains references to other polymorphic instances.")
|
|
36
|
+
model Eagle extends Bird {
|
|
37
|
+
kind: "eagle";
|
|
38
|
+
friends?: Bird[];
|
|
39
|
+
hate?: Record<Bird>;
|
|
40
|
+
partner?: Bird;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@route("/model")
|
|
44
|
+
@get
|
|
45
|
+
op getModel(): Bird;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Expectation for `jsonBirdToTransportDiscriminator`:**
|
|
49
|
+
This function should select the appropriate transport transformation based on the `kind` property of the `Bird` instance. It checks for specific kinds ("seagull", "sparrow", "goose", "eagle") and delegates to the corresponding transform. If the kind is unknown, it logs a warning and returns a fallback value.
|
|
50
|
+
|
|
51
|
+
```ts src/models/serializers.ts function jsonBirdToTransportDiscriminator
|
|
52
|
+
export function jsonBirdToTransportDiscriminator(input_?: Bird): any {
|
|
53
|
+
if (!input_) {
|
|
54
|
+
return input_ as any;
|
|
55
|
+
}
|
|
56
|
+
const discriminatorValue = input_.kind;
|
|
57
|
+
if (discriminatorValue === "seagull") {
|
|
58
|
+
return jsonSeaGullToTransportTransform(input_ as any)!;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (discriminatorValue === "sparrow") {
|
|
62
|
+
return jsonSparrowToTransportTransform(input_ as any)!;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (discriminatorValue === "goose") {
|
|
66
|
+
return jsonGooseToTransportTransform(input_ as any)!;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (discriminatorValue === "eagle") {
|
|
70
|
+
return jsonEagleToTransportTransform(input_ as any)!;
|
|
71
|
+
}
|
|
72
|
+
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
73
|
+
return input_ as any;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Expectation for `jsonBirdToTransportTransform`:**
|
|
78
|
+
This function should transform a basic `Bird` instance by mapping its core properties (`kind` and `wingspan`) to the transport format.
|
|
79
|
+
|
|
80
|
+
```ts src/models/serializers.ts function jsonBirdToTransportTransform
|
|
81
|
+
export function jsonBirdToTransportTransform(input_?: Bird | null): any {
|
|
82
|
+
if (!input_) {
|
|
83
|
+
return input_ as any;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
...jsonBirdToTransportDiscriminator(input_),
|
|
88
|
+
kind: input_.kind,
|
|
89
|
+
wingspan: input_.wingspan,
|
|
90
|
+
}!;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Expectation for `jsonSeaGullToTransportTransform`:**
|
|
95
|
+
For a `SeaGull` instance, the serializer should extend the base transformation provided by `jsonBirdToApplicationTransform` and then explicitly include all properties from SeaGull in this case it is just the `kind` .
|
|
96
|
+
|
|
97
|
+
```ts src/models/serializers.ts function jsonSeaGullToTransportTransform
|
|
98
|
+
export function jsonSeaGullToTransportTransform(input_?: SeaGull | null): any {
|
|
99
|
+
if (!input_) {
|
|
100
|
+
return input_ as any;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
kind: input_.kind,
|
|
105
|
+
wingspan: input_.wingspan,
|
|
106
|
+
}!;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Expectation for `jsonSparrowToTransportTransform`:**
|
|
111
|
+
Similarly, the serializer for a `Sparrow` instance should build upon the base Bird transformation and add the `kind` property accordingly.
|
|
112
|
+
|
|
113
|
+
```ts src/models/serializers.ts function jsonSparrowToTransportTransform
|
|
114
|
+
export function jsonSparrowToTransportTransform(input_?: Sparrow | null): any {
|
|
115
|
+
if (!input_) {
|
|
116
|
+
return input_ as any;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
kind: input_.kind,
|
|
121
|
+
wingspan: input_.wingspan,
|
|
122
|
+
}!;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Expectation for `jsonGooseToTransportTransform`:**
|
|
127
|
+
This function should transform a `Goose` instance by reusing the base Bird transformation and explicitly setting the `kind` property.
|
|
128
|
+
|
|
129
|
+
```ts src/models/serializers.ts function jsonGooseToTransportTransform
|
|
130
|
+
export function jsonGooseToTransportTransform(input_?: Goose | null): any {
|
|
131
|
+
if (!input_) {
|
|
132
|
+
return input_ as any;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
kind: input_.kind,
|
|
137
|
+
wingspan: input_.wingspan,
|
|
138
|
+
}!;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Expectation for `jsonEagleToTransportTransform`:**
|
|
143
|
+
The serializer for an `Eagle` instance is more complex due to additional properties. It must:
|
|
144
|
+
|
|
145
|
+
- Extend the base transformation (`jsonBirdToApplicationTransform`),
|
|
146
|
+
- Transform the `friends` property (an array of `Bird` instances) using `jsonArrayBirdToTransportTransform`,
|
|
147
|
+
- Transform the `hate` property (a primitive Record of `Bird` instances) using `jsonRecordBirdToTransportTransform`, and
|
|
148
|
+
- Transform the `partner` property (a single `Bird` instance) using `jsonBirdToApplicationTransform`.
|
|
149
|
+
|
|
150
|
+
```ts src/models/serializers.ts function jsonEagleToTransportTransform
|
|
151
|
+
export function jsonEagleToTransportTransform(input_?: Eagle | null): any {
|
|
152
|
+
if (!input_) {
|
|
153
|
+
return input_ as any;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
kind: input_.kind,
|
|
158
|
+
friends: jsonArrayBirdToTransportTransform(input_.friends),
|
|
159
|
+
hate: jsonRecordBirdToTransportTransform(input_.hate),
|
|
160
|
+
partner: jsonBirdToTransportTransform(input_.partner),
|
|
161
|
+
wingspan: input_.wingspan,
|
|
162
|
+
}!;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Should emit serializer and deserializer correctly for properties with primitive Record type
|
|
2
|
+
|
|
3
|
+
## Typespec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
model Foo {
|
|
7
|
+
my_values: Record<int32>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
op foo(): Foo;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## TypeScript
|
|
14
|
+
|
|
15
|
+
Should generate a model `Foo` and also a `jsonFooToTransportTransform` and `jsonFooToApplicationTransform` functions that call the `recordSerializer` internally.
|
|
16
|
+
|
|
17
|
+
```ts src/models/models.ts interface Foo
|
|
18
|
+
export interface Foo {
|
|
19
|
+
myValues: Record<string, number>;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
24
|
+
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
25
|
+
if (!input_) {
|
|
26
|
+
return input_ as any;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
my_values: jsonRecordInt32ToTransportTransform(input_.myValues),
|
|
31
|
+
}!;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
36
|
+
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
37
|
+
if (!input_) {
|
|
38
|
+
return input_ as any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
myValues: jsonRecordInt32ToApplicationTransform(input_.my_values),
|
|
43
|
+
}!;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
# Should emit serializer and deserializer correctly for properties with complex array type
|
|
48
|
+
|
|
49
|
+
## Typespec
|
|
50
|
+
|
|
51
|
+
```tsp
|
|
52
|
+
model Bar {
|
|
53
|
+
bar_value: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
model Foo {
|
|
57
|
+
my_values: Record<Bar>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
op foo(): Foo | Bar;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## TypeScript
|
|
64
|
+
|
|
65
|
+
Should generate models `Foo` and `Bar` and also a `jsonFooToTransportTransform`, `jsonFooToApplicationTransform`, `barToTransport` and `barToApplication` functions that call the `recordSerializer` passing `barToTransport` or `barDeserialize` as the serialization callback.
|
|
66
|
+
|
|
67
|
+
```ts src/models/models.ts interface Foo
|
|
68
|
+
export interface Foo {
|
|
69
|
+
myValues: Record<string, Bar>;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts src/models/models.ts interface Bar
|
|
74
|
+
export interface Bar {
|
|
75
|
+
barValue: string;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
80
|
+
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
81
|
+
if (!input_) {
|
|
82
|
+
return input_ as any;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
my_values: jsonRecordBarToTransportTransform(input_.myValues),
|
|
87
|
+
}!;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
92
|
+
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
93
|
+
if (!input_) {
|
|
94
|
+
return input_ as any;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
myValues: jsonRecordBarToApplicationTransform(input_.my_values),
|
|
99
|
+
}!;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Should generate a serializer for a declared utcDateTime scalar
|
|
2
|
+
|
|
3
|
+
Should generate a Type Alias for each of the utcDateTime taking into account the encoding. All should generate
|
|
4
|
+
|
|
5
|
+
## TypeSpec
|
|
6
|
+
|
|
7
|
+
```tsp
|
|
8
|
+
scalar MyDate extends utcDateTime;
|
|
9
|
+
@encode("rfc3339")
|
|
10
|
+
scalar MyUtcDate extends utcDateTime;
|
|
11
|
+
@encode("rfc7231")
|
|
12
|
+
scalar MyIsoDate extends utcDateTime;
|
|
13
|
+
@encode("unixTimestamp", int32)
|
|
14
|
+
scalar MyUnixDate extends utcDateTime;
|
|
15
|
+
|
|
16
|
+
op foo(a: MyDate, b: MyUtcDate, c: MyIsoDate, d: MyUnixDate): void;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## TypeScript
|
|
20
|
+
|
|
21
|
+
```ts src/models/models.ts
|
|
22
|
+
export type String = string;
|
|
23
|
+
|
|
24
|
+
export type MyDate = Date;
|
|
25
|
+
|
|
26
|
+
export type UtcDateTime = Date;
|
|
27
|
+
|
|
28
|
+
export type MyUtcDate = Date;
|
|
29
|
+
|
|
30
|
+
export type MyIsoDate = Date;
|
|
31
|
+
|
|
32
|
+
export type MyUnixDate = Date;
|
|
33
|
+
```
|