@azure-tools/typespec-ts 0.11.0 → 0.12.0-alpha.20230501.1
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/.rush/temp/package-deps_build.json +265 -152
- package/.rush/temp/shrinkwrap-deps.json +58 -54
- package/CHANGELOG.md +4 -0
- package/CONTRIBUTING.md +5 -2
- package/README.md +3 -3
- package/dist/src/casingUtils.d.ts +4 -0
- package/dist/src/casingUtils.d.ts.map +1 -0
- package/dist/src/casingUtils.js +39 -0
- package/dist/src/casingUtils.js.map +1 -0
- package/dist/src/emitUtil.js +7 -1
- package/dist/src/emitUtil.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +41 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modelUtils.d.ts +22 -1
- package/dist/src/modelUtils.d.ts.map +1 -1
- package/dist/src/modelUtils.js +105 -13
- package/dist/src/modelUtils.js.map +1 -1
- package/dist/src/modular/buildApiIndex.d.ts +3 -0
- package/dist/src/modular/buildApiIndex.d.ts.map +1 -0
- package/dist/src/modular/buildApiIndex.js +12 -0
- package/dist/src/modular/buildApiIndex.js.map +1 -0
- package/dist/src/modular/buildClassicalClient.d.ts +4 -0
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -0
- package/dist/src/modular/buildClassicalClient.js +112 -0
- package/dist/src/modular/buildClassicalClient.js.map +1 -0
- package/dist/src/modular/buildClientContext.d.ts +7 -0
- package/dist/src/modular/buildClientContext.d.ts.map +1 -0
- package/dist/src/modular/buildClientContext.js +72 -0
- package/dist/src/modular/buildClientContext.js.map +1 -0
- package/dist/src/modular/buildCodeModel.d.ts +14 -0
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -0
- package/dist/src/modular/buildCodeModel.js +1110 -0
- package/dist/src/modular/buildCodeModel.js.map +1 -0
- package/dist/src/modular/buildOperations.d.ts +13 -0
- package/dist/src/modular/buildOperations.d.ts.map +1 -0
- package/dist/src/modular/buildOperations.js +70 -0
- package/dist/src/modular/buildOperations.js.map +1 -0
- package/dist/src/modular/buildProjectFiles.d.ts +5 -0
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -0
- package/dist/src/modular/buildProjectFiles.js +182 -0
- package/dist/src/modular/buildProjectFiles.js.map +1 -0
- package/dist/src/modular/buildRootIndex.d.ts +4 -0
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -0
- package/dist/src/modular/buildRootIndex.js +66 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -0
- package/dist/src/modular/buildSharedTypes.d.ts +6 -0
- package/dist/src/modular/buildSharedTypes.d.ts.map +1 -0
- package/dist/src/modular/buildSharedTypes.js +33 -0
- package/dist/src/modular/buildSharedTypes.js.map +1 -0
- package/dist/src/modular/emitModels.d.ts +7 -0
- package/dist/src/modular/emitModels.d.ts.map +1 -0
- package/dist/src/modular/emitModels.js +63 -0
- package/dist/src/modular/emitModels.js.map +1 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts +4 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/clientHelpers.js +31 -0
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -0
- package/dist/src/modular/helpers/credentialHelpers.d.ts +7 -0
- package/dist/src/modular/helpers/credentialHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/credentialHelpers.js +32 -0
- package/dist/src/modular/helpers/credentialHelpers.js.map +1 -0
- package/dist/src/modular/helpers/namingHelpers.d.ts +3 -0
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/namingHelpers.js +4 -0
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -0
- package/dist/src/modular/helpers/operationHelpers.d.ts +8 -0
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/operationHelpers.js +274 -0
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -0
- package/dist/src/modular/helpers/parameterHelpers.d.ts +3 -0
- package/dist/src/modular/helpers/parameterHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/parameterHelpers.js +16 -0
- package/dist/src/modular/helpers/parameterHelpers.js.map +1 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts +16 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -0
- package/dist/src/modular/helpers/typeHelpers.js +92 -0
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -0
- package/dist/src/modular/interfaces.d.ts +10 -0
- package/dist/src/modular/interfaces.d.ts.map +1 -0
- package/dist/src/modular/interfaces.js +2 -0
- package/dist/src/modular/interfaces.js.map +1 -0
- package/dist/src/modular/modularCodeModel.d.ts +121 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -0
- package/dist/src/modular/modularCodeModel.js +2 -0
- package/dist/src/modular/modularCodeModel.js.map +1 -0
- package/dist/src/operationUtil.d.ts +30 -4
- package/dist/src/operationUtil.d.ts.map +1 -1
- package/dist/src/operationUtil.js +77 -18
- package/dist/src/operationUtil.js.map +1 -1
- package/dist/src/transform/transform.d.ts +4 -6
- package/dist/src/transform/transform.d.ts.map +1 -1
- package/dist/src/transform/transform.js +17 -58
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts +5 -0
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -0
- package/dist/src/transform/transformApiVersionInfo.js +64 -0
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -0
- package/dist/src/transform/transformHelperFunctionDetails.d.ts +6 -0
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -0
- package/dist/src/transform/{transformAnnotationDetails.js → transformHelperFunctionDetails.js} +2 -2
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -0
- package/dist/src/transform/transformParameters.d.ts +2 -2
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +20 -7
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts +2 -2
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js +15 -7
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts +2 -2
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +23 -2
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts +2 -2
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +10 -22
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts +2 -2
- package/dist/src/transform/transfromRLCOptions.js +1 -1
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -19
- package/src/casingUtils.ts +48 -0
- package/src/emitUtil.ts +9 -4
- package/src/index.ts +53 -10
- package/src/lib.ts +2 -1
- package/src/modelUtils.ts +137 -14
- package/src/modular/buildApiIndex.ts +13 -0
- package/src/modular/buildClassicalClient.ts +147 -0
- package/src/modular/buildClientContext.ts +104 -0
- package/src/modular/buildCodeModel.ts +1449 -0
- package/src/modular/buildOperations.ts +95 -0
- package/src/modular/buildProjectFiles.ts +219 -0
- package/src/modular/buildRootIndex.ts +94 -0
- package/src/modular/buildSharedTypes.ts +40 -0
- package/src/modular/emitModels.ts +72 -0
- package/src/modular/helpers/clientHelpers.ts +38 -0
- package/src/modular/helpers/credentialHelpers.ts +40 -0
- package/src/modular/helpers/namingHelpers.ts +5 -0
- package/src/modular/helpers/operationHelpers.ts +418 -0
- package/src/modular/helpers/parameterHelpers.ts +17 -0
- package/src/modular/helpers/typeHelpers.ts +106 -0
- package/src/modular/interfaces.ts +10 -0
- package/src/modular/modularCodeModel.ts +151 -0
- package/src/modular/static/karma.conf.cjs +120 -0
- package/src/modular/static/rollup.test.config.js +67 -0
- package/src/modular/static/scripts/renameOutput.mjs +17 -0
- package/src/operationUtil.ts +119 -31
- package/src/transform/transform.ts +33 -96
- package/src/transform/transformApiVersionInfo.ts +108 -0
- package/src/transform/{transformAnnotationDetails.ts → transformHelperFunctionDetails.ts} +11 -11
- package/src/transform/transformParameters.ts +30 -14
- package/src/transform/transformPaths.ts +29 -19
- package/src/transform/transformResponses.ts +50 -8
- package/src/transform/transformSchemas.ts +20 -28
- package/src/transform/transfromRLCOptions.ts +3 -3
- package/test/commands/cadl-ranch-list.ts +53 -20
- package/test/commands/gen-cadl-ranch.ts +6 -2
- package/test/commands/run.ts +3 -13
- package/test/integration/arrayItemTypes.spec.ts +6 -3
- package/test/integration/azurecore.spec.ts +130 -0
- package/test/integration/collectionFormat.spec.ts +118 -0
- package/test/integration/dictionary.spec.ts +6 -2
- package/test/integration/extensibleEnums.spec.ts +8 -8
- package/test/integration/fixedEnums.spec.ts +7 -7
- package/test/integration/generated/arrays/itemTypes/src/clientDefinitions.ts +33 -18
- package/test/integration/generated/arrays/itemTypes/src/parameters.ts +8 -0
- package/test/integration/generated/arrays/itemTypes/src/responses.ts +11 -0
- package/test/integration/generated/arrays/itemTypes/tspconfig.yaml +5 -2
- package/test/integration/generated/authentication/apiKey/package.json +2 -2
- package/test/integration/generated/authentication/apiKey/tspconfig.yaml +5 -2
- package/test/integration/generated/authentication/oauth2/tspconfig.yaml +5 -2
- package/test/integration/generated/authentication/union/tspconfig.yaml +5 -2
- package/test/integration/generated/{resiliency/devDriven → azure/core}/README.md +7 -7
- package/test/integration/generated/{lro/lroBasic → azure/core}/api-extractor.json +1 -1
- package/test/integration/generated/{resiliency/devDriven → azure/core}/package.json +6 -6
- package/test/integration/generated/azure/core/src/azureCoreClient.ts +31 -0
- package/test/integration/generated/azure/core/src/clientDefinitions.ts +108 -0
- package/test/integration/generated/{resiliency/devDriven → azure/core}/src/index.ts +4 -3
- package/test/integration/generated/azure/core/src/isUnexpected.ts +178 -0
- package/test/integration/generated/azure/core/src/models.ts +18 -0
- package/test/integration/generated/azure/core/src/outputModels.ts +32 -0
- package/test/integration/generated/{resiliency/devDriven → azure/core}/src/paginateHelper.ts +55 -5
- package/test/integration/generated/azure/core/src/parameters.ts +68 -0
- package/test/integration/generated/azure/core/src/responses.ts +158 -0
- package/test/integration/generated/azure/core/src/serializeHelper.ts +16 -0
- package/test/integration/generated/azure/core/tspconfig.yaml +15 -0
- package/test/integration/generated/azure/core-traits/README.md +56 -0
- package/test/integration/generated/azure/core-traits/api-extractor.json +18 -0
- package/test/integration/generated/azure/core-traits/package.json +80 -0
- package/test/integration/generated/azure/core-traits/src/azureCoreTraitsClient.ts +31 -0
- package/test/integration/generated/azure/core-traits/src/clientDefinitions.ts +22 -0
- package/test/integration/generated/azure/core-traits/src/index.ts +13 -0
- package/test/integration/generated/{resiliency/devDriven → azure/core-traits}/src/isUnexpected.ts +6 -26
- package/test/integration/generated/azure/core-traits/src/outputModels.ts +10 -0
- package/test/integration/generated/azure/core-traits/src/parameters.ts +26 -0
- package/test/integration/generated/azure/core-traits/src/responses.ts +32 -0
- package/test/integration/generated/azure/core-traits/tspconfig.yaml +15 -0
- package/test/integration/generated/dictionary/package.json +2 -2
- package/test/integration/generated/dictionary/src/clientDefinitions.ts +35 -20
- package/test/integration/generated/dictionary/src/parameters.ts +8 -0
- package/test/integration/generated/dictionary/src/responses.ts +11 -0
- package/test/integration/generated/dictionary/tspconfig.yaml +5 -2
- package/test/integration/generated/enums/extensible/README.md +3 -3
- package/test/integration/generated/enums/extensible/package.json +2 -2
- package/test/integration/generated/enums/extensible/src/clientDefinitions.ts +5 -5
- package/test/integration/generated/enums/extensible/src/index.ts +3 -3
- package/test/integration/generated/enums/extensible/src/{enumsExtensible.ts → typeEnumExtensible.ts} +4 -4
- package/test/integration/generated/enums/extensible/tspconfig.yaml +5 -2
- package/test/integration/generated/enums/fixed/README.md +3 -3
- package/test/integration/generated/enums/fixed/package.json +2 -2
- package/test/integration/generated/enums/fixed/src/clientDefinitions.ts +5 -5
- package/test/integration/generated/enums/fixed/src/index.ts +3 -3
- package/test/integration/generated/enums/fixed/src/{enumsFixed.ts → typeEnumFixed.ts} +4 -4
- package/test/integration/generated/enums/fixed/tspconfig.yaml +5 -2
- package/test/integration/generated/hello/package.json +2 -2
- package/test/integration/generated/hello/tspconfig.yaml +5 -2
- package/test/integration/generated/internal/src/clientDefinitions.ts +27 -0
- package/test/integration/generated/internal/src/index.ts +13 -0
- package/test/integration/generated/{lro/lroBasic/src/azureLro.ts → internal/src/internalClient.ts} +5 -5
- package/test/integration/generated/internal/src/models.ts +8 -0
- package/test/integration/generated/internal/src/outputModels.ts +13 -0
- package/test/integration/generated/internal/src/parameters.ts +21 -0
- package/test/integration/generated/internal/src/responses.ts +20 -0
- package/test/integration/generated/internal/tspconfig.yaml +14 -0
- package/test/integration/generated/lro/lroCore/.eslintrc.json +11 -0
- package/test/integration/generated/lro/lroCore/README.md +56 -0
- package/test/integration/generated/{resiliency/devDriven → lro/lroCore}/api-extractor.json +1 -1
- package/test/integration/generated/lro/{lroBasic → lroCore}/package.json +6 -6
- package/test/integration/generated/lro/lroCore/rollup.config.js +118 -0
- package/test/integration/generated/lro/lroCore/src/clientDefinitions.ts +54 -0
- package/test/integration/generated/lro/lroCore/src/index.ts +15 -0
- package/test/integration/generated/lro/lroCore/src/isUnexpected.ts +135 -0
- package/test/integration/generated/lro/lroCore/src/models.ts +8 -0
- package/test/integration/generated/lro/lroCore/src/outputModels.ts +50 -0
- package/test/integration/generated/lro/lroCore/src/parameters.ts +25 -0
- package/test/integration/generated/lro/{lroBasic → lroCore}/src/pollingHelper.ts +38 -0
- package/test/integration/generated/lro/lroCore/src/responses.ts +109 -0
- package/test/integration/generated/lro/lroCore/src/specsAzureCoreLroStandard.ts +31 -0
- package/test/integration/generated/lro/lroCore/tsconfig.json +25 -0
- package/test/integration/generated/lro/lroCore/tspconfig.yaml +14 -0
- package/test/integration/generated/lro/lroRPC/.eslintrc.json +11 -0
- package/test/integration/generated/lro/{lroBasic → lroRPC}/README.md +7 -7
- package/test/integration/generated/lro/lroRPC/api-extractor.json +18 -0
- package/test/integration/generated/lro/lroRPC/package.json +82 -0
- package/test/integration/generated/lro/lroRPC/rollup.config.js +118 -0
- package/test/integration/generated/lro/lroRPC/src/clientDefinitions.ts +79 -0
- package/test/integration/generated/lro/lroRPC/src/index.ts +15 -0
- package/test/integration/generated/lro/lroRPC/src/isUnexpected.ts +153 -0
- package/test/integration/generated/lro/lroRPC/src/models.ts +8 -0
- package/test/integration/generated/lro/lroRPC/src/outputModels.ts +40 -0
- package/test/integration/generated/lro/lroRPC/src/parameters.ts +20 -0
- package/test/integration/generated/lro/lroRPC/src/pollingHelper.ts +127 -0
- package/test/integration/generated/lro/lroRPC/src/responses.ts +124 -0
- package/test/integration/generated/lro/lroRPC/src/specsAzureCoreLroRpc.ts +31 -0
- package/test/integration/generated/lro/lroRPC/tsconfig.json +25 -0
- package/test/integration/generated/lro/lroRPC/tspconfig.yaml +14 -0
- package/test/integration/generated/models/inheritance/README.md +3 -3
- package/test/integration/generated/models/inheritance/package.json +2 -2
- package/test/integration/generated/models/inheritance/src/clientDefinitions.ts +13 -11
- package/test/integration/generated/models/inheritance/src/index.ts +3 -3
- package/test/integration/generated/models/inheritance/src/{modelsInheritance.ts → typeModelInheritance.ts} +4 -4
- package/test/integration/generated/models/inheritance/tspconfig.yaml +5 -2
- package/test/integration/generated/models/propertyNullable/.eslintrc.json +11 -0
- package/test/integration/generated/models/propertyNullable/README.md +56 -0
- package/test/integration/generated/models/propertyNullable/api-extractor.json +18 -0
- package/test/integration/generated/models/propertyNullable/package.json +80 -0
- package/test/integration/generated/models/propertyNullable/rollup.config.js +118 -0
- package/test/integration/generated/models/propertyNullable/src/clientDefinitions.ts +227 -0
- package/test/integration/generated/models/propertyNullable/src/index.ts +13 -0
- package/test/integration/generated/models/propertyNullable/src/models.ts +56 -0
- package/test/integration/generated/models/propertyNullable/src/outputModels.ts +56 -0
- package/test/integration/generated/models/propertyNullable/src/parameters.ts +197 -0
- package/test/integration/generated/models/propertyNullable/src/responses.ts +144 -0
- package/test/integration/generated/{resiliency/devDriven/src/resiliencyDevDriven.ts → models/propertyNullable/src/typePropertyNullable.ts} +5 -5
- package/test/integration/generated/models/propertyNullable/tsconfig.json +25 -0
- package/test/integration/generated/models/propertyNullable/tspconfig.yaml +14 -0
- package/test/integration/generated/models/propertyOptional/README.md +3 -3
- package/test/integration/generated/models/propertyOptional/package.json +2 -2
- package/test/integration/generated/models/propertyOptional/src/clientDefinitions.ts +47 -47
- package/test/integration/generated/models/propertyOptional/src/index.ts +3 -3
- package/test/integration/generated/models/propertyOptional/src/parameters.ts +7 -6
- package/test/integration/generated/models/propertyOptional/src/responses.ts +4 -4
- package/test/integration/generated/models/propertyOptional/src/{modelsPropertyOptional.ts → typePropertyOptional.ts} +4 -4
- package/test/integration/generated/models/propertyOptional/tspconfig.yaml +5 -2
- package/test/integration/generated/models/propertyTypes/README.md +3 -3
- package/test/integration/generated/models/propertyTypes/package.json +2 -2
- package/test/integration/generated/models/propertyTypes/src/clientDefinitions.ts +55 -47
- package/test/integration/generated/models/propertyTypes/src/index.ts +3 -3
- package/test/integration/generated/models/propertyTypes/src/parameters.ts +8 -6
- package/test/integration/generated/models/propertyTypes/src/responses.ts +4 -4
- package/test/integration/generated/models/propertyTypes/src/{modelsPropertyTypes.ts → typePropertyValueTypes.ts} +4 -4
- package/test/integration/generated/models/propertyTypes/tspconfig.yaml +5 -2
- package/test/integration/generated/models/usage/README.md +3 -3
- package/test/integration/generated/models/usage/package.json +2 -2
- package/test/integration/generated/models/usage/src/clientDefinitions.ts +7 -7
- package/test/integration/generated/models/usage/src/index.ts +3 -3
- package/test/integration/generated/models/usage/src/{modelsUsage.ts → typeModelUsage.ts} +4 -4
- package/test/integration/generated/models/usage/tspconfig.yaml +5 -2
- package/test/integration/generated/models/visibility/README.md +3 -3
- package/test/integration/generated/models/visibility/package.json +2 -2
- package/test/integration/generated/models/visibility/src/clientDefinitions.ts +3 -3
- package/test/integration/generated/models/visibility/src/index.ts +3 -3
- package/test/integration/generated/models/visibility/src/{modelsVisibilityAutomatic.ts → typeModelVisibility.ts} +4 -4
- package/test/integration/generated/models/visibility/tspconfig.yaml +5 -2
- package/test/integration/generated/parameters/collection-format/src/clientDefinitions.ts +63 -0
- package/test/integration/generated/parameters/collection-format/src/collectionFormatClient.ts +31 -0
- package/test/integration/generated/parameters/collection-format/src/index.ts +12 -0
- package/test/integration/generated/parameters/collection-format/src/parameters.ts +71 -0
- package/test/integration/generated/parameters/collection-format/src/responses.ts +34 -0
- package/test/integration/generated/parameters/collection-format/src/serializeHelper.ts +28 -0
- package/test/integration/generated/parameters/collection-format/tspconfig.yaml +14 -0
- package/test/integration/generated/parameters/spread/src/clientDefinitions.ts +61 -0
- package/test/integration/generated/{lro/lroBasic → parameters/spread}/src/index.ts +4 -4
- package/test/integration/generated/parameters/spread/src/models.ts +7 -0
- package/test/integration/generated/parameters/spread/src/parameters.ts +61 -0
- package/test/integration/generated/parameters/spread/src/parametersSpread.ts +31 -0
- package/test/integration/generated/parameters/spread/src/responses.ts +25 -0
- package/test/integration/generated/parameters/spread/tspconfig.yaml +12 -0
- package/test/integration/generated/projection/src/clientDefinitions.ts +71 -0
- package/test/integration/generated/projection/src/index.ts +12 -0
- package/test/integration/generated/projection/src/models.ts +22 -0
- package/test/integration/generated/projection/src/parameters.ts +48 -0
- package/test/integration/generated/projection/src/projectionClient.ts +31 -0
- package/test/integration/generated/projection/src/responses.ts +34 -0
- package/test/integration/generated/projection/tspconfig.yaml +14 -0
- package/test/integration/generated/resiliency/srvDriven1/README.md +4 -4
- package/test/integration/generated/resiliency/srvDriven1/package.json +2 -2
- package/test/integration/generated/resiliency/srvDriven1/src/clientDefinitions.ts +25 -49
- package/test/integration/generated/resiliency/srvDriven1/src/index.ts +3 -5
- package/test/integration/generated/resiliency/srvDriven1/src/parameters.ts +11 -32
- package/test/integration/generated/resiliency/srvDriven1/src/responses.ts +9 -24
- package/test/integration/generated/resiliency/srvDriven1/src/serviceDrivenOldClient.ts +39 -0
- package/test/integration/generated/resiliency/srvDriven1/tspconfig.yaml +6 -2
- package/test/integration/generated/resiliency/srvDriven2/README.md +13 -4
- package/test/integration/generated/resiliency/srvDriven2/package.json +2 -2
- package/test/integration/generated/resiliency/srvDriven2/src/clientDefinitions.ts +32 -68
- package/test/integration/generated/resiliency/srvDriven2/src/index.ts +3 -5
- package/test/integration/generated/resiliency/srvDriven2/src/parameters.ts +19 -42
- package/test/integration/generated/resiliency/srvDriven2/src/responses.ts +10 -31
- package/test/integration/generated/resiliency/srvDriven2/src/serviceDrivenNewClient.ts +39 -0
- package/test/integration/generated/resiliency/srvDriven2/tspconfig.yaml +6 -2
- package/test/integration/generated/server/path/multiple/src/clientDefinitions.ts +35 -0
- package/test/integration/generated/server/path/multiple/src/index.ts +11 -0
- package/test/integration/generated/server/path/multiple/src/multipleParamInServerPathClient.ts +39 -0
- package/test/integration/generated/server/path/multiple/src/parameters.ts +7 -0
- package/test/integration/generated/server/path/multiple/src/responses.ts +14 -0
- package/test/integration/generated/server/path/multiple/tspconfig.yaml +14 -0
- package/test/integration/generated/server/path/single/src/clientDefinitions.ts +19 -0
- package/test/integration/generated/server/path/single/src/index.ts +11 -0
- package/test/integration/generated/server/path/single/src/parameters.ts +6 -0
- package/test/integration/generated/server/path/single/src/responses.ts +9 -0
- package/test/integration/generated/server/path/single/src/singleParamInServerPathClient.ts +34 -0
- package/test/integration/generated/server/path/single/tspconfig.yaml +14 -0
- package/test/integration/generated/specialWords/tspconfig.yaml +5 -2
- package/test/integration/generated/unions/src/clientDefinitions.ts +8 -8
- package/test/integration/generated/unions/tspconfig.yaml +5 -2
- package/test/integration/internal.spec.ts +43 -0
- package/test/integration/lroCore.spec.ts +89 -0
- package/test/integration/modelInheritance.spec.ts +13 -13
- package/test/integration/modelPropertyNullable.spec.ts +115 -0
- package/test/integration/modelPropertyOptional.spec.ts +32 -32
- package/test/integration/modelPropertyType.spec.ts +6 -6
- package/test/integration/modelUsage.spec.ts +7 -7
- package/test/integration/projection.spec.ts +102 -0
- package/test/integration/resiliencyDpgCustomization.spec.ts +69 -35
- package/test/integration/server.spec.ts +59 -0
- package/test/integration/spreadParameters.spec.ts +82 -0
- package/test/integration/unions.spec.ts +4 -4
- package/test/unit/apiVersion.spec.ts +388 -0
- package/test/unit/clientFactoryGenerator.spec.ts +0 -131
- package/test/unit/modelsGenerator.spec.ts +2 -2
- package/test/unit/parametersGenerator.spec.ts +1 -1
- package/test/unit/responsesGenerator.spec.ts +1 -1
- package/test/unit/util/emitUtil.ts +6 -5
- package/test/unit/util/testUtil.ts +3 -3
- package/dist/src/transform/transformAnnotationDetails.d.ts +0 -6
- package/dist/src/transform/transformAnnotationDetails.d.ts.map +0 -1
- package/dist/src/transform/transformAnnotationDetails.js.map +0 -1
- package/dist/src/transform/transformApiVersionParam.d.ts +0 -5
- package/dist/src/transform/transformApiVersionParam.d.ts.map +0 -1
- package/dist/src/transform/transformApiVersionParam.js +0 -76
- package/dist/src/transform/transformApiVersionParam.js.map +0 -1
- package/src/transform/transformApiVersionParam.ts +0 -104
- package/test/integration/generated/lro/lroBasic/src/clientDefinitions.ts +0 -37
- package/test/integration/generated/lro/lroBasic/src/parameters.ts +0 -8
- package/test/integration/generated/lro/lroBasic/src/responses.ts +0 -22
- package/test/integration/generated/lro/lroBasic/tspconfig.yaml +0 -11
- package/test/integration/generated/resiliency/devDriven/src/clientDefinitions.ts +0 -75
- package/test/integration/generated/resiliency/devDriven/src/models.ts +0 -8
- package/test/integration/generated/resiliency/devDriven/src/outputModels.ts +0 -25
- package/test/integration/generated/resiliency/devDriven/src/parameters.ts +0 -17
- package/test/integration/generated/resiliency/devDriven/src/responses.ts +0 -62
- package/test/integration/generated/resiliency/devDriven/tspconfig.yaml +0 -11
- package/test/integration/generated/resiliency/srvDriven1/src/models.ts +0 -6
- package/test/integration/generated/resiliency/srvDriven1/src/outputModels.ts +0 -6
- package/test/integration/generated/resiliency/srvDriven1/src/resiliencyServiceDriven1.ts +0 -31
- package/test/integration/generated/resiliency/srvDriven2/src/models.ts +0 -6
- package/test/integration/generated/resiliency/srvDriven2/src/outputModels.ts +0 -6
- package/test/integration/generated/resiliency/srvDriven2/src/resiliencyServiceDriven2.ts +0 -31
- package/test/integration/helloWorld.spec.ts +0 -20
- package/test/integration/lroBasic.spec.ts +0 -25
- /package/test/integration/generated/{resiliency/devDriven → azure/core}/.eslintrc.json +0 -0
- /package/test/integration/generated/{resiliency/devDriven → azure/core}/rollup.config.js +0 -0
- /package/test/integration/generated/{resiliency/devDriven → azure/core}/tsconfig.json +0 -0
- /package/test/integration/generated/{lro/lroBasic → azure/core-traits}/.eslintrc.json +0 -0
- /package/test/integration/generated/{lro/lroBasic → azure/core-traits}/rollup.config.js +0 -0
- /package/test/integration/generated/{lro/lroBasic → azure/core-traits}/tsconfig.json +0 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionDeclarationStructure,
|
|
3
|
+
OptionalKind,
|
|
4
|
+
ParameterDeclarationStructure
|
|
5
|
+
} from "ts-morph";
|
|
6
|
+
import { toPascalCase } from "../../casingUtils.js";
|
|
7
|
+
import {
|
|
8
|
+
BodyParameter,
|
|
9
|
+
Operation,
|
|
10
|
+
Parameter,
|
|
11
|
+
Property,
|
|
12
|
+
Type
|
|
13
|
+
} from "../modularCodeModel.js";
|
|
14
|
+
import { buildType } from "./typeHelpers.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This operation builds and returns the function declaration for an operation.
|
|
18
|
+
*/
|
|
19
|
+
export function getOperationFunction(
|
|
20
|
+
operation: Operation
|
|
21
|
+
): OptionalKind<FunctionDeclarationStructure> {
|
|
22
|
+
const optionsType = getOperationOptionsName(operation);
|
|
23
|
+
// Extract required parameters
|
|
24
|
+
let parameters: OptionalKind<ParameterDeclarationStructure>[] = [];
|
|
25
|
+
|
|
26
|
+
if (operation.bodyParameter?.type.type === "model") {
|
|
27
|
+
parameters = (operation.bodyParameter?.type.properties ?? [])
|
|
28
|
+
.filter((p) => !p.optional)
|
|
29
|
+
.map((p) => buildType(p.clientName, p.type));
|
|
30
|
+
} else if (operation.bodyParameter?.type.type === "list") {
|
|
31
|
+
const bodyArray = operation.bodyParameter;
|
|
32
|
+
parameters.push(buildType(bodyArray.clientName, bodyArray.type));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
parameters = parameters.concat(
|
|
36
|
+
operation.parameters
|
|
37
|
+
.filter(
|
|
38
|
+
(p) =>
|
|
39
|
+
p.implementation === "Method" &&
|
|
40
|
+
p.type.type !== "constant" &&
|
|
41
|
+
p.clientDefaultValue === undefined &&
|
|
42
|
+
!p.optional
|
|
43
|
+
)
|
|
44
|
+
.map((p) => buildType(p.clientName, p.type))
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Add context as the first parameter
|
|
48
|
+
parameters.unshift({ name: "context", type: "Client" });
|
|
49
|
+
|
|
50
|
+
// Add the options parameter
|
|
51
|
+
parameters.push({
|
|
52
|
+
name: "options",
|
|
53
|
+
type: optionsType,
|
|
54
|
+
initializer: "{ requestOptions: {} }"
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// TODO: Support operation overloads
|
|
58
|
+
const response = operation.responses[0]!;
|
|
59
|
+
const returnType =
|
|
60
|
+
response?.type?.type === "model"
|
|
61
|
+
? buildType(response.type.name, response.type)
|
|
62
|
+
: { name: "", type: "void" };
|
|
63
|
+
|
|
64
|
+
const functionStatement: OptionalKind<FunctionDeclarationStructure> = {
|
|
65
|
+
docs: [operation.description],
|
|
66
|
+
isAsync: true,
|
|
67
|
+
isExported: true,
|
|
68
|
+
name: operation.name,
|
|
69
|
+
parameters,
|
|
70
|
+
returnType: `Promise<${returnType.type}>`
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const operationPath = operation.url;
|
|
74
|
+
const operationMethod = operation.method.toLowerCase();
|
|
75
|
+
|
|
76
|
+
const statements: string[] = [];
|
|
77
|
+
statements.push(
|
|
78
|
+
`const result = await context.path("${operationPath}", ${getPathParameters(
|
|
79
|
+
operation
|
|
80
|
+
)}).${operationMethod}({${getRequestParameters(operation)}});`
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
statements.push(`if(isUnexpected(result)){`, "throw result.body", "}");
|
|
84
|
+
|
|
85
|
+
if (!response?.type?.properties) {
|
|
86
|
+
statements.push(`return;`);
|
|
87
|
+
} else {
|
|
88
|
+
statements.push(
|
|
89
|
+
`return {`,
|
|
90
|
+
getResponseMapping(response.type.properties ?? []).join(","),
|
|
91
|
+
`}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...functionStatement,
|
|
96
|
+
statements
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getOperationOptionsName(operation: Operation) {
|
|
101
|
+
return `${toPascalCase(operation.groupName)}${toPascalCase(
|
|
102
|
+
operation.name
|
|
103
|
+
)}Options`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* This function build the request parameters that we will provide to the
|
|
108
|
+
* RLC internally. This will translate High Level parameters into the RLC ones.
|
|
109
|
+
* Figuring out what goes in headers, body, path and qsp.
|
|
110
|
+
*/
|
|
111
|
+
function getRequestParameters(operation: Operation): string {
|
|
112
|
+
if (!operation.parameters) {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const operationParameters = operation.parameters.filter(
|
|
117
|
+
(p) => p.implementation !== "Client" && !isContentType(p)
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const contentTypeParameter = operation.parameters.find(isContentType);
|
|
121
|
+
|
|
122
|
+
const parametersImplementation: Record<
|
|
123
|
+
"header" | "query" | "body",
|
|
124
|
+
string[]
|
|
125
|
+
> = {
|
|
126
|
+
header: [],
|
|
127
|
+
query: [],
|
|
128
|
+
body: []
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
for (const param of operationParameters) {
|
|
132
|
+
if (param.location === "header" || param.location === "query") {
|
|
133
|
+
parametersImplementation[param.location].push(getParameterMap(param));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let paramStr = "";
|
|
138
|
+
|
|
139
|
+
if (contentTypeParameter) {
|
|
140
|
+
paramStr = `${getContentTypeValue(contentTypeParameter)},`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (parametersImplementation.header.length) {
|
|
144
|
+
paramStr = `${paramStr}\nheaders: {${parametersImplementation.header.join(
|
|
145
|
+
",\n"
|
|
146
|
+
)}, ...options.requestOptions?.headers},`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (parametersImplementation.query.length) {
|
|
150
|
+
paramStr = `${paramStr}\nqueryParameters: {${parametersImplementation.query.join(
|
|
151
|
+
",\n"
|
|
152
|
+
)}},`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
paramStr = `${paramStr}${buildBodyParameter(operation.bodyParameter)}`;
|
|
156
|
+
|
|
157
|
+
return paramStr;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildBodyParameter(bodyParameter: BodyParameter | undefined) {
|
|
161
|
+
if (!bodyParameter) {
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (bodyParameter.type.type === "model") {
|
|
166
|
+
const bodyParts: string[] = [];
|
|
167
|
+
for (const param of bodyParameter?.type.properties?.filter(
|
|
168
|
+
(p) => !p.readonly
|
|
169
|
+
) ?? []) {
|
|
170
|
+
bodyParts.push(getParameterMap(param));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (bodyParameter && bodyParameter.type.properties) {
|
|
174
|
+
return `\nbody: {${bodyParts.join(",\n")}},`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (bodyParameter.type.type === "list") {
|
|
179
|
+
return `\nbody: ${bodyParameter.clientName},`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* This function helps with renames, translating client names to rest api names
|
|
187
|
+
*/
|
|
188
|
+
function getParameterMap(param: Parameter | Property) {
|
|
189
|
+
if (isConstant(param)) {
|
|
190
|
+
return getConstantValue(param);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isOptionalWithouDefault(param)) {
|
|
194
|
+
return getOptionalWithoutDefault(param);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isOptionalWithDefault(param)) {
|
|
198
|
+
return getOptionalWithDefault(param);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (isRequired(param)) {
|
|
202
|
+
return getRequired(param);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
throw new Error(`Parameter ${param.clientName} is not supported`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function isContentType(param: Parameter): boolean {
|
|
209
|
+
return (
|
|
210
|
+
param.location === "header" &&
|
|
211
|
+
param.restApiName.toLowerCase() === "content-type"
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getContentTypeValue(param: Parameter | Property) {
|
|
216
|
+
const defaultValue =
|
|
217
|
+
param.clientDefaultValue ?? param.type.clientDefaultValue;
|
|
218
|
+
|
|
219
|
+
if (!defaultValue) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Constant ${param.clientName} does not have a default value`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (defaultValue) {
|
|
226
|
+
return `contentType: (options.${param.clientName} as any) ?? "${defaultValue}"`;
|
|
227
|
+
} else {
|
|
228
|
+
return `contentType: options.${param.clientName}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
type RequiredType = (Parameter | Property) & {
|
|
233
|
+
type: { optional: false | undefined; value: string };
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
function isRequired(param: Parameter | Property): param is RequiredType {
|
|
237
|
+
return !param.optional;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getRequired(param: RequiredType) {
|
|
241
|
+
return `"${param.restApiName}": ${param.clientName}`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
type ConstantType = (Parameter | Property) & {
|
|
245
|
+
type: { type: "constant"; value: string };
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
function getConstantValue(param: ConstantType) {
|
|
249
|
+
const defaultValue =
|
|
250
|
+
param.clientDefaultValue ?? param.type.clientDefaultValue;
|
|
251
|
+
|
|
252
|
+
if (!defaultValue) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
`Constant ${param.clientName} does not have a default value`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return `"${param.restApiName}": "${defaultValue}"`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function isConstant(param: Parameter | Property): param is ConstantType {
|
|
262
|
+
return (
|
|
263
|
+
param.type.type === "constant" && param.clientDefaultValue !== undefined
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
type OptionalWithoutDefaultType = (Parameter | Property) & {
|
|
268
|
+
type: { optional: true; clientDefaultValue: never };
|
|
269
|
+
};
|
|
270
|
+
function isOptionalWithouDefault(
|
|
271
|
+
param: Parameter | Property
|
|
272
|
+
): param is OptionalWithoutDefaultType {
|
|
273
|
+
return Boolean(param.optional && !param.clientDefaultValue);
|
|
274
|
+
}
|
|
275
|
+
function getOptionalWithoutDefault(param: OptionalWithoutDefaultType) {
|
|
276
|
+
return `...(options.${param.clientName} && {"${param.restApiName}": options.${param.clientName}})`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
type OptionalWithDefaultType = (Parameter | Property) & {
|
|
280
|
+
type: { optional: true; clientDefaultValue: string };
|
|
281
|
+
};
|
|
282
|
+
function isOptionalWithDefault(
|
|
283
|
+
param: Parameter | Property
|
|
284
|
+
): param is OptionalWithDefaultType {
|
|
285
|
+
return Boolean(param.clientDefaultValue);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getOptionalWithDefault(param: OptionalWithDefaultType) {
|
|
289
|
+
return `"${param.restApiName}": options.${
|
|
290
|
+
param.clientName
|
|
291
|
+
} ?? ${getQuotedValue(param)}`;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function getQuotedValue(param: OptionalWithDefaultType) {
|
|
295
|
+
if (param.type.type === "string") {
|
|
296
|
+
return `"${param.clientDefaultValue}"`;
|
|
297
|
+
} else {
|
|
298
|
+
return param.clientDefaultValue;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Builds the assignment for when a property or parameter has a default value
|
|
304
|
+
*/
|
|
305
|
+
function getDefaultValue(param: Parameter | Property) {
|
|
306
|
+
return (param.clientDefaultValue ?? param.type.clientDefaultValue) !==
|
|
307
|
+
undefined
|
|
308
|
+
? `${param.optional ? "??" : ""} "${
|
|
309
|
+
param.clientDefaultValue ?? param.type.clientDefaultValue
|
|
310
|
+
}"`
|
|
311
|
+
: "";
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Extracts the path parameters
|
|
316
|
+
*/
|
|
317
|
+
function getPathParameters(operation: Operation) {
|
|
318
|
+
if (!operation.parameters) {
|
|
319
|
+
return "";
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let pathParams = "";
|
|
323
|
+
for (const param of operation.parameters) {
|
|
324
|
+
if (param.location === "path") {
|
|
325
|
+
if (!param.optional) {
|
|
326
|
+
pathParams = `${pathParams} ${param.clientName},`;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const defaultValue = getDefaultValue(param);
|
|
331
|
+
|
|
332
|
+
pathParams = `${pathParams}, options.${param.clientName}`;
|
|
333
|
+
|
|
334
|
+
if (defaultValue) {
|
|
335
|
+
pathParams = ` ?? "${defaultValue}"`;
|
|
336
|
+
}
|
|
337
|
+
pathParams = `${pathParams},`;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return pathParams;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* This function helps translating an RLC response to an HLC response,
|
|
346
|
+
* extracting properties from body and headers and building the HLC response object
|
|
347
|
+
*/
|
|
348
|
+
function getResponseMapping(
|
|
349
|
+
properties: Property[],
|
|
350
|
+
propertyPath: string = "result.body"
|
|
351
|
+
) {
|
|
352
|
+
const props: string[] = [];
|
|
353
|
+
for (const property of properties) {
|
|
354
|
+
// TODO: Do we need to also add headers in the result type?
|
|
355
|
+
if (property.type.type === "model") {
|
|
356
|
+
props.push(
|
|
357
|
+
`"${property.restApiName}": ${
|
|
358
|
+
!property.optional
|
|
359
|
+
? ""
|
|
360
|
+
: `!${propertyPath}.${property.clientName} ? undefined :`
|
|
361
|
+
} {${getResponseMapping(
|
|
362
|
+
property.type.properties ?? [],
|
|
363
|
+
`${propertyPath}.${property.restApiName}${
|
|
364
|
+
property.optional ? "?" : ""
|
|
365
|
+
}`
|
|
366
|
+
)}}`
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
const dot = propertyPath.endsWith("?") ? "." : "";
|
|
370
|
+
const restValue = `${
|
|
371
|
+
propertyPath ? `${propertyPath}${dot}` : `${dot}`
|
|
372
|
+
}["${property.restApiName}"]`;
|
|
373
|
+
props.push(
|
|
374
|
+
`"${property.clientName}": ${deserializeResponseValue(
|
|
375
|
+
property.type,
|
|
376
|
+
restValue
|
|
377
|
+
)}`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return props;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* This function helps converting strings into JS complex types recursively.
|
|
387
|
+
* We need to drill down into Array elements to make sure that the element type is
|
|
388
|
+
* deserialized correctly
|
|
389
|
+
*/
|
|
390
|
+
function deserializeResponseValue(type: Type, restValue: string): string {
|
|
391
|
+
switch (type.type) {
|
|
392
|
+
case "datetime":
|
|
393
|
+
return `new Date(${restValue} ?? "")`;
|
|
394
|
+
case "list":
|
|
395
|
+
if (type.elementType?.type === "model") {
|
|
396
|
+
return `(${restValue} ?? []).map(p => ({${getResponseMapping(
|
|
397
|
+
type.elementType?.properties ?? [],
|
|
398
|
+
"p"
|
|
399
|
+
)}}))`;
|
|
400
|
+
} else if (
|
|
401
|
+
type.elementType?.properties?.some((p) => needsDeserialize(p.type))
|
|
402
|
+
) {
|
|
403
|
+
return `(${restValue} ?? []).map(p => ${deserializeResponseValue(
|
|
404
|
+
type.elementType!,
|
|
405
|
+
"p"
|
|
406
|
+
)})`;
|
|
407
|
+
} else {
|
|
408
|
+
return restValue;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
default:
|
|
412
|
+
return restValue;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function needsDeserialize(type?: Type) {
|
|
417
|
+
return type?.type === "datetime" || type?.type === "model";
|
|
418
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Parameter } from "../modularCodeModel.js";
|
|
2
|
+
|
|
3
|
+
const parameterTypeMap: Record<string, string> = {
|
|
4
|
+
Key: "AzureKeyCredential",
|
|
5
|
+
OAuth2: "TokenCredential"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function getParameterType(param: Parameter): string {
|
|
9
|
+
switch (param.type.type) {
|
|
10
|
+
case "combined":
|
|
11
|
+
if (!param.type.types) throw new Error("Combined type without types");
|
|
12
|
+
return param.type.types.map((p) => parameterTypeMap[p.type]).join(" | ");
|
|
13
|
+
|
|
14
|
+
default:
|
|
15
|
+
return parameterTypeMap[param.type.type] ?? param.type.type;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Type } from "../modularCodeModel.js";
|
|
2
|
+
|
|
3
|
+
export interface TypeMetadata {
|
|
4
|
+
name: string;
|
|
5
|
+
originModule?: string;
|
|
6
|
+
isRelative?: boolean;
|
|
7
|
+
modifier?: "Array";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getType(type: Type): TypeMetadata {
|
|
11
|
+
switch (type.type) {
|
|
12
|
+
case "Key":
|
|
13
|
+
return {
|
|
14
|
+
name: "AzureKeyCredential",
|
|
15
|
+
originModule: "@azure/core-auth",
|
|
16
|
+
isRelative: false
|
|
17
|
+
};
|
|
18
|
+
case "boolean":
|
|
19
|
+
return { name: "boolean" };
|
|
20
|
+
case "constant": {
|
|
21
|
+
let typeName: string = type.value ?? "undefined";
|
|
22
|
+
if (type.valueType?.type === "string") {
|
|
23
|
+
typeName = type.value ? `"${type.value}"` : "undefined";
|
|
24
|
+
}
|
|
25
|
+
return { name: typeName };
|
|
26
|
+
}
|
|
27
|
+
case "datetime":
|
|
28
|
+
return { name: "Date" };
|
|
29
|
+
case "enum":
|
|
30
|
+
if (!type.name) {
|
|
31
|
+
throw new Error("Unable to process enum without name");
|
|
32
|
+
}
|
|
33
|
+
return { name: type.name, originModule: "models.js" };
|
|
34
|
+
case "float":
|
|
35
|
+
case "integer":
|
|
36
|
+
return { name: "number" };
|
|
37
|
+
case "byte-array":
|
|
38
|
+
return { name: "string" };
|
|
39
|
+
case "list":
|
|
40
|
+
if (!type.elementType) {
|
|
41
|
+
throw new Error("Unable to process Array with no elementType");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
name: getType(type.elementType).name,
|
|
45
|
+
modifier: "Array",
|
|
46
|
+
originModule:
|
|
47
|
+
type.elementType?.type === "model" ? "models.js" : undefined
|
|
48
|
+
};
|
|
49
|
+
case "model":
|
|
50
|
+
if (!type.name) {
|
|
51
|
+
throw new Error("Unable to process model without name");
|
|
52
|
+
}
|
|
53
|
+
return { name: type.name, originModule: "models.js" };
|
|
54
|
+
case "string":
|
|
55
|
+
case "duration":
|
|
56
|
+
return { name: "string" };
|
|
57
|
+
case "combined": {
|
|
58
|
+
if (!type.types) {
|
|
59
|
+
throw new Error("Unable to process combined without combinedTypes");
|
|
60
|
+
}
|
|
61
|
+
const name = type.types
|
|
62
|
+
.map((t) => {
|
|
63
|
+
const sdkType = getTypeName(getType(t));
|
|
64
|
+
return `${sdkType}`;
|
|
65
|
+
})
|
|
66
|
+
.join(" | ");
|
|
67
|
+
return { name };
|
|
68
|
+
}
|
|
69
|
+
case "dict":
|
|
70
|
+
if (!type.elementType) {
|
|
71
|
+
throw new Error("Unable to process dict without elemetType info");
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
name: `Record<string, ${getTypeName(getType(type.elementType))}>`
|
|
75
|
+
};
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unsupported type ${type.type}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getTypeName(typeMetadata: TypeMetadata) {
|
|
82
|
+
let typeName = typeMetadata.name;
|
|
83
|
+
if (typeMetadata.modifier === "Array") {
|
|
84
|
+
typeName = `${typeName}[]`;
|
|
85
|
+
}
|
|
86
|
+
return typeName;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Gets the Typescript representation of a TypeSpec type
|
|
91
|
+
*/
|
|
92
|
+
export function buildType(
|
|
93
|
+
clientName: string | undefined,
|
|
94
|
+
type: Type | undefined
|
|
95
|
+
) {
|
|
96
|
+
if (!type) {
|
|
97
|
+
throw new Error("Type should be defined");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const typeMetadata = getType(type);
|
|
101
|
+
let typeName = typeMetadata.name;
|
|
102
|
+
if (typeMetadata.modifier === "Array") {
|
|
103
|
+
typeName = `${typeName}[]`;
|
|
104
|
+
}
|
|
105
|
+
return { name: clientName ?? "", type: typeName };
|
|
106
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OptionalKind, ParameterDeclarationStructure } from "ts-morph";
|
|
2
|
+
import { Parameter } from "./modularCodeModel.js";
|
|
3
|
+
|
|
4
|
+
export interface ClientDetails {
|
|
5
|
+
name: string;
|
|
6
|
+
params?: OptionalKind<ParameterDeclarationStructure>[];
|
|
7
|
+
description: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
credentialsParam?: Parameter;
|
|
10
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { RLCOptions } from "@azure-tools/rlc-common";
|
|
2
|
+
|
|
3
|
+
export interface ModularCodeModel {
|
|
4
|
+
options: RLCOptions;
|
|
5
|
+
namespace?: string;
|
|
6
|
+
subnamespaceToClients?: any;
|
|
7
|
+
clients: Client[];
|
|
8
|
+
types: Type[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Header {
|
|
12
|
+
type: Type;
|
|
13
|
+
restApiName: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Property {
|
|
17
|
+
clientDefaultValue?: any;
|
|
18
|
+
clientName: string;
|
|
19
|
+
restApiName: string;
|
|
20
|
+
type: Type;
|
|
21
|
+
optional?: boolean;
|
|
22
|
+
description: string;
|
|
23
|
+
readonly?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface BodyParameter {
|
|
27
|
+
contentTypes: string[];
|
|
28
|
+
type: Type;
|
|
29
|
+
restApiName: string;
|
|
30
|
+
location: "body";
|
|
31
|
+
optional: boolean;
|
|
32
|
+
description: string;
|
|
33
|
+
clientName: string;
|
|
34
|
+
inOverload: boolean;
|
|
35
|
+
defaultContentType: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface OperationGroup {
|
|
39
|
+
className: string;
|
|
40
|
+
propertyName: string;
|
|
41
|
+
operations: Operation[];
|
|
42
|
+
}
|
|
43
|
+
export interface Policy {
|
|
44
|
+
type: string;
|
|
45
|
+
key: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface XmlMetadata {}
|
|
49
|
+
export interface EnumValue {
|
|
50
|
+
name: string;
|
|
51
|
+
value: string;
|
|
52
|
+
description: string;
|
|
53
|
+
}
|
|
54
|
+
export interface Type {
|
|
55
|
+
name?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
type:
|
|
58
|
+
| "string"
|
|
59
|
+
| "Key"
|
|
60
|
+
| "OAuth2"
|
|
61
|
+
| "constant"
|
|
62
|
+
| "model"
|
|
63
|
+
| "list"
|
|
64
|
+
| "byte-array"
|
|
65
|
+
| "datetime"
|
|
66
|
+
| "float"
|
|
67
|
+
| "duration"
|
|
68
|
+
| "enum"
|
|
69
|
+
| "integer"
|
|
70
|
+
| "float"
|
|
71
|
+
| "boolean"
|
|
72
|
+
| "dict"
|
|
73
|
+
| "combined";
|
|
74
|
+
policy?: Policy;
|
|
75
|
+
apiVersions?: any[];
|
|
76
|
+
clientDefaultValue?: any;
|
|
77
|
+
value?: string;
|
|
78
|
+
values?: EnumValue[];
|
|
79
|
+
isFixed?: boolean;
|
|
80
|
+
valueType?: Type;
|
|
81
|
+
elementType?: Type;
|
|
82
|
+
xmlMetadata?: XmlMetadata;
|
|
83
|
+
format?: string;
|
|
84
|
+
properties?: Property[];
|
|
85
|
+
types?: Type[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface Client {
|
|
89
|
+
name: string;
|
|
90
|
+
description: string;
|
|
91
|
+
parameters: Parameter[];
|
|
92
|
+
operationGroups: OperationGroup[];
|
|
93
|
+
url: string;
|
|
94
|
+
apiVersions: any[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type ParameterLocation =
|
|
98
|
+
| "endpointPath"
|
|
99
|
+
| "header"
|
|
100
|
+
| "query"
|
|
101
|
+
| "path"
|
|
102
|
+
| "other";
|
|
103
|
+
|
|
104
|
+
export interface Parameter {
|
|
105
|
+
optional: boolean;
|
|
106
|
+
description: string;
|
|
107
|
+
clientName: string;
|
|
108
|
+
inOverload: boolean;
|
|
109
|
+
restApiName: string;
|
|
110
|
+
location: ParameterLocation;
|
|
111
|
+
type: Type;
|
|
112
|
+
implementation: string;
|
|
113
|
+
skipUrlEncoding?: boolean;
|
|
114
|
+
clientDefaultValue?: string | null;
|
|
115
|
+
in_docstring?: boolean;
|
|
116
|
+
checkClientInput?: boolean;
|
|
117
|
+
delimiter?: any;
|
|
118
|
+
explode?: boolean;
|
|
119
|
+
groupedBy?: any;
|
|
120
|
+
inDocstring?: boolean;
|
|
121
|
+
inOverriden?: boolean;
|
|
122
|
+
isApiVersion?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface Response {
|
|
126
|
+
headers: Header[];
|
|
127
|
+
statusCodes: (number | "default")[];
|
|
128
|
+
discriminator: string;
|
|
129
|
+
type: Type;
|
|
130
|
+
addedOn?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Operation {
|
|
134
|
+
name: string;
|
|
135
|
+
description: string;
|
|
136
|
+
summary: string;
|
|
137
|
+
url: string;
|
|
138
|
+
method: string;
|
|
139
|
+
parameters: Parameter[];
|
|
140
|
+
bodyParameter?: BodyParameter;
|
|
141
|
+
responses: Response[];
|
|
142
|
+
exceptions: Response[];
|
|
143
|
+
groupName: string;
|
|
144
|
+
discriminator: string;
|
|
145
|
+
isOverload: boolean;
|
|
146
|
+
overloads: any[];
|
|
147
|
+
apiVersions: any[];
|
|
148
|
+
itemName?: string;
|
|
149
|
+
continuationTokenName?: string;
|
|
150
|
+
addedOn?: string;
|
|
151
|
+
}
|