@azure-tools/typespec-ts 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +23 -0
- package/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/.rush/temp/package-deps_build.json +303 -0
- package/.rush/temp/shrinkwrap-deps.json +469 -0
- package/CHANGELOG.md +65 -0
- package/CONTRIBUTING.md +134 -0
- package/README.md +150 -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 +59 -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 +189 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/modelUtils.d.ts +12 -0
- package/dist/src/modelUtils.d.ts.map +1 -0
- package/dist/src/modelUtils.js +812 -0
- package/dist/src/modelUtils.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 +8 -0
- package/dist/src/transform/transform.d.ts.map +1 -0
- package/dist/src/transform/transform.js +131 -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/transformApiVersionParam.d.ts +5 -0
- package/dist/src/transform/transformApiVersionParam.d.ts.map +1 -0
- package/dist/src/transform/transformApiVersionParam.js +76 -0
- package/dist/src/transform/transformApiVersionParam.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 +315 -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 +175 -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 +73 -0
- package/src/emitUtil.ts +63 -0
- package/src/index.ts +106 -0
- package/src/lib.ts +207 -0
- package/src/modelUtils.ts +961 -0
- package/src/operationUtil.ts +203 -0
- package/src/transform/transform.ts +224 -0
- package/src/transform/transformAnnotationDetails.ts +231 -0
- package/src/transform/transformApiVersionParam.ts +104 -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 +209 -0
- package/src/transform/transfromRLCOptions.ts +202 -0
- package/test/commands/cadl-ranch-list.ts +83 -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 +41 -0
- package/test/integration/arrayItemTypes.spec.ts +93 -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/dictionary.spec.ts +102 -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 +150 -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 +78 -0
- package/test/integration/generated/arrays/itemTypes/src/responses.ts +104 -0
- package/test/integration/generated/arrays/itemTypes/tspconfig.yaml +12 -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 +10 -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 +12 -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 +12 -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 +165 -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 +86 -0
- package/test/integration/generated/dictionary/src/responses.ts +115 -0
- package/test/integration/generated/dictionary/tsconfig.json +25 -0
- package/test/integration/generated/dictionary/tspconfig.yaml +12 -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 +11 -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 +11 -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 +11 -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 +12 -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 +22 -0
- package/test/integration/generated/lro/lroBasic/tsconfig.json +25 -0
- package/test/integration/generated/lro/lroBasic/tspconfig.yaml +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -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 +11 -0
- package/test/integration/helloWorld.spec.ts +20 -0
- package/test/integration/lroBasic.spec.ts +25 -0
- package/test/integration/modelInheritance.spec.ts +192 -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/resiliencyDpgCustomization.spec.ts +52 -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/azureCoreOperationsGenerator.spec.ts +71 -0
- package/test/unit/clientDefinitionGenerator.spec.ts +73 -0
- package/test/unit/clientFactoryGenerator.spec.ts +507 -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 +156 -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,203 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { NameType, normalizeName } from "@azure-tools/rlc-common";
|
|
5
|
+
import {
|
|
6
|
+
DecoratedType,
|
|
7
|
+
ignoreDiagnostics,
|
|
8
|
+
Model,
|
|
9
|
+
Program,
|
|
10
|
+
Type
|
|
11
|
+
} from "@typespec/compiler";
|
|
12
|
+
import {
|
|
13
|
+
getHttpOperation,
|
|
14
|
+
HttpOperation,
|
|
15
|
+
HttpOperationResponse,
|
|
16
|
+
StatusCode
|
|
17
|
+
} from "@typespec/http";
|
|
18
|
+
import {
|
|
19
|
+
getPagedResult,
|
|
20
|
+
PagedResultMetadata
|
|
21
|
+
} from "@azure-tools/typespec-azure-core";
|
|
22
|
+
import {
|
|
23
|
+
Client,
|
|
24
|
+
DpgContext,
|
|
25
|
+
listOperationGroups,
|
|
26
|
+
listOperationsInOperationGroup,
|
|
27
|
+
OperationGroup
|
|
28
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
29
|
+
|
|
30
|
+
export function getNormalizedOperationName(
|
|
31
|
+
route: HttpOperation,
|
|
32
|
+
includeGroupName = true
|
|
33
|
+
) {
|
|
34
|
+
return includeGroupName
|
|
35
|
+
? normalizeName(
|
|
36
|
+
`${route.container?.name}_${route.operation.name}`,
|
|
37
|
+
NameType.Interface
|
|
38
|
+
)
|
|
39
|
+
: normalizeName(`${route.operation.name}`, NameType.Interface);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getOperationStatuscode(
|
|
43
|
+
response: HttpOperationResponse
|
|
44
|
+
): string {
|
|
45
|
+
switch (response.statusCode) {
|
|
46
|
+
case "*":
|
|
47
|
+
return "default";
|
|
48
|
+
default:
|
|
49
|
+
return `${response.statusCode}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// FIXME: this is the placeholder function to extract the operationGroupName
|
|
54
|
+
export function getOperationGroupName(operationGroup?: OperationGroup) {
|
|
55
|
+
return operationGroup?.type.name ?? "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isDefaultStatusCode(statusCode: StatusCode) {
|
|
59
|
+
return statusCode === "*";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isDefinedStatusCode(statusCode: StatusCode) {
|
|
63
|
+
return statusCode !== "*";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function isBinaryPayload(body: Type, contentType: string) {
|
|
67
|
+
contentType = `"${contentType}"`;
|
|
68
|
+
if (
|
|
69
|
+
body.kind === "Scalar" &&
|
|
70
|
+
body.name === "bytes" &&
|
|
71
|
+
contentType !== `"application/json"` &&
|
|
72
|
+
contentType !== `"text/plain"` &&
|
|
73
|
+
contentType !== `"application/json" | "text/plain"` &&
|
|
74
|
+
contentType !== `"text/plain" | "application/json"`
|
|
75
|
+
) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function isLongRunningOperation(
|
|
82
|
+
program: Program,
|
|
83
|
+
operation: HttpOperation
|
|
84
|
+
) {
|
|
85
|
+
program;
|
|
86
|
+
for (const resp of operation.responses) {
|
|
87
|
+
if (!resp.responses || !resp.responses.length) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (hasDecorator(operation.operation, "$pollingOperation")) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
for (const unit of resp.responses) {
|
|
94
|
+
for (const [_, header] of Object.entries(unit.headers!)) {
|
|
95
|
+
if (hasDecorator(header, "$pollingLocation")) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hasDecorator(type: DecoratedType, name: string): boolean {
|
|
105
|
+
return type.decorators.find((it) => it.decorator.name === name) !== undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function hasPollingOperations(
|
|
109
|
+
program: Program,
|
|
110
|
+
client: Client,
|
|
111
|
+
dpgContext: DpgContext
|
|
112
|
+
) {
|
|
113
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
114
|
+
for (const operationGroup of operationGroups) {
|
|
115
|
+
const operations = listOperationsInOperationGroup(
|
|
116
|
+
dpgContext,
|
|
117
|
+
operationGroup
|
|
118
|
+
);
|
|
119
|
+
for (const op of operations) {
|
|
120
|
+
const route = ignoreDiagnostics(getHttpOperation(program, op));
|
|
121
|
+
if (isLongRunningOperation(program, route)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
127
|
+
for (const clientOp of clientOperations) {
|
|
128
|
+
const route = ignoreDiagnostics(getHttpOperation(program, clientOp));
|
|
129
|
+
if (isLongRunningOperation(program, route)) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function isPagingOperation(program: Program, operation: HttpOperation) {
|
|
138
|
+
for (const response of operation.responses) {
|
|
139
|
+
const paged = extractPagedMetadataNested(program, response.type as Model);
|
|
140
|
+
if (paged) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function hasPagingOperations(
|
|
148
|
+
program: Program,
|
|
149
|
+
client: Client,
|
|
150
|
+
dpgContext: DpgContext
|
|
151
|
+
) {
|
|
152
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
153
|
+
for (const operationGroup of operationGroups) {
|
|
154
|
+
const operations = listOperationsInOperationGroup(
|
|
155
|
+
dpgContext,
|
|
156
|
+
operationGroup
|
|
157
|
+
);
|
|
158
|
+
for (const op of operations) {
|
|
159
|
+
const route = ignoreDiagnostics(getHttpOperation(program, op));
|
|
160
|
+
if (isPagingOperation(program, route)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
166
|
+
for (const clientOp of clientOperations) {
|
|
167
|
+
const route = ignoreDiagnostics(getHttpOperation(program, clientOp));
|
|
168
|
+
if (isPagingOperation(program, route)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function extractPagedMetadataNested(
|
|
176
|
+
program: Program,
|
|
177
|
+
type: Model
|
|
178
|
+
): PagedResultMetadata | undefined {
|
|
179
|
+
// This only works for `is Page<T>` not `extends Page<T>`.
|
|
180
|
+
let paged = getPagedResult(program, type);
|
|
181
|
+
if (paged) {
|
|
182
|
+
return paged;
|
|
183
|
+
}
|
|
184
|
+
if (type.baseModel) {
|
|
185
|
+
paged = getPagedResult(program, type.baseModel);
|
|
186
|
+
}
|
|
187
|
+
if (paged) {
|
|
188
|
+
return paged;
|
|
189
|
+
}
|
|
190
|
+
const templateArguments = type.templateArguments;
|
|
191
|
+
if (templateArguments) {
|
|
192
|
+
for (const argument of templateArguments) {
|
|
193
|
+
const modelArgument = argument as Model;
|
|
194
|
+
if (modelArgument) {
|
|
195
|
+
paged = extractPagedMetadataNested(program, modelArgument);
|
|
196
|
+
if (paged) {
|
|
197
|
+
return paged;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return paged;
|
|
203
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Client,
|
|
6
|
+
DpgContext,
|
|
7
|
+
getDefaultApiVersion
|
|
8
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
9
|
+
import {
|
|
10
|
+
ImportKind,
|
|
11
|
+
NameType,
|
|
12
|
+
normalizeName,
|
|
13
|
+
OperationParameter,
|
|
14
|
+
OperationResponse,
|
|
15
|
+
PathParameter,
|
|
16
|
+
Paths,
|
|
17
|
+
RLCModel,
|
|
18
|
+
RLCOptions,
|
|
19
|
+
Schema,
|
|
20
|
+
UrlInfo
|
|
21
|
+
} from "@azure-tools/rlc-common";
|
|
22
|
+
import {
|
|
23
|
+
Program,
|
|
24
|
+
Type,
|
|
25
|
+
BooleanLiteral,
|
|
26
|
+
StringLiteral,
|
|
27
|
+
NumericLiteral,
|
|
28
|
+
ModelProperty,
|
|
29
|
+
listServices,
|
|
30
|
+
NoTarget,
|
|
31
|
+
Service,
|
|
32
|
+
getDoc,
|
|
33
|
+
getService
|
|
34
|
+
} from "@typespec/compiler";
|
|
35
|
+
import { getServers } from "@typespec/http";
|
|
36
|
+
import { join } from "path";
|
|
37
|
+
import {
|
|
38
|
+
getFormattedPropertyDoc,
|
|
39
|
+
getSchemaForType,
|
|
40
|
+
getTypeName
|
|
41
|
+
} from "../modelUtils.js";
|
|
42
|
+
import { transformAnnotationDetails } from "./transformAnnotationDetails.js";
|
|
43
|
+
import { transformToParameterTypes } from "./transformParameters.js";
|
|
44
|
+
import { transformPaths } from "./transformPaths.js";
|
|
45
|
+
import { transformToResponseTypes } from "./transformResponses.js";
|
|
46
|
+
import { transformSchemas } from "./transformSchemas.js";
|
|
47
|
+
import { transformRLCOptions } from "./transfromRLCOptions.js";
|
|
48
|
+
import { isApiVersion } from "@azure-tools/typespec-client-generator-core";
|
|
49
|
+
import { reportDiagnostic } from "../lib.js";
|
|
50
|
+
import { transformApiVersionParam } from "./transformApiVersionParam.js";
|
|
51
|
+
|
|
52
|
+
export async function transformRLCModel(
|
|
53
|
+
program: Program,
|
|
54
|
+
emitterOptions: RLCOptions,
|
|
55
|
+
client: Client,
|
|
56
|
+
emitterOutputDir: string,
|
|
57
|
+
dpgContext: DpgContext
|
|
58
|
+
): Promise<RLCModel> {
|
|
59
|
+
const options: RLCOptions = transformRLCOptions(
|
|
60
|
+
program,
|
|
61
|
+
emitterOptions,
|
|
62
|
+
emitterOutputDir,
|
|
63
|
+
dpgContext
|
|
64
|
+
);
|
|
65
|
+
const srcPath = join(
|
|
66
|
+
emitterOutputDir ?? "",
|
|
67
|
+
"src",
|
|
68
|
+
options.batch && options.batch.length > 1
|
|
69
|
+
? normalizeName(client.name.replace("Client", ""), NameType.File)
|
|
70
|
+
: ""
|
|
71
|
+
);
|
|
72
|
+
const libraryName = normalizeName(
|
|
73
|
+
options.batch && options.batch.length > 1
|
|
74
|
+
? client.name
|
|
75
|
+
: options?.title ?? getDefaultService(program)?.title ?? "",
|
|
76
|
+
NameType.Class
|
|
77
|
+
);
|
|
78
|
+
const importSet = new Map<ImportKind, Set<string>>();
|
|
79
|
+
const paths: Paths = transformPaths(program, client, dpgContext);
|
|
80
|
+
const schemas: Schema[] = transformSchemas(program, client, dpgContext);
|
|
81
|
+
const apiVersionInQueryParam = transformApiVersionParam(
|
|
82
|
+
client,
|
|
83
|
+
program,
|
|
84
|
+
dpgContext
|
|
85
|
+
);
|
|
86
|
+
const responses: OperationResponse[] = transformToResponseTypes(
|
|
87
|
+
program,
|
|
88
|
+
importSet,
|
|
89
|
+
client,
|
|
90
|
+
dpgContext
|
|
91
|
+
);
|
|
92
|
+
const parameters: OperationParameter[] = transformToParameterTypes(
|
|
93
|
+
program,
|
|
94
|
+
importSet,
|
|
95
|
+
client,
|
|
96
|
+
dpgContext
|
|
97
|
+
);
|
|
98
|
+
const annotations = transformAnnotationDetails(program, client, dpgContext);
|
|
99
|
+
const urlInfo = transformUrlInfo(program, dpgContext);
|
|
100
|
+
return {
|
|
101
|
+
srcPath,
|
|
102
|
+
libraryName,
|
|
103
|
+
paths,
|
|
104
|
+
options,
|
|
105
|
+
schemas,
|
|
106
|
+
responses,
|
|
107
|
+
importSet,
|
|
108
|
+
apiVersionInQueryParam,
|
|
109
|
+
parameters,
|
|
110
|
+
annotations,
|
|
111
|
+
urlInfo
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function transformUrlInfo(
|
|
116
|
+
program: Program,
|
|
117
|
+
dpgContext: DpgContext
|
|
118
|
+
): UrlInfo | undefined {
|
|
119
|
+
const serviceNs = getDefaultService(program)?.type;
|
|
120
|
+
let endpoint = undefined;
|
|
121
|
+
const urlParameters: PathParameter[] = [];
|
|
122
|
+
if (serviceNs) {
|
|
123
|
+
const host = getServers(program, serviceNs);
|
|
124
|
+
if (host?.[0]?.url) {
|
|
125
|
+
endpoint = host[0].url;
|
|
126
|
+
}
|
|
127
|
+
if (host && host?.[0] && host?.[0]?.parameters) {
|
|
128
|
+
// Currently we only support one parameter in the servers definition
|
|
129
|
+
for (const key of host[0].parameters.keys()) {
|
|
130
|
+
const property = host?.[0]?.parameters.get(key);
|
|
131
|
+
const type = property?.type;
|
|
132
|
+
|
|
133
|
+
if (!type) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const schema = getSchemaForType(program, type);
|
|
138
|
+
urlParameters.push({
|
|
139
|
+
name: key,
|
|
140
|
+
type: getTypeName(schema),
|
|
141
|
+
description:
|
|
142
|
+
(getDoc(program, property) &&
|
|
143
|
+
getFormattedPropertyDoc(
|
|
144
|
+
program,
|
|
145
|
+
property,
|
|
146
|
+
schema,
|
|
147
|
+
" " /* sperator*/
|
|
148
|
+
)) ??
|
|
149
|
+
getFormattedPropertyDoc(program, type, schema, " " /* sperator*/),
|
|
150
|
+
value: getDefaultValue(
|
|
151
|
+
program,
|
|
152
|
+
dpgContext,
|
|
153
|
+
host?.[0]?.parameters.get(key)
|
|
154
|
+
)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Set the default value if missing endpoint parameter
|
|
160
|
+
if (endpoint == undefined && urlParameters.length === 0) {
|
|
161
|
+
endpoint = "{endpoint}";
|
|
162
|
+
urlParameters.push({
|
|
163
|
+
name: "endpoint",
|
|
164
|
+
type: "string"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return { endpoint, urlParameters };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getDefaultValue(
|
|
171
|
+
program: Program,
|
|
172
|
+
dpgContext: DpgContext,
|
|
173
|
+
param?: ModelProperty
|
|
174
|
+
) {
|
|
175
|
+
const otherDefaultValue = param?.default;
|
|
176
|
+
const serviceNamespace = getDefaultService(program)?.type;
|
|
177
|
+
if (!serviceNamespace) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const defaultApiVersion =
|
|
181
|
+
getDefaultApiVersion(dpgContext, serviceNamespace)?.value ??
|
|
182
|
+
getService(program, serviceNamespace)?.version;
|
|
183
|
+
if (param && isApiVersion(dpgContext, param) && defaultApiVersion) {
|
|
184
|
+
return defaultApiVersion;
|
|
185
|
+
} else if (isLiteralValue(otherDefaultValue)) {
|
|
186
|
+
return otherDefaultValue.value;
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function isLiteralValue(
|
|
192
|
+
type?: Type
|
|
193
|
+
): type is StringLiteral | NumericLiteral | BooleanLiteral {
|
|
194
|
+
if (!type) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (
|
|
199
|
+
type.kind === "Boolean" ||
|
|
200
|
+
type.kind === "String" ||
|
|
201
|
+
type.kind === "Number"
|
|
202
|
+
) {
|
|
203
|
+
return type.value !== undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function getDefaultService(program: Program): Service | undefined {
|
|
210
|
+
const services = listServices(program);
|
|
211
|
+
if (!services || services.length === 0) {
|
|
212
|
+
reportDiagnostic(program, {
|
|
213
|
+
code: "no-service-defined",
|
|
214
|
+
target: NoTarget
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (services.length > 1) {
|
|
218
|
+
reportDiagnostic(program, {
|
|
219
|
+
code: "more-than-one-service",
|
|
220
|
+
target: NoTarget
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return services[0];
|
|
224
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { PagedResultMetadata } from "@azure-tools/typespec-azure-core";
|
|
2
|
+
import {
|
|
3
|
+
Client,
|
|
4
|
+
DpgContext,
|
|
5
|
+
listOperationGroups,
|
|
6
|
+
listOperationsInOperationGroup
|
|
7
|
+
} from "@azure-tools/typespec-client-generator-core";
|
|
8
|
+
import { AnnotationDetails } from "@azure-tools/rlc-common";
|
|
9
|
+
import { ignoreDiagnostics, Model, Program, Type } from "@typespec/compiler";
|
|
10
|
+
import { getHttpOperation, HttpOperation } from "@typespec/http";
|
|
11
|
+
import {
|
|
12
|
+
hasPagingOperations,
|
|
13
|
+
extractPagedMetadataNested,
|
|
14
|
+
hasPollingOperations
|
|
15
|
+
} from "../operationUtil.js";
|
|
16
|
+
import { getSpecialSerializeInfo } from "./transformParameters.js";
|
|
17
|
+
|
|
18
|
+
export function transformAnnotationDetails(
|
|
19
|
+
program: Program,
|
|
20
|
+
client: Client,
|
|
21
|
+
dpgContext: DpgContext
|
|
22
|
+
): AnnotationDetails | undefined {
|
|
23
|
+
// Extract paged metadata from Azure.Core.Page
|
|
24
|
+
const annotationDetails = {
|
|
25
|
+
hasLongRunning: hasPollingOperations(program, client, dpgContext)
|
|
26
|
+
};
|
|
27
|
+
const details = extractPageDetailFromCore(program, client, dpgContext);
|
|
28
|
+
const serializeInfo = extractSpecialSerializeInfo(
|
|
29
|
+
program,
|
|
30
|
+
client,
|
|
31
|
+
dpgContext
|
|
32
|
+
);
|
|
33
|
+
if (details) {
|
|
34
|
+
return {
|
|
35
|
+
...details,
|
|
36
|
+
...annotationDetails,
|
|
37
|
+
...serializeInfo
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// TODO: Remove this when @pageable is finally removed.
|
|
41
|
+
const nextLinks = new Set<string>();
|
|
42
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
43
|
+
for (const operationGroup of operationGroups) {
|
|
44
|
+
const operations = listOperationsInOperationGroup(
|
|
45
|
+
dpgContext,
|
|
46
|
+
operationGroup
|
|
47
|
+
);
|
|
48
|
+
for (const op of operations) {
|
|
49
|
+
const route = ignoreDiagnostics(getHttpOperation(program, op));
|
|
50
|
+
if (getPageable(program, route.operation)) {
|
|
51
|
+
const nextLinkName =
|
|
52
|
+
getPageable(program, route.operation) || "nextLink";
|
|
53
|
+
if (nextLinkName) {
|
|
54
|
+
nextLinks.add(nextLinkName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
60
|
+
for (const clientOp of clientOperations) {
|
|
61
|
+
const route = ignoreDiagnostics(getHttpOperation(program, clientOp));
|
|
62
|
+
if (getPageable(program, route.operation)) {
|
|
63
|
+
const nextLinkName = getPageable(program, route.operation) || "nextLink";
|
|
64
|
+
if (nextLinkName) {
|
|
65
|
+
nextLinks.add(nextLinkName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (nextLinks.size === 0) {
|
|
70
|
+
return {
|
|
71
|
+
...annotationDetails,
|
|
72
|
+
...serializeInfo
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
...annotationDetails,
|
|
77
|
+
hasPaging: true,
|
|
78
|
+
pageDetails: {
|
|
79
|
+
itemNames: ["value"],
|
|
80
|
+
nextLinkNames: [...nextLinks],
|
|
81
|
+
isComplexPaging: nextLinks.size > 1
|
|
82
|
+
},
|
|
83
|
+
...serializeInfo
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const pageableOperationsKey = Symbol("pageable");
|
|
87
|
+
export function getPageable(
|
|
88
|
+
program: Program,
|
|
89
|
+
entity: Type
|
|
90
|
+
): string | undefined {
|
|
91
|
+
return program.stateMap(pageableOperationsKey).get(entity);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function extractPageDetailFromCore(
|
|
95
|
+
program: Program,
|
|
96
|
+
client: Client,
|
|
97
|
+
dpgContext: DpgContext
|
|
98
|
+
) {
|
|
99
|
+
if (!hasPagingOperations(program, client, dpgContext)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const nextLinks = new Set<string>();
|
|
103
|
+
const itemNames = new Set<string>();
|
|
104
|
+
// Add default values
|
|
105
|
+
nextLinks.add("nextLink");
|
|
106
|
+
itemNames.add("value");
|
|
107
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
108
|
+
for (const operationGroup of operationGroups) {
|
|
109
|
+
const operations = listOperationsInOperationGroup(
|
|
110
|
+
dpgContext,
|
|
111
|
+
operationGroup
|
|
112
|
+
);
|
|
113
|
+
for (const op of operations) {
|
|
114
|
+
const route = ignoreDiagnostics(getHttpOperation(program, op));
|
|
115
|
+
extractPageDetailFromCoreForRoute(route);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
119
|
+
for (const clientOp of clientOperations) {
|
|
120
|
+
const route = ignoreDiagnostics(getHttpOperation(program, clientOp));
|
|
121
|
+
extractPageDetailFromCoreForRoute(route);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function extractPageDetailFromCoreForRoute(route: HttpOperation) {
|
|
125
|
+
for (const response of route.responses) {
|
|
126
|
+
const paged = extractPagedMetadataNested(program, response.type as Model);
|
|
127
|
+
if (paged) {
|
|
128
|
+
const nextLinkName = parseNextLinkName(paged);
|
|
129
|
+
if (nextLinkName) {
|
|
130
|
+
nextLinks.add(nextLinkName);
|
|
131
|
+
}
|
|
132
|
+
const itemName = parseItemName(paged);
|
|
133
|
+
if (itemName) {
|
|
134
|
+
itemNames.add(itemName);
|
|
135
|
+
}
|
|
136
|
+
// Once we find paged metadata, we don't need to processs any further.
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// If there are more than one options for nextLink and item names we need to generate a
|
|
142
|
+
// more complex pagination helper.
|
|
143
|
+
const isComplexPaging = nextLinks.size > 1 || itemNames.size > 1;
|
|
144
|
+
return {
|
|
145
|
+
hasPaging: true,
|
|
146
|
+
pageDetails: {
|
|
147
|
+
itemNames: [...itemNames],
|
|
148
|
+
nextLinkNames: [...nextLinks],
|
|
149
|
+
isComplexPaging
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function parseNextLinkName(paged: PagedResultMetadata): string | undefined {
|
|
155
|
+
const pathComponents = paged.nextLinkPath?.split(".");
|
|
156
|
+
if (pathComponents) {
|
|
157
|
+
// TODO: This logic breaks down if there actually is a dotted path.
|
|
158
|
+
return pathComponents[pathComponents.length - 1];
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function parseItemName(paged: PagedResultMetadata): string | undefined {
|
|
164
|
+
const pathComponents = paged.itemsPath?.split(".");
|
|
165
|
+
if (pathComponents) {
|
|
166
|
+
// TODO: This logic breaks down if there actually is a dotted path.
|
|
167
|
+
return pathComponents[pathComponents.length - 1];
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function extractSpecialSerializeInfo(
|
|
173
|
+
program: Program,
|
|
174
|
+
client: Client,
|
|
175
|
+
dpgContext: DpgContext
|
|
176
|
+
) {
|
|
177
|
+
let hasMultiCollection = false;
|
|
178
|
+
let hasPipeCollection = false;
|
|
179
|
+
let hasTsvCollection = false;
|
|
180
|
+
let hasSsvCollection = false;
|
|
181
|
+
const operationGroups = listOperationGroups(dpgContext, client);
|
|
182
|
+
for (const operationGroup of operationGroups) {
|
|
183
|
+
const operations = listOperationsInOperationGroup(
|
|
184
|
+
dpgContext,
|
|
185
|
+
operationGroup
|
|
186
|
+
);
|
|
187
|
+
for (const op of operations) {
|
|
188
|
+
const route = ignoreDiagnostics(getHttpOperation(program, op));
|
|
189
|
+
route.parameters.parameters.forEach((parameter) => {
|
|
190
|
+
const serializeInfo = getSpecialSerializeInfo(parameter);
|
|
191
|
+
hasMultiCollection = hasMultiCollection
|
|
192
|
+
? hasMultiCollection
|
|
193
|
+
: serializeInfo.hasMultiCollection;
|
|
194
|
+
hasPipeCollection = hasPipeCollection
|
|
195
|
+
? hasPipeCollection
|
|
196
|
+
: serializeInfo.hasPipeCollection;
|
|
197
|
+
hasTsvCollection = hasTsvCollection
|
|
198
|
+
? hasTsvCollection
|
|
199
|
+
: serializeInfo.hasTsvCollection;
|
|
200
|
+
hasSsvCollection = hasSsvCollection
|
|
201
|
+
? hasSsvCollection
|
|
202
|
+
: serializeInfo.hasSsvCollection;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const clientOperations = listOperationsInOperationGroup(dpgContext, client);
|
|
207
|
+
for (const clientOp of clientOperations) {
|
|
208
|
+
const route = ignoreDiagnostics(getHttpOperation(program, clientOp));
|
|
209
|
+
route.parameters.parameters.forEach((parameter) => {
|
|
210
|
+
const serializeInfo = getSpecialSerializeInfo(parameter);
|
|
211
|
+
hasMultiCollection = hasMultiCollection
|
|
212
|
+
? hasMultiCollection
|
|
213
|
+
: serializeInfo.hasMultiCollection;
|
|
214
|
+
hasPipeCollection = hasPipeCollection
|
|
215
|
+
? hasPipeCollection
|
|
216
|
+
: serializeInfo.hasPipeCollection;
|
|
217
|
+
hasTsvCollection = hasTsvCollection
|
|
218
|
+
? hasTsvCollection
|
|
219
|
+
: serializeInfo.hasTsvCollection;
|
|
220
|
+
hasSsvCollection = hasSsvCollection
|
|
221
|
+
? hasSsvCollection
|
|
222
|
+
: serializeInfo.hasSsvCollection;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
hasMultiCollection,
|
|
227
|
+
hasPipeCollection,
|
|
228
|
+
hasTsvCollection,
|
|
229
|
+
hasSsvCollection
|
|
230
|
+
};
|
|
231
|
+
}
|