@azure-tools/typespec-ts 0.11.0-alpha.20230413.3
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/.eslintrc.json +23 -0
- package/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/.rush/temp/package-deps_build.json +392 -0
- package/.rush/temp/shrinkwrap-deps.json +472 -0
- package/CHANGELOG.md +65 -0
- package/CONTRIBUTING.md +137 -0
- package/README.md +150 -0
- 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.d.ts +6 -0
- package/dist/src/emitUtil.d.ts.map +1 -0
- package/dist/src/emitUtil.js +45 -0
- package/dist/src/emitUtil.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +90 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +159 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +190 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/modelUtils.d.ts +33 -0
- package/dist/src/modelUtils.d.ts.map +1 -0
- package/dist/src/modelUtils.js +900 -0
- package/dist/src/modelUtils.js.map +1 -0
- 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 +116 -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 +65 -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 +1106 -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 +68 -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 +188 -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 +49 -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 +22 -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 +191 -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 +11 -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 +71 -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 +120 -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 +16 -0
- package/dist/src/operationUtil.d.ts.map +1 -0
- package/dist/src/operationUtil.js +142 -0
- package/dist/src/operationUtil.js.map +1 -0
- package/dist/src/transform/transform.d.ts +6 -0
- package/dist/src/transform/transform.d.ts.map +1 -0
- package/dist/src/transform/transform.js +87 -0
- package/dist/src/transform/transform.js.map +1 -0
- package/dist/src/transform/transformAnnotationDetails.d.ts +6 -0
- package/dist/src/transform/transformAnnotationDetails.d.ts.map +1 -0
- package/dist/src/transform/transformAnnotationDetails.js +188 -0
- package/dist/src/transform/transformAnnotationDetails.js.map +1 -0
- 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/transformParameters.d.ts +14 -0
- package/dist/src/transform/transformParameters.d.ts.map +1 -0
- package/dist/src/transform/transformParameters.js +314 -0
- package/dist/src/transform/transformParameters.js.map +1 -0
- package/dist/src/transform/transformPaths.d.ts +10 -0
- package/dist/src/transform/transformPaths.d.ts.map +1 -0
- package/dist/src/transform/transformPaths.js +124 -0
- package/dist/src/transform/transformPaths.js.map +1 -0
- package/dist/src/transform/transformResponses.d.ts +5 -0
- package/dist/src/transform/transformResponses.d.ts.map +1 -0
- package/dist/src/transform/transformResponses.js +136 -0
- package/dist/src/transform/transformResponses.js.map +1 -0
- package/dist/src/transform/transformSchemas.d.ts +4 -0
- package/dist/src/transform/transformSchemas.d.ts.map +1 -0
- package/dist/src/transform/transformSchemas.js +161 -0
- package/dist/src/transform/transformSchemas.js.map +1 -0
- package/dist/src/transform/transfromRLCOptions.d.ts +10 -0
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -0
- package/dist/src/transform/transfromRLCOptions.js +156 -0
- package/dist/src/transform/transfromRLCOptions.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +80 -0
- package/src/casingUtils.ts +48 -0
- package/src/emitUtil.ts +63 -0
- package/src/index.ts +148 -0
- package/src/lib.ts +208 -0
- package/src/modelUtils.ts +1080 -0
- package/src/modular/buildApiIndex.ts +13 -0
- package/src/modular/buildClassicalClient.ts +154 -0
- package/src/modular/buildClientContext.ts +96 -0
- package/src/modular/buildCodeModel.ts +1444 -0
- package/src/modular/buildOperations.ts +93 -0
- package/src/modular/buildProjectFiles.ts +217 -0
- package/src/modular/buildRootIndex.ts +75 -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 +29 -0
- package/src/modular/helpers/namingHelpers.ts +5 -0
- package/src/modular/helpers/operationHelpers.ts +289 -0
- package/src/modular/helpers/parameterHelpers.ts +12 -0
- package/src/modular/helpers/typeHelpers.ts +84 -0
- package/src/modular/interfaces.ts +10 -0
- package/src/modular/modularCodeModel.ts +148 -0
- package/src/operationUtil.ts +203 -0
- package/src/transform/transform.ts +154 -0
- package/src/transform/transformAnnotationDetails.ts +231 -0
- package/src/transform/transformApiVersionInfo.ts +108 -0
- package/src/transform/transformParameters.ts +480 -0
- package/src/transform/transformPaths.ts +187 -0
- package/src/transform/transformResponses.ts +190 -0
- package/src/transform/transformSchemas.ts +197 -0
- package/src/transform/transfromRLCOptions.ts +202 -0
- package/test/commands/cadl-ranch-list.ts +111 -0
- package/test/commands/check-clean-tree.ts +55 -0
- package/test/commands/childProcessOnExit.ts +16 -0
- package/test/commands/gen-cadl-ranch.ts +21 -0
- package/test/commands/run.ts +31 -0
- package/test/integration/arrayItemTypes.spec.ts +96 -0
- package/test/integration/authApiKey.spec.ts +38 -0
- package/test/integration/authOauth2.spec.ts +65 -0
- package/test/integration/authUnion.spec.ts +72 -0
- package/test/integration/collectionFormat.spec.ts +74 -0
- package/test/integration/dictionary.spec.ts +106 -0
- package/test/integration/extensibleEnums.spec.ts +61 -0
- package/test/integration/fixedEnums.spec.ts +52 -0
- package/test/integration/generated/arrays/itemTypes/src/arrayItemTypesClient.ts +31 -0
- package/test/integration/generated/arrays/itemTypes/src/clientDefinitions.ts +165 -0
- package/test/integration/generated/arrays/itemTypes/src/index.ts +13 -0
- package/test/integration/generated/arrays/itemTypes/src/models.ts +9 -0
- package/test/integration/generated/arrays/itemTypes/src/outputModels.ts +9 -0
- package/test/integration/generated/arrays/itemTypes/src/parameters.ts +86 -0
- package/test/integration/generated/arrays/itemTypes/src/responses.ts +115 -0
- package/test/integration/generated/arrays/itemTypes/tspconfig.yaml +15 -0
- package/test/integration/generated/authentication/apiKey/.eslintrc.json +11 -0
- package/test/integration/generated/authentication/apiKey/README.md +56 -0
- package/test/integration/generated/authentication/apiKey/api-extractor.json +18 -0
- package/test/integration/generated/authentication/apiKey/karma.conf.js +133 -0
- package/test/integration/generated/authentication/apiKey/package.json +103 -0
- package/test/integration/generated/authentication/apiKey/rollup.config.js +118 -0
- package/test/integration/generated/authentication/apiKey/src/authApiKeyClient.ts +41 -0
- package/test/integration/generated/authentication/apiKey/src/clientDefinitions.ts +33 -0
- package/test/integration/generated/authentication/apiKey/src/index.ts +12 -0
- package/test/integration/generated/authentication/apiKey/src/outputModels.ts +6 -0
- package/test/integration/generated/authentication/apiKey/src/parameters.ts +7 -0
- package/test/integration/generated/authentication/apiKey/src/responses.ts +21 -0
- package/test/integration/generated/authentication/apiKey/test/public/sampleTest.spec.ts +23 -0
- package/test/integration/generated/authentication/apiKey/test/public/utils/env.browser.ts +2 -0
- package/test/integration/generated/authentication/apiKey/test/public/utils/env.ts +6 -0
- package/test/integration/generated/authentication/apiKey/test/public/utils/recordedClient.ts +29 -0
- package/test/integration/generated/authentication/apiKey/tsconfig.json +25 -0
- package/test/integration/generated/authentication/apiKey/tspconfig.yaml +13 -0
- package/test/integration/generated/authentication/oauth2/karma.conf.js +133 -0
- package/test/integration/generated/authentication/oauth2/src/authOauth2Client.ts +41 -0
- package/test/integration/generated/authentication/oauth2/src/clientDefinitions.ts +33 -0
- package/test/integration/generated/authentication/oauth2/src/index.ts +12 -0
- package/test/integration/generated/authentication/oauth2/src/outputModels.ts +6 -0
- package/test/integration/generated/authentication/oauth2/src/parameters.ts +7 -0
- package/test/integration/generated/authentication/oauth2/src/responses.ts +21 -0
- package/test/integration/generated/authentication/oauth2/test/public/sampleTest.spec.ts +23 -0
- package/test/integration/generated/authentication/oauth2/test/public/utils/env.browser.ts +2 -0
- package/test/integration/generated/authentication/oauth2/test/public/utils/env.ts +6 -0
- package/test/integration/generated/authentication/oauth2/test/public/utils/recordedClient.ts +29 -0
- package/test/integration/generated/authentication/oauth2/tspconfig.yaml +15 -0
- package/test/integration/generated/authentication/union/karma.conf.js +133 -0
- package/test/integration/generated/authentication/union/src/authUnionClient.ts +42 -0
- package/test/integration/generated/authentication/union/src/clientDefinitions.ts +27 -0
- package/test/integration/generated/authentication/union/src/index.ts +11 -0
- package/test/integration/generated/authentication/union/src/parameters.ts +7 -0
- package/test/integration/generated/authentication/union/src/responses.ts +14 -0
- package/test/integration/generated/authentication/union/test/public/sampleTest.spec.ts +23 -0
- package/test/integration/generated/authentication/union/test/public/utils/env.browser.ts +2 -0
- package/test/integration/generated/authentication/union/test/public/utils/env.ts +6 -0
- package/test/integration/generated/authentication/union/test/public/utils/recordedClient.ts +29 -0
- package/test/integration/generated/authentication/union/tspconfig.yaml +15 -0
- package/test/integration/generated/dictionary/.eslintrc.json +11 -0
- package/test/integration/generated/dictionary/README.md +56 -0
- package/test/integration/generated/dictionary/api-extractor.json +18 -0
- package/test/integration/generated/dictionary/package.json +80 -0
- package/test/integration/generated/dictionary/rollup.config.js +118 -0
- package/test/integration/generated/dictionary/src/clientDefinitions.ts +180 -0
- package/test/integration/generated/dictionary/src/dictClient.ts +29 -0
- package/test/integration/generated/dictionary/src/index.ts +13 -0
- package/test/integration/generated/dictionary/src/models.ts +9 -0
- package/test/integration/generated/dictionary/src/outputModels.ts +9 -0
- package/test/integration/generated/dictionary/src/parameters.ts +94 -0
- package/test/integration/generated/dictionary/src/responses.ts +126 -0
- package/test/integration/generated/dictionary/tsconfig.json +25 -0
- package/test/integration/generated/dictionary/tspconfig.yaml +15 -0
- package/test/integration/generated/enums/extensible/.eslintrc.json +11 -0
- package/test/integration/generated/enums/extensible/README.md +56 -0
- package/test/integration/generated/enums/extensible/api-extractor.json +18 -0
- package/test/integration/generated/enums/extensible/package.json +80 -0
- package/test/integration/generated/enums/extensible/rollup.config.js +118 -0
- package/test/integration/generated/enums/extensible/src/clientDefinitions.ts +45 -0
- package/test/integration/generated/enums/extensible/src/enumsExtensible.ts +31 -0
- package/test/integration/generated/enums/extensible/src/index.ts +11 -0
- package/test/integration/generated/enums/extensible/src/parameters.ts +23 -0
- package/test/integration/generated/enums/extensible/src/responses.ts +26 -0
- package/test/integration/generated/enums/extensible/tsconfig.json +25 -0
- package/test/integration/generated/enums/extensible/tspconfig.yaml +14 -0
- package/test/integration/generated/enums/fixed/.eslintrc.json +11 -0
- package/test/integration/generated/enums/fixed/README.md +56 -0
- package/test/integration/generated/enums/fixed/api-extractor.json +18 -0
- package/test/integration/generated/enums/fixed/package.json +80 -0
- package/test/integration/generated/enums/fixed/rollup.config.js +118 -0
- package/test/integration/generated/enums/fixed/src/clientDefinitions.ts +43 -0
- package/test/integration/generated/enums/fixed/src/enumsFixed.ts +31 -0
- package/test/integration/generated/enums/fixed/src/index.ts +11 -0
- package/test/integration/generated/enums/fixed/src/parameters.ts +36 -0
- package/test/integration/generated/enums/fixed/src/responses.ts +27 -0
- package/test/integration/generated/enums/fixed/tsconfig.json +25 -0
- package/test/integration/generated/enums/fixed/tspconfig.yaml +14 -0
- package/test/integration/generated/hello/.eslintrc.json +11 -0
- package/test/integration/generated/hello/README.md +56 -0
- package/test/integration/generated/hello/api-extractor.json +18 -0
- package/test/integration/generated/hello/package.json +80 -0
- package/test/integration/generated/hello/rollup.config.js +118 -0
- package/test/integration/generated/hello/src/clientDefinitions.ts +19 -0
- package/test/integration/generated/hello/src/hello.ts +29 -0
- package/test/integration/generated/hello/src/index.ts +11 -0
- package/test/integration/generated/hello/src/parameters.ts +6 -0
- package/test/integration/generated/hello/src/responses.ts +10 -0
- package/test/integration/generated/hello/tsconfig.json +25 -0
- package/test/integration/generated/hello/tspconfig.yaml +14 -0
- package/test/integration/generated/internal/src/clientDefinitions.ts +27 -0
- package/test/integration/generated/internal/src/index.ts +13 -0
- package/test/integration/generated/internal/src/internalClient.ts +31 -0
- 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/lroBasic/.eslintrc.json +11 -0
- package/test/integration/generated/lro/lroBasic/README.md +56 -0
- package/test/integration/generated/lro/lroBasic/api-extractor.json +18 -0
- package/test/integration/generated/lro/lroBasic/package.json +82 -0
- package/test/integration/generated/lro/lroBasic/rollup.config.js +118 -0
- package/test/integration/generated/lro/lroBasic/src/azureLro.ts +31 -0
- package/test/integration/generated/lro/lroBasic/src/clientDefinitions.ts +37 -0
- package/test/integration/generated/lro/lroBasic/src/index.ts +13 -0
- package/test/integration/generated/lro/lroBasic/src/outputModels.ts +8 -0
- package/test/integration/generated/lro/lroBasic/src/parameters.ts +8 -0
- package/test/integration/generated/lro/lroBasic/src/pollingHelper.ts +75 -0
- package/test/integration/generated/lro/lroBasic/src/responses.ts +23 -0
- package/test/integration/generated/lro/lroBasic/tsconfig.json +25 -0
- package/test/integration/generated/lro/lroBasic/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/lro/lroCore/api-extractor.json +18 -0
- package/test/integration/generated/lro/lroCore/package.json +82 -0
- package/test/integration/generated/lro/lroCore/rollup.config.js +118 -0
- package/test/integration/generated/lro/lroCore/src/azureLroCore.ts +31 -0
- package/test/integration/generated/lro/lroCore/src/clientDefinitions.ts +51 -0
- package/test/integration/generated/lro/lroCore/src/index.ts +15 -0
- package/test/integration/generated/lro/lroCore/src/isUnexpected.ts +128 -0
- package/test/integration/generated/lro/lroCore/src/models.ts +8 -0
- package/test/integration/generated/lro/lroCore/src/outputModels.ts +53 -0
- package/test/integration/generated/lro/lroCore/src/parameters.ts +25 -0
- package/test/integration/generated/lro/lroCore/src/pollingHelper.ts +75 -0
- package/test/integration/generated/lro/lroCore/src/responses.ts +91 -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/models/inheritance/.eslintrc.json +11 -0
- package/test/integration/generated/models/inheritance/README.md +56 -0
- package/test/integration/generated/models/inheritance/api-extractor.json +18 -0
- package/test/integration/generated/models/inheritance/package.json +80 -0
- package/test/integration/generated/models/inheritance/rollup.config.js +118 -0
- package/test/integration/generated/models/inheritance/src/clientDefinitions.ts +79 -0
- package/test/integration/generated/models/inheritance/src/index.ts +13 -0
- package/test/integration/generated/models/inheritance/src/models.ts +52 -0
- package/test/integration/generated/models/inheritance/src/modelsInheritance.ts +31 -0
- package/test/integration/generated/models/inheritance/src/outputModels.ts +52 -0
- package/test/integration/generated/models/inheritance/src/parameters.ts +35 -0
- package/test/integration/generated/models/inheritance/src/responses.ts +56 -0
- package/test/integration/generated/models/inheritance/tsconfig.json +25 -0
- package/test/integration/generated/models/inheritance/tspconfig.yaml +14 -0
- 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/modelsPropertyNullable.ts +31 -0
- package/test/integration/generated/models/propertyNullable/src/outputModels.ts +56 -0
- package/test/integration/generated/models/propertyNullable/src/parameters.ts +195 -0
- package/test/integration/generated/models/propertyNullable/src/responses.ts +144 -0
- 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/.eslintrc.json +11 -0
- package/test/integration/generated/models/propertyOptional/README.md +56 -0
- package/test/integration/generated/models/propertyOptional/api-extractor.json +18 -0
- package/test/integration/generated/models/propertyOptional/package.json +80 -0
- package/test/integration/generated/models/propertyOptional/rollup.config.js +118 -0
- package/test/integration/generated/models/propertyOptional/src/clientDefinitions.ts +263 -0
- package/test/integration/generated/models/propertyOptional/src/index.ts +13 -0
- package/test/integration/generated/models/propertyOptional/src/models.ts +46 -0
- package/test/integration/generated/models/propertyOptional/src/modelsPropertyOptional.ts +31 -0
- package/test/integration/generated/models/propertyOptional/src/outputModels.ts +46 -0
- package/test/integration/generated/models/propertyOptional/src/parameters.ts +124 -0
- package/test/integration/generated/models/propertyOptional/src/responses.ts +169 -0
- package/test/integration/generated/models/propertyOptional/tsconfig.json +25 -0
- package/test/integration/generated/models/propertyOptional/tspconfig.yaml +14 -0
- package/test/integration/generated/models/propertyTypes/.eslintrc.json +11 -0
- package/test/integration/generated/models/propertyTypes/README.md +56 -0
- package/test/integration/generated/models/propertyTypes/api-extractor.json +18 -0
- package/test/integration/generated/models/propertyTypes/package.json +80 -0
- package/test/integration/generated/models/propertyTypes/rollup.config.js +118 -0
- package/test/integration/generated/models/propertyTypes/src/clientDefinitions.ts +234 -0
- package/test/integration/generated/models/propertyTypes/src/index.ts +13 -0
- package/test/integration/generated/models/propertyTypes/src/models.ts +99 -0
- package/test/integration/generated/models/propertyTypes/src/modelsPropertyTypes.ts +31 -0
- package/test/integration/generated/models/propertyTypes/src/outputModels.ts +99 -0
- package/test/integration/generated/models/propertyTypes/src/parameters.ts +147 -0
- package/test/integration/generated/models/propertyTypes/src/responses.ts +186 -0
- package/test/integration/generated/models/propertyTypes/tsconfig.json +25 -0
- package/test/integration/generated/models/propertyTypes/tspconfig.yaml +14 -0
- package/test/integration/generated/models/usage/.eslintrc.json +11 -0
- package/test/integration/generated/models/usage/README.md +56 -0
- package/test/integration/generated/models/usage/api-extractor.json +18 -0
- package/test/integration/generated/models/usage/package.json +80 -0
- package/test/integration/generated/models/usage/rollup.config.js +118 -0
- package/test/integration/generated/models/usage/src/clientDefinitions.ts +41 -0
- package/test/integration/generated/models/usage/src/index.ts +13 -0
- package/test/integration/generated/models/usage/src/models.ts +12 -0
- package/test/integration/generated/models/usage/src/modelsUsage.ts +31 -0
- package/test/integration/generated/models/usage/src/outputModels.ts +12 -0
- package/test/integration/generated/models/usage/src/parameters.ts +19 -0
- package/test/integration/generated/models/usage/src/responses.ts +22 -0
- package/test/integration/generated/models/usage/tsconfig.json +25 -0
- package/test/integration/generated/models/usage/tspconfig.yaml +14 -0
- package/test/integration/generated/models/visibility/.eslintrc.json +11 -0
- package/test/integration/generated/models/visibility/README.md +56 -0
- package/test/integration/generated/models/visibility/api-extractor.json +18 -0
- package/test/integration/generated/models/visibility/package.json +80 -0
- package/test/integration/generated/models/visibility/rollup.config.js +118 -0
- package/test/integration/generated/models/visibility/src/clientDefinitions.ts +40 -0
- package/test/integration/generated/models/visibility/src/index.ts +13 -0
- package/test/integration/generated/models/visibility/src/models.ts +14 -0
- package/test/integration/generated/models/visibility/src/modelsVisibilityAutomatic.ts +31 -0
- package/test/integration/generated/models/visibility/src/outputModels.ts +16 -0
- package/test/integration/generated/models/visibility/src/parameters.ts +41 -0
- package/test/integration/generated/models/visibility/src/responses.ts +36 -0
- package/test/integration/generated/models/visibility/tsconfig.json +25 -0
- package/test/integration/generated/models/visibility/tspconfig.yaml +14 -0
- package/test/integration/generated/parameters/collection-format/src/clientDefinitions.ts +39 -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 +38 -0
- package/test/integration/generated/parameters/collection-format/src/responses.ts +19 -0
- package/test/integration/generated/parameters/collection-format/src/serializeHelper.ts +16 -0
- package/test/integration/generated/parameters/collection-format/tspconfig.yaml +14 -0
- package/test/integration/generated/projection/src/clientDefinitions.ts +45 -0
- package/test/integration/generated/projection/src/index.ts +12 -0
- package/test/integration/generated/projection/src/models.ts +11 -0
- package/test/integration/generated/projection/src/parameters.ts +26 -0
- package/test/integration/generated/projection/src/projectionClient.ts +31 -0
- package/test/integration/generated/projection/src/responses.ts +19 -0
- package/test/integration/generated/projection/tspconfig.yaml +14 -0
- package/test/integration/generated/resiliency/devDriven/.eslintrc.json +11 -0
- package/test/integration/generated/resiliency/devDriven/README.md +56 -0
- package/test/integration/generated/resiliency/devDriven/api-extractor.json +18 -0
- package/test/integration/generated/resiliency/devDriven/package.json +81 -0
- package/test/integration/generated/resiliency/devDriven/rollup.config.js +118 -0
- package/test/integration/generated/resiliency/devDriven/src/clientDefinitions.ts +75 -0
- package/test/integration/generated/resiliency/devDriven/src/index.ts +15 -0
- package/test/integration/generated/resiliency/devDriven/src/isUnexpected.ts +117 -0
- package/test/integration/generated/resiliency/devDriven/src/models.ts +8 -0
- package/test/integration/generated/resiliency/devDriven/src/outputModels.ts +25 -0
- package/test/integration/generated/resiliency/devDriven/src/paginateHelper.ts +154 -0
- package/test/integration/generated/resiliency/devDriven/src/parameters.ts +17 -0
- package/test/integration/generated/resiliency/devDriven/src/resiliencyDevDriven.ts +31 -0
- package/test/integration/generated/resiliency/devDriven/src/responses.ts +62 -0
- package/test/integration/generated/resiliency/devDriven/tsconfig.json +25 -0
- package/test/integration/generated/resiliency/devDriven/tspconfig.yaml +14 -0
- package/test/integration/generated/resiliency/srvDriven1/.eslintrc.json +11 -0
- package/test/integration/generated/resiliency/srvDriven1/README.md +56 -0
- package/test/integration/generated/resiliency/srvDriven1/api-extractor.json +18 -0
- package/test/integration/generated/resiliency/srvDriven1/package.json +80 -0
- package/test/integration/generated/resiliency/srvDriven1/rollup.config.js +118 -0
- package/test/integration/generated/resiliency/srvDriven1/src/clientDefinitions.ts +70 -0
- package/test/integration/generated/resiliency/srvDriven1/src/index.ts +13 -0
- package/test/integration/generated/resiliency/srvDriven1/src/models.ts +6 -0
- package/test/integration/generated/resiliency/srvDriven1/src/outputModels.ts +6 -0
- package/test/integration/generated/resiliency/srvDriven1/src/parameters.ts +51 -0
- package/test/integration/generated/resiliency/srvDriven1/src/resiliencyServiceDriven1.ts +31 -0
- package/test/integration/generated/resiliency/srvDriven1/src/responses.ts +34 -0
- package/test/integration/generated/resiliency/srvDriven1/tsconfig.json +25 -0
- package/test/integration/generated/resiliency/srvDriven1/tspconfig.yaml +14 -0
- package/test/integration/generated/resiliency/srvDriven2/.eslintrc.json +11 -0
- package/test/integration/generated/resiliency/srvDriven2/README.md +56 -0
- package/test/integration/generated/resiliency/srvDriven2/api-extractor.json +18 -0
- package/test/integration/generated/resiliency/srvDriven2/package.json +80 -0
- package/test/integration/generated/resiliency/srvDriven2/rollup.config.js +118 -0
- package/test/integration/generated/resiliency/srvDriven2/src/clientDefinitions.ts +93 -0
- package/test/integration/generated/resiliency/srvDriven2/src/index.ts +13 -0
- package/test/integration/generated/resiliency/srvDriven2/src/models.ts +6 -0
- package/test/integration/generated/resiliency/srvDriven2/src/outputModels.ts +6 -0
- package/test/integration/generated/resiliency/srvDriven2/src/parameters.ts +68 -0
- package/test/integration/generated/resiliency/srvDriven2/src/resiliencyServiceDriven2.ts +31 -0
- package/test/integration/generated/resiliency/srvDriven2/src/responses.ts +45 -0
- package/test/integration/generated/resiliency/srvDriven2/tsconfig.json +25 -0
- package/test/integration/generated/resiliency/srvDriven2/tspconfig.yaml +14 -0
- 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/src/clientDefinitions.ts +61 -0
- package/test/integration/generated/specialWords/src/index.ts +13 -0
- package/test/integration/generated/specialWords/src/models.ts +17 -0
- package/test/integration/generated/specialWords/src/outputModels.ts +17 -0
- package/test/integration/generated/specialWords/src/parameters.ts +37 -0
- package/test/integration/generated/specialWords/src/responses.ts +31 -0
- package/test/integration/generated/specialWords/src/specialWordsClient.ts +31 -0
- package/test/integration/generated/specialWords/tspconfig.yaml +14 -0
- package/test/integration/generated/unions/src/clientDefinitions.ts +53 -0
- package/test/integration/generated/unions/src/index.ts +12 -0
- package/test/integration/generated/unions/src/models.ts +27 -0
- package/test/integration/generated/unions/src/parameters.ts +34 -0
- package/test/integration/generated/unions/src/responses.ts +24 -0
- package/test/integration/generated/unions/src/unionsClient.ts +31 -0
- package/test/integration/generated/unions/tspconfig.yaml +14 -0
- package/test/integration/helloWorld.spec.ts +20 -0
- package/test/integration/internal.spec.ts +43 -0
- package/test/integration/lroBasic.spec.ts +25 -0
- package/test/integration/modelInheritance.spec.ts +192 -0
- package/test/integration/modelPropertyNullable.spec.ts +115 -0
- package/test/integration/modelPropertyOptional.spec.ts +362 -0
- package/test/integration/modelPropertyType.spec.ts +119 -0
- package/test/integration/modelUsage.spec.ts +47 -0
- package/test/integration/projection.spec.ts +55 -0
- package/test/integration/resiliencyDpgCustomization.spec.ts +52 -0
- package/test/integration/server.spec.ts +59 -0
- package/test/integration/specialWords.spec.ts +73 -0
- package/test/integration/unions.spec.ts +69 -0
- package/test/tsconfig.json +4 -0
- package/test/unit/apiVersion.spec.ts +388 -0
- package/test/unit/azureCoreOperationsGenerator.spec.ts +71 -0
- package/test/unit/clientDefinitionGenerator.spec.ts +73 -0
- package/test/unit/clientFactoryGenerator.spec.ts +376 -0
- package/test/unit/docsGenerator.spec.ts +201 -0
- package/test/unit/modelsGenerator.spec.ts +1319 -0
- package/test/unit/parametersGenerator.spec.ts +561 -0
- package/test/unit/responsesGenerator.spec.ts +462 -0
- package/test/unit/spreadAndAlias.spec.ts +200 -0
- package/test/unit/util/emitUtil.ts +157 -0
- package/test/unit/util/testUtil.ts +83 -0
- package/test/util/customBearerTokenTestingPolicy.ts +78 -0
- package/test/util/matrix.ts +48 -0
- package/tsconfig.json +36 -0
- package/tsconfig.test.json +7 -0
- package/typespec-ts.build.log +2 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionDeclarationStructure,
|
|
3
|
+
OptionalKind,
|
|
4
|
+
ParameterDeclarationStructure
|
|
5
|
+
} from "ts-morph";
|
|
6
|
+
import { toPascalCase } from "../../casingUtils.js";
|
|
7
|
+
import { Operation, Parameter, Property, Type } from "../modularCodeModel.js";
|
|
8
|
+
import { buildType } from "./typeHelpers.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This operation builds and returns the function declaration for an operation.
|
|
12
|
+
*/
|
|
13
|
+
export function getOperationFunction(
|
|
14
|
+
operation: Operation
|
|
15
|
+
): OptionalKind<FunctionDeclarationStructure> {
|
|
16
|
+
const optionsType = getOperationOptionsName(operation);
|
|
17
|
+
// Extract required parameters
|
|
18
|
+
let parameters: OptionalKind<ParameterDeclarationStructure>[] = (
|
|
19
|
+
operation.bodyParameter?.type.properties ?? []
|
|
20
|
+
)
|
|
21
|
+
.filter((p) => !p.optional)
|
|
22
|
+
.map((p) => buildType(p.clientName, p.type));
|
|
23
|
+
|
|
24
|
+
parameters = parameters.concat(
|
|
25
|
+
operation.parameters
|
|
26
|
+
.filter(
|
|
27
|
+
(p) =>
|
|
28
|
+
p.implementation === "Method" &&
|
|
29
|
+
p.type.type !== "constant" &&
|
|
30
|
+
!p.optional
|
|
31
|
+
)
|
|
32
|
+
.map((p) => buildType(p.clientName, p.type))
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Add context as the first parameter
|
|
36
|
+
parameters.unshift({ name: "context", type: "Client" });
|
|
37
|
+
|
|
38
|
+
// Add the options parameter
|
|
39
|
+
parameters.push({
|
|
40
|
+
name: "options",
|
|
41
|
+
type: optionsType,
|
|
42
|
+
initializer: "{ requestOptions: {} }"
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// TODO: Support operation overloads
|
|
46
|
+
const response = operation.responses[0]!;
|
|
47
|
+
const returnType =
|
|
48
|
+
response?.type?.type === "model"
|
|
49
|
+
? buildType(response.type.name, response.type)
|
|
50
|
+
: { name: "", type: "void" };
|
|
51
|
+
|
|
52
|
+
const functionStatement: OptionalKind<FunctionDeclarationStructure> = {
|
|
53
|
+
docs: [operation.description],
|
|
54
|
+
isAsync: true,
|
|
55
|
+
isExported: true,
|
|
56
|
+
name: operation.name,
|
|
57
|
+
parameters,
|
|
58
|
+
returnType: `Promise<${returnType.type}>`
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const operationPath = operation.url;
|
|
62
|
+
const operationMethod = operation.method.toLowerCase();
|
|
63
|
+
|
|
64
|
+
const statements: string[] = [];
|
|
65
|
+
statements.push(
|
|
66
|
+
`const result = await context.path("${operationPath}", ${getPathParameters(
|
|
67
|
+
operation
|
|
68
|
+
)}).${operationMethod}({${getRequestParameters(operation)}});`
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
statements.push(`if(isUnexpected(result)){`, "throw result.body", "}");
|
|
72
|
+
|
|
73
|
+
if (!response?.type?.properties) {
|
|
74
|
+
statements.push(`return;`);
|
|
75
|
+
} else {
|
|
76
|
+
statements.push(
|
|
77
|
+
`return {`,
|
|
78
|
+
getResponseMapping(response.type.properties ?? []).join(","),
|
|
79
|
+
`}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...functionStatement,
|
|
84
|
+
statements
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getOperationOptionsName(operation: Operation) {
|
|
89
|
+
return `${toPascalCase(operation.groupName)}${toPascalCase(
|
|
90
|
+
operation.name
|
|
91
|
+
)}Options`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* This function build the request parameters that we will provide to the
|
|
96
|
+
* RLC internally. This will translate High Level parameters into the RLC ones.
|
|
97
|
+
* Figuring out what goes in headers, body, path and qsp.
|
|
98
|
+
*/
|
|
99
|
+
function getRequestParameters(operation: Operation): string {
|
|
100
|
+
if (!operation.parameters) {
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const operationParameters = operation.parameters.filter(
|
|
105
|
+
(p) => p.implementation !== "Client"
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const parametersImplementation: Record<
|
|
109
|
+
"header" | "query" | "body",
|
|
110
|
+
string[]
|
|
111
|
+
> = {
|
|
112
|
+
header: [],
|
|
113
|
+
query: [],
|
|
114
|
+
body: []
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
for (const param of operationParameters) {
|
|
118
|
+
if (param.location === "header" || param.location === "query") {
|
|
119
|
+
parametersImplementation[param.location].push(getParameterMap(param));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const param of operation.bodyParameter?.type.properties?.filter(
|
|
124
|
+
(p) => !p.readonly
|
|
125
|
+
) ?? []) {
|
|
126
|
+
parametersImplementation.body.push(getParameterMap(param));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let paramStr = "";
|
|
130
|
+
|
|
131
|
+
if (parametersImplementation.header.length) {
|
|
132
|
+
paramStr = `${paramStr}\nheaders: {${parametersImplementation.header.join(
|
|
133
|
+
"\n"
|
|
134
|
+
)}...options.requestOptions?.headers},`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (parametersImplementation.query.length) {
|
|
138
|
+
paramStr = `${paramStr}\nqueryParameters: {${parametersImplementation.query.join(
|
|
139
|
+
"\n"
|
|
140
|
+
)}},`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (operation.bodyParameter && operation.bodyParameter.type.properties) {
|
|
144
|
+
paramStr = `${paramStr}\nbody: {${parametersImplementation.body.join(
|
|
145
|
+
"\n"
|
|
146
|
+
)}},`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return paramStr;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* This function helps with renames, translating client names to rest api names
|
|
154
|
+
*/
|
|
155
|
+
function getParameterMap(param: Parameter | Property) {
|
|
156
|
+
const defaultValue = getDefaultValue(param);
|
|
157
|
+
|
|
158
|
+
if (param.optional || (param.type.type === "constant" && !defaultValue)) {
|
|
159
|
+
return `...(options.${param.clientName} && {"${
|
|
160
|
+
param.restApiName
|
|
161
|
+
}": ${`options.${param.clientName}})`},`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return `"${param.restApiName}": ${
|
|
165
|
+
param.optional
|
|
166
|
+
? `options.${param.clientName} ${defaultValue}`
|
|
167
|
+
: param.type.type === "constant"
|
|
168
|
+
? `${defaultValue}`
|
|
169
|
+
: param.clientName
|
|
170
|
+
},`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Builds the assignment for when a property or parameter has a default value
|
|
175
|
+
*/
|
|
176
|
+
function getDefaultValue(param: Parameter | Property) {
|
|
177
|
+
return (param.clientDefaultValue ?? param.type.clientDefaultValue) !==
|
|
178
|
+
undefined
|
|
179
|
+
? `${param.optional ? "??" : ""} "${
|
|
180
|
+
param.clientDefaultValue ?? param.type.clientDefaultValue
|
|
181
|
+
}"`
|
|
182
|
+
: "";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Extracts the path parameters
|
|
187
|
+
*/
|
|
188
|
+
function getPathParameters(operation: Operation) {
|
|
189
|
+
if (!operation.parameters) {
|
|
190
|
+
return "";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let pathParams = "";
|
|
194
|
+
for (const param of operation.parameters) {
|
|
195
|
+
if (param.location === "path") {
|
|
196
|
+
if (!param.optional) {
|
|
197
|
+
pathParams = `${pathParams} ${param.clientName},`;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const defaultValue = getDefaultValue(param);
|
|
202
|
+
|
|
203
|
+
pathParams = `${pathParams}, options.${param.clientName}`;
|
|
204
|
+
|
|
205
|
+
if (defaultValue) {
|
|
206
|
+
pathParams = ` ?? "${defaultValue}"`;
|
|
207
|
+
}
|
|
208
|
+
pathParams = `${pathParams},`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return pathParams;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* This function helps translating an RLC response to an HLC response,
|
|
217
|
+
* extracting properties from body and headers and building the HLC response object
|
|
218
|
+
*/
|
|
219
|
+
function getResponseMapping(
|
|
220
|
+
properties: Property[],
|
|
221
|
+
propertyPath: string = "result.body"
|
|
222
|
+
) {
|
|
223
|
+
const props: string[] = [];
|
|
224
|
+
for (const property of properties) {
|
|
225
|
+
// TODO: Do we need to also add headers in the result type?
|
|
226
|
+
if (property.type.type === "model") {
|
|
227
|
+
props.push(
|
|
228
|
+
`"${property.restApiName}": ${
|
|
229
|
+
!property.optional
|
|
230
|
+
? ""
|
|
231
|
+
: `!${propertyPath}.${property.clientName} ? undefined :`
|
|
232
|
+
} {${getResponseMapping(
|
|
233
|
+
property.type.properties ?? [],
|
|
234
|
+
`${propertyPath}.${property.restApiName}${
|
|
235
|
+
property.optional ? "?" : ""
|
|
236
|
+
}`
|
|
237
|
+
)}}`
|
|
238
|
+
);
|
|
239
|
+
} else {
|
|
240
|
+
const dot = propertyPath.endsWith("?") ? "." : "";
|
|
241
|
+
const restValue = `${
|
|
242
|
+
propertyPath ? `${propertyPath}${dot}` : `${dot}`
|
|
243
|
+
}["${property.restApiName}"]`;
|
|
244
|
+
props.push(
|
|
245
|
+
`"${property.clientName}": ${deserializeResponseValue(
|
|
246
|
+
property.type,
|
|
247
|
+
restValue
|
|
248
|
+
)}`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return props;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* This function helps converting strings into JS complex types recursively.
|
|
258
|
+
* We need to drill down into Array elements to make sure that the element type is
|
|
259
|
+
* deserialized correctly
|
|
260
|
+
*/
|
|
261
|
+
function deserializeResponseValue(type: Type, restValue: string): string {
|
|
262
|
+
switch (type.type) {
|
|
263
|
+
case "datetime":
|
|
264
|
+
return `new Date(${restValue} ?? "")`;
|
|
265
|
+
case "list":
|
|
266
|
+
if (type.elementType?.type === "model") {
|
|
267
|
+
return `(${restValue} ?? []).map(p => ({${getResponseMapping(
|
|
268
|
+
type.elementType?.properties ?? [],
|
|
269
|
+
"p"
|
|
270
|
+
)}}))`;
|
|
271
|
+
} else if (
|
|
272
|
+
type.elementType?.properties?.some((p) => needsDeserialize(p.type))
|
|
273
|
+
) {
|
|
274
|
+
return `(${restValue} ?? []).map(p => ${deserializeResponseValue(
|
|
275
|
+
type.elementType!,
|
|
276
|
+
"p"
|
|
277
|
+
)})`;
|
|
278
|
+
} else {
|
|
279
|
+
return restValue;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
default:
|
|
283
|
+
return restValue;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function needsDeserialize(type?: Type) {
|
|
288
|
+
return type?.type === "datetime" || type?.type === "model";
|
|
289
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Parameter } from "../modularCodeModel.js";
|
|
2
|
+
|
|
3
|
+
export function getParameterType(param: Parameter): string {
|
|
4
|
+
switch (param.type.type) {
|
|
5
|
+
case "Key":
|
|
6
|
+
return "AzureKeyCredential";
|
|
7
|
+
case "OAuth2":
|
|
8
|
+
return "TokenCredential";
|
|
9
|
+
default:
|
|
10
|
+
return param.type.type;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 "list":
|
|
38
|
+
if (!type.elementType) {
|
|
39
|
+
throw new Error("Unable to process Array with no elementType");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
name: getType(type.elementType).name,
|
|
43
|
+
modifier: "Array",
|
|
44
|
+
originModule:
|
|
45
|
+
type.elementType?.type === "model" ? "models.js" : undefined
|
|
46
|
+
};
|
|
47
|
+
case "model":
|
|
48
|
+
if (!type.name) {
|
|
49
|
+
throw new Error("Unable to process model without name");
|
|
50
|
+
}
|
|
51
|
+
return { name: type.name, originModule: "models.js" };
|
|
52
|
+
case "string":
|
|
53
|
+
case "duration":
|
|
54
|
+
return { name: "string" };
|
|
55
|
+
case "dict":
|
|
56
|
+
if (!type.elementType) {
|
|
57
|
+
throw new Error("Unable to process dict without elemetType info");
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
name: `Record<string, ${type.elementType.type}>`
|
|
61
|
+
};
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unsupported type ${type.type}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the Typescript representation of a TypeSpec type
|
|
69
|
+
*/
|
|
70
|
+
export function buildType(
|
|
71
|
+
clientName: string | undefined,
|
|
72
|
+
type: Type | undefined
|
|
73
|
+
) {
|
|
74
|
+
if (!type) {
|
|
75
|
+
throw new Error("Type should be defined");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const typeMetadata = getType(type);
|
|
79
|
+
let typeName = typeMetadata.name;
|
|
80
|
+
if (typeMetadata.modifier === "Array") {
|
|
81
|
+
typeName = `${typeName}[]`;
|
|
82
|
+
}
|
|
83
|
+
return { name: clientName ?? "", type: typeName };
|
|
84
|
+
}
|
|
@@ -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,148 @@
|
|
|
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
|
+
| "datetime"
|
|
65
|
+
| "float"
|
|
66
|
+
| "duration"
|
|
67
|
+
| "enum"
|
|
68
|
+
| "integer"
|
|
69
|
+
| "float"
|
|
70
|
+
| "boolean"
|
|
71
|
+
| "dict";
|
|
72
|
+
policy?: Policy;
|
|
73
|
+
apiVersions?: any[];
|
|
74
|
+
clientDefaultValue?: any;
|
|
75
|
+
value?: string;
|
|
76
|
+
values?: EnumValue[];
|
|
77
|
+
isFixed?: boolean;
|
|
78
|
+
valueType?: Type;
|
|
79
|
+
elementType?: Type;
|
|
80
|
+
xmlMetadata?: XmlMetadata;
|
|
81
|
+
format?: string;
|
|
82
|
+
properties?: Property[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface Client {
|
|
86
|
+
name: string;
|
|
87
|
+
description: string;
|
|
88
|
+
parameters: Parameter[];
|
|
89
|
+
operationGroups: OperationGroup[];
|
|
90
|
+
url: string;
|
|
91
|
+
apiVersions: any[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type ParameterLocation =
|
|
95
|
+
| "endpointPath"
|
|
96
|
+
| "header"
|
|
97
|
+
| "query"
|
|
98
|
+
| "path"
|
|
99
|
+
| "other";
|
|
100
|
+
|
|
101
|
+
export interface Parameter {
|
|
102
|
+
optional: boolean;
|
|
103
|
+
description: string;
|
|
104
|
+
clientName: string;
|
|
105
|
+
inOverload: boolean;
|
|
106
|
+
restApiName: string;
|
|
107
|
+
location: ParameterLocation;
|
|
108
|
+
type: Type;
|
|
109
|
+
implementation: string;
|
|
110
|
+
skipUrlEncoding?: boolean;
|
|
111
|
+
clientDefaultValue?: string | null;
|
|
112
|
+
in_docstring?: boolean;
|
|
113
|
+
checkClientInput?: boolean;
|
|
114
|
+
delimiter?: any;
|
|
115
|
+
explode?: boolean;
|
|
116
|
+
groupedBy?: any;
|
|
117
|
+
inDocstring?: boolean;
|
|
118
|
+
inOverriden?: boolean;
|
|
119
|
+
isApiVersion?: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface Response {
|
|
123
|
+
headers: Header[];
|
|
124
|
+
statusCodes: (number | "default")[];
|
|
125
|
+
discriminator: string;
|
|
126
|
+
type: Type;
|
|
127
|
+
addedOn?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface Operation {
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
summary: string;
|
|
134
|
+
url: string;
|
|
135
|
+
method: string;
|
|
136
|
+
parameters: Parameter[];
|
|
137
|
+
bodyParameter?: BodyParameter;
|
|
138
|
+
responses: Response[];
|
|
139
|
+
exceptions: Response[];
|
|
140
|
+
groupName: string;
|
|
141
|
+
discriminator: string;
|
|
142
|
+
isOverload: boolean;
|
|
143
|
+
overloads: any[];
|
|
144
|
+
apiVersions: any[];
|
|
145
|
+
itemName?: string;
|
|
146
|
+
continuationTokenName?: string;
|
|
147
|
+
addedOn?: string;
|
|
148
|
+
}
|