@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,1319 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { emitModelsFromCadl, emitParameterFromCadl } from "./util/emitUtil.js";
|
|
3
|
+
import { assertEqualContent } from "./util/testUtil.js";
|
|
4
|
+
|
|
5
|
+
type VerifyPropertyConfig = {
|
|
6
|
+
additionalCadlDefinition?: string;
|
|
7
|
+
outputType?: string;
|
|
8
|
+
additionalInputContent?: string;
|
|
9
|
+
additionalOutputContent?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe("Input/output model type", () => {
|
|
13
|
+
it("shouldn't generate models if there is no operations", async () => {
|
|
14
|
+
const schemaOutput = await emitModelsFromCadl(`
|
|
15
|
+
model Test {
|
|
16
|
+
prop: string;
|
|
17
|
+
}
|
|
18
|
+
`);
|
|
19
|
+
assert.ok(schemaOutput);
|
|
20
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
21
|
+
// both are undefined
|
|
22
|
+
assert.ok(!inputModelFile);
|
|
23
|
+
assert.ok(!outputModelFile);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
async function verifyPropertyType(
|
|
27
|
+
cadlType: string,
|
|
28
|
+
inputType: string,
|
|
29
|
+
options?: VerifyPropertyConfig,
|
|
30
|
+
needAzureCore: boolean = false
|
|
31
|
+
) {
|
|
32
|
+
const defaultOption: VerifyPropertyConfig = {
|
|
33
|
+
additionalCadlDefinition: "",
|
|
34
|
+
outputType: inputType,
|
|
35
|
+
additionalInputContent: "",
|
|
36
|
+
additionalOutputContent: ""
|
|
37
|
+
};
|
|
38
|
+
const {
|
|
39
|
+
additionalCadlDefinition,
|
|
40
|
+
outputType,
|
|
41
|
+
additionalInputContent,
|
|
42
|
+
additionalOutputContent
|
|
43
|
+
} = {
|
|
44
|
+
...defaultOption,
|
|
45
|
+
...options
|
|
46
|
+
};
|
|
47
|
+
const schemaOutput = await emitModelsFromCadl(
|
|
48
|
+
`
|
|
49
|
+
${additionalCadlDefinition}
|
|
50
|
+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
|
|
51
|
+
model InputOutputModel {
|
|
52
|
+
prop: ${cadlType};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "for test"
|
|
56
|
+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
|
|
57
|
+
@route("/models")
|
|
58
|
+
@get
|
|
59
|
+
op getModel(@body input: InputOutputModel): InputOutputModel;`,
|
|
60
|
+
needAzureCore
|
|
61
|
+
);
|
|
62
|
+
assert.ok(schemaOutput);
|
|
63
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
64
|
+
assert.strictEqual(inputModelFile?.path, "models.ts");
|
|
65
|
+
assertEqualContent(
|
|
66
|
+
inputModelFile?.content!,
|
|
67
|
+
`
|
|
68
|
+
export interface InputOutputModel {
|
|
69
|
+
prop: ${inputType};
|
|
70
|
+
}
|
|
71
|
+
${additionalInputContent}`
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
assert.strictEqual(outputModelFile?.path, "outputModels.ts");
|
|
75
|
+
assertEqualContent(
|
|
76
|
+
outputModelFile?.content!,
|
|
77
|
+
`
|
|
78
|
+
export interface InputOutputModelOutput {
|
|
79
|
+
prop: ${outputType};
|
|
80
|
+
}
|
|
81
|
+
${additionalOutputContent}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("null generation", async () => {
|
|
86
|
+
it("should generate null only", async () => {
|
|
87
|
+
const cadlType = "null";
|
|
88
|
+
const typeScriptType = "null";
|
|
89
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should generate nullable union", async () => {
|
|
93
|
+
const cadlType = "string | null";
|
|
94
|
+
const typeScriptType = "string | null";
|
|
95
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should generate nullable array", async () => {
|
|
99
|
+
const cadlDefinition = `
|
|
100
|
+
alias nullableArray = int32 | null;`;
|
|
101
|
+
const cadlType = "nullableArray[]";
|
|
102
|
+
const typeScriptType = "(number | null)[]";
|
|
103
|
+
await verifyPropertyType(cadlType, typeScriptType, {
|
|
104
|
+
additionalCadlDefinition: cadlDefinition
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should generate nullable boolean dictionary", async () => {
|
|
109
|
+
const cadlType = "Record<boolean | null>";
|
|
110
|
+
const typeScriptType = "Record<string, boolean | null>";
|
|
111
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should generate nullable model", async () => {
|
|
115
|
+
const cadlDefinition = `
|
|
116
|
+
model SimpleModel {
|
|
117
|
+
color: "red" | "blue";
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
const cadlType = "SimpleModel | null";
|
|
121
|
+
const typeScriptType = "SimpleModel | null";
|
|
122
|
+
await verifyPropertyType(cadlType, typeScriptType, {
|
|
123
|
+
additionalCadlDefinition: cadlDefinition,
|
|
124
|
+
outputType: "SimpleModelOutput | null",
|
|
125
|
+
additionalInputContent: `
|
|
126
|
+
export interface SimpleModel {
|
|
127
|
+
color: "red" | "blue";
|
|
128
|
+
}
|
|
129
|
+
`,
|
|
130
|
+
additionalOutputContent: `
|
|
131
|
+
export interface SimpleModelOutput {
|
|
132
|
+
color: "red" | "blue";
|
|
133
|
+
}
|
|
134
|
+
`
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should generate nullable literal dictionary", async () => {
|
|
139
|
+
const cadlType = 'Record<"test" | null>';
|
|
140
|
+
const typeScriptType = 'Record<string, "test" | null>';
|
|
141
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("number generation", () => {
|
|
146
|
+
it("should handle int32 -> number", async () => {
|
|
147
|
+
await verifyPropertyType("int32", "number");
|
|
148
|
+
});
|
|
149
|
+
it("should handle int64 -> number", async () => {
|
|
150
|
+
await verifyPropertyType("int64", "number");
|
|
151
|
+
});
|
|
152
|
+
it("should handle safeint -> number", async () => {
|
|
153
|
+
await verifyPropertyType("safeint", "number");
|
|
154
|
+
});
|
|
155
|
+
it("should handle float32 -> number", async () => {
|
|
156
|
+
await verifyPropertyType("float32", "number");
|
|
157
|
+
});
|
|
158
|
+
it("should handle float64 -> number", async () => {
|
|
159
|
+
await verifyPropertyType("float64", "number");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("string generation", () => {
|
|
163
|
+
it("should handle extensible_enum as property -> string", async () => {
|
|
164
|
+
// When extensible_enum is comsumed as body property it should be string only
|
|
165
|
+
const schemaOutput = await emitModelsFromCadl(`
|
|
166
|
+
@doc("Extensible enum model description")
|
|
167
|
+
enum TranslationLanguageValues {
|
|
168
|
+
English,
|
|
169
|
+
Chinese,
|
|
170
|
+
}
|
|
171
|
+
model InputOutputModel {
|
|
172
|
+
@doc("Property description")
|
|
173
|
+
prop: TranslationLanguageValues;
|
|
174
|
+
}
|
|
175
|
+
@route("/models")
|
|
176
|
+
@get
|
|
177
|
+
op getModel(@body input: InputOutputModel): InputOutputModel;
|
|
178
|
+
`);
|
|
179
|
+
assert.ok(schemaOutput);
|
|
180
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
181
|
+
assertEqualContent(
|
|
182
|
+
inputModelFile?.content!,
|
|
183
|
+
`
|
|
184
|
+
export interface InputOutputModel {
|
|
185
|
+
/**
|
|
186
|
+
* Property description
|
|
187
|
+
*
|
|
188
|
+
* Possible values: English, Chinese
|
|
189
|
+
*/
|
|
190
|
+
prop: string;
|
|
191
|
+
}`
|
|
192
|
+
);
|
|
193
|
+
assertEqualContent(
|
|
194
|
+
outputModelFile?.content!,
|
|
195
|
+
`
|
|
196
|
+
export interface InputOutputModelOutput {
|
|
197
|
+
/**
|
|
198
|
+
* Property description
|
|
199
|
+
*
|
|
200
|
+
* Possible values: English, Chinese
|
|
201
|
+
*/
|
|
202
|
+
prop: string;
|
|
203
|
+
}`
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
it("should handle extensible_enum as body -> string", async () => {
|
|
207
|
+
// When extensible_enum is comsumed as body property it should be string only
|
|
208
|
+
const schemaOutput = await emitParameterFromCadl(`
|
|
209
|
+
enum TranslationLanguage {
|
|
210
|
+
English,
|
|
211
|
+
Chinese,
|
|
212
|
+
}
|
|
213
|
+
model InputOutputModel {
|
|
214
|
+
prop: TranslationLanguage;
|
|
215
|
+
}
|
|
216
|
+
@route("/models")
|
|
217
|
+
@get
|
|
218
|
+
op getModel(@body input: TranslationLanguage): InputOutputModel;
|
|
219
|
+
`);
|
|
220
|
+
assert.ok(schemaOutput);
|
|
221
|
+
assertEqualContent(
|
|
222
|
+
schemaOutput?.content!,
|
|
223
|
+
`
|
|
224
|
+
import { RequestParameters } from "@azure-rest/core-client";
|
|
225
|
+
|
|
226
|
+
export interface GetModelBodyParam {
|
|
227
|
+
/** Possible values: English, Chinese */
|
|
228
|
+
body: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type GetModelParameters = GetModelBodyParam & RequestParameters;`
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// TODO: Is enum convered to string literals only? Do we need to generate enum instaed?
|
|
236
|
+
it("should handle enum -> string_literals", async () => {
|
|
237
|
+
const cadlTypeDefinition = `
|
|
238
|
+
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "for test"
|
|
239
|
+
@fixed
|
|
240
|
+
enum TranslationLanguageValues {
|
|
241
|
+
English,
|
|
242
|
+
Chinese,
|
|
243
|
+
}`;
|
|
244
|
+
const cadlType = "TranslationLanguageValues";
|
|
245
|
+
const typeScriptType = `"English" | "Chinese"`;
|
|
246
|
+
await verifyPropertyType(
|
|
247
|
+
cadlType,
|
|
248
|
+
typeScriptType,
|
|
249
|
+
{
|
|
250
|
+
additionalCadlDefinition: cadlTypeDefinition
|
|
251
|
+
},
|
|
252
|
+
true
|
|
253
|
+
);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("should handle type_literals:string -> string_literals", async () => {
|
|
257
|
+
const cadlType = `"English" | "Chinese"`;
|
|
258
|
+
const typeScriptType = `"English" | "Chinese"`;
|
|
259
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should handle type_literals:boolean -> boolean_literals", async () => {
|
|
263
|
+
const cadlType = `true`;
|
|
264
|
+
const typeScriptType = `true`;
|
|
265
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("should handle string -> string", async () => {
|
|
269
|
+
const cadlType = "string";
|
|
270
|
+
const typeScriptType = "string";
|
|
271
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("should handle never, its property will be ignored both in Input and Ouput model", async () => {
|
|
275
|
+
const cadlDefinition = `
|
|
276
|
+
model SimpleModel {
|
|
277
|
+
prop1: never;
|
|
278
|
+
prop2: never;
|
|
279
|
+
}`;
|
|
280
|
+
const cadlType = "SimpleModel";
|
|
281
|
+
const inputModelName = "SimpleModel";
|
|
282
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
283
|
+
additionalCadlDefinition: cadlDefinition,
|
|
284
|
+
outputType: `${inputModelName}Output`,
|
|
285
|
+
additionalInputContent: `
|
|
286
|
+
export interface ${inputModelName} {}`,
|
|
287
|
+
additionalOutputContent: `
|
|
288
|
+
export interface ${inputModelName}Output {}`
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe("array basic generation", () => {
|
|
294
|
+
it("should handle string[] -> string[]", async () => {
|
|
295
|
+
const cadlType = "string[]";
|
|
296
|
+
const typeScriptType = "string[]";
|
|
297
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should handle int32[] -> number[]", async () => {
|
|
301
|
+
const cadlType = "int32[]";
|
|
302
|
+
const typeScriptType = "number[]";
|
|
303
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("should handle float32[] -> number[]", async () => {
|
|
307
|
+
const cadlType = "float32[]";
|
|
308
|
+
const typeScriptType = "number[]";
|
|
309
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("should handle boolean[] -> boolean[]", async () => {
|
|
313
|
+
const cadlType = "boolean[]";
|
|
314
|
+
const typeScriptType = "boolean[]";
|
|
315
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("should handle bytes[] -> string[]", async () => {
|
|
319
|
+
const cadlType = "bytes[]";
|
|
320
|
+
const typeScriptType = "string[]";
|
|
321
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("should handle plainDate[] -> input 'Date[] | string[]' output type 'string[]'", async () => {
|
|
325
|
+
const cadlType = "plainDate[]";
|
|
326
|
+
const inputType = "Date[] | string[]";
|
|
327
|
+
const outputType = "string[]";
|
|
328
|
+
await verifyPropertyType(cadlType, inputType, { outputType });
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("should handle true[] -> true[]", async () => {
|
|
332
|
+
const cadlType = "true[]";
|
|
333
|
+
const typeScriptType = "true[]";
|
|
334
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("should handle 32[] -> 32[]", async () => {
|
|
338
|
+
const cadlType = "32[]";
|
|
339
|
+
const typeScriptType = "32[]";
|
|
340
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("should handle 'job'[] -> 'job'[]", async () => {
|
|
344
|
+
const cadlType = `"job"[]`;
|
|
345
|
+
const typeScriptType = `"job"[]`;
|
|
346
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("should handle unknown[] -> input 'unknown[]' output type 'any[]'", async () => {
|
|
350
|
+
const cadlType = "unknown[]";
|
|
351
|
+
const inputType = "unknown[]";
|
|
352
|
+
const outputType = "any[]";
|
|
353
|
+
await verifyPropertyType(cadlType, inputType, { outputType });
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("should handle unknown -> input 'unknown' output type 'any'", async () => {
|
|
357
|
+
const cadlType = "unknown";
|
|
358
|
+
const inputType = "unknown";
|
|
359
|
+
const outputType = "any";
|
|
360
|
+
await verifyPropertyType(cadlType, inputType, { outputType });
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
describe("array models generation", () => {
|
|
364
|
+
it("should handle SimpleModel[] -> Array<SimpleModel>", async () => {
|
|
365
|
+
const cadlDefinition = `
|
|
366
|
+
model SimpleModel {
|
|
367
|
+
prop1: string;
|
|
368
|
+
prop2: int32;
|
|
369
|
+
}
|
|
370
|
+
`;
|
|
371
|
+
const cadlType = "SimpleModel[]";
|
|
372
|
+
const inputModelName = "Array<SimpleModel>";
|
|
373
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
374
|
+
additionalCadlDefinition: cadlDefinition,
|
|
375
|
+
outputType: `Array<SimpleModelOutput>`,
|
|
376
|
+
additionalInputContent: `
|
|
377
|
+
export interface SimpleModel {
|
|
378
|
+
prop1:string;
|
|
379
|
+
prop2:number;
|
|
380
|
+
}`,
|
|
381
|
+
additionalOutputContent: `
|
|
382
|
+
export interface SimpleModelOutput {
|
|
383
|
+
prop1:string;
|
|
384
|
+
prop2:number;
|
|
385
|
+
}`
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("should handle fixed enum array", async () => {
|
|
390
|
+
const cadlDefinition = `
|
|
391
|
+
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "for test"
|
|
392
|
+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
|
|
393
|
+
@fixed
|
|
394
|
+
enum DiskEncryptionTarget {
|
|
395
|
+
OsDisk: "osdisk",
|
|
396
|
+
TemporaryDisk: "temporarydisk",
|
|
397
|
+
}
|
|
398
|
+
`;
|
|
399
|
+
const cadlType = "DiskEncryptionTarget[]";
|
|
400
|
+
const typeScriptType = `("osdisk" | "temporarydisk")[]`;
|
|
401
|
+
const inputModelName = typeScriptType;
|
|
402
|
+
await verifyPropertyType(
|
|
403
|
+
cadlType,
|
|
404
|
+
inputModelName,
|
|
405
|
+
{
|
|
406
|
+
additionalCadlDefinition: cadlDefinition,
|
|
407
|
+
outputType: typeScriptType
|
|
408
|
+
},
|
|
409
|
+
true
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("should handle extensible enum array", async () => {
|
|
414
|
+
const cadlDefinition = `
|
|
415
|
+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
|
|
416
|
+
enum DiskEncryptionTarget {
|
|
417
|
+
OsDisk: "osdisk",
|
|
418
|
+
TemporaryDisk: "temporarydisk",
|
|
419
|
+
}
|
|
420
|
+
`;
|
|
421
|
+
const cadlType = "DiskEncryptionTarget[]";
|
|
422
|
+
const typeScriptType = `string[]`;
|
|
423
|
+
const inputModelName = typeScriptType;
|
|
424
|
+
await verifyPropertyType(
|
|
425
|
+
cadlType,
|
|
426
|
+
inputModelName,
|
|
427
|
+
{
|
|
428
|
+
additionalCadlDefinition: cadlDefinition,
|
|
429
|
+
outputType: typeScriptType
|
|
430
|
+
},
|
|
431
|
+
true
|
|
432
|
+
);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
describe("object generation", () => {
|
|
436
|
+
it("should handle basic model -> type/interface", async () => {
|
|
437
|
+
const cadlDefinition = `
|
|
438
|
+
model SimpleModel {
|
|
439
|
+
prop1: string;
|
|
440
|
+
prop2: int32;
|
|
441
|
+
}`;
|
|
442
|
+
const cadlType = "SimpleModel";
|
|
443
|
+
const inputModelName = "SimpleModel";
|
|
444
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
445
|
+
additionalCadlDefinition: cadlDefinition,
|
|
446
|
+
outputType: `${inputModelName}Output`,
|
|
447
|
+
additionalInputContent: `
|
|
448
|
+
export interface ${inputModelName} {
|
|
449
|
+
prop1:string;
|
|
450
|
+
prop2:number;
|
|
451
|
+
}`,
|
|
452
|
+
additionalOutputContent: `
|
|
453
|
+
export interface ${inputModelName}Output {
|
|
454
|
+
prop1:string;
|
|
455
|
+
prop2:number;
|
|
456
|
+
}`
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it("should handle nested model -> type/interface", async () => {
|
|
461
|
+
const cadlDefinition = `
|
|
462
|
+
model SimpleModel {
|
|
463
|
+
prop1: string;
|
|
464
|
+
prop2: int32;
|
|
465
|
+
}
|
|
466
|
+
model NestedModel {
|
|
467
|
+
...SimpleModel;
|
|
468
|
+
}
|
|
469
|
+
`;
|
|
470
|
+
const cadlType = "NestedModel";
|
|
471
|
+
const inputModelName = "NestedModel";
|
|
472
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
473
|
+
additionalCadlDefinition: cadlDefinition,
|
|
474
|
+
outputType: `${inputModelName}Output`,
|
|
475
|
+
additionalInputContent: `
|
|
476
|
+
export interface ${inputModelName} {
|
|
477
|
+
prop1:string;
|
|
478
|
+
prop2:number;
|
|
479
|
+
}`,
|
|
480
|
+
additionalOutputContent: `
|
|
481
|
+
export interface ${inputModelName}Output {
|
|
482
|
+
prop1:string;
|
|
483
|
+
prop2:number;
|
|
484
|
+
}`
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it.skip("should handle anonymous model -> effective type/interface", async () => {
|
|
489
|
+
const cadlDefinition = `
|
|
490
|
+
model SimpleModel {
|
|
491
|
+
prop1: string;
|
|
492
|
+
prop2: int32;
|
|
493
|
+
}
|
|
494
|
+
`;
|
|
495
|
+
const cadlType = "{...SimpleModel}";
|
|
496
|
+
const inputModelName = "SimpleModel";
|
|
497
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
498
|
+
additionalCadlDefinition: cadlDefinition,
|
|
499
|
+
outputType: `${inputModelName}Output`,
|
|
500
|
+
additionalInputContent: `
|
|
501
|
+
export interface ${inputModelName} {
|
|
502
|
+
prop1:string;
|
|
503
|
+
prop2:number;
|
|
504
|
+
}`,
|
|
505
|
+
additionalOutputContent: `
|
|
506
|
+
export interface ${inputModelName}Output {
|
|
507
|
+
prop1:string;
|
|
508
|
+
prop2:number;
|
|
509
|
+
}`
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
describe("inheritance & polymorphism", () => {
|
|
514
|
+
it("should handle inheritance model -> multiple types/interfaces", async () => {
|
|
515
|
+
const schemaOutput = await emitModelsFromCadl(`
|
|
516
|
+
@discriminator("kind")
|
|
517
|
+
model Pet {
|
|
518
|
+
name: string;
|
|
519
|
+
weight?: float32;
|
|
520
|
+
}
|
|
521
|
+
model Cat extends Pet {
|
|
522
|
+
kind: "cat";
|
|
523
|
+
meow: int32;
|
|
524
|
+
}
|
|
525
|
+
model Dog extends Pet {
|
|
526
|
+
kind: "dog";
|
|
527
|
+
bark: string;
|
|
528
|
+
}
|
|
529
|
+
op read(): { @body body: Pet };
|
|
530
|
+
`);
|
|
531
|
+
assert.ok(schemaOutput);
|
|
532
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
533
|
+
assert.ok(!inputModelFile?.content);
|
|
534
|
+
assert.strictEqual(outputModelFile?.path, "outputModels.ts");
|
|
535
|
+
assertEqualContent(
|
|
536
|
+
outputModelFile?.content!,
|
|
537
|
+
`
|
|
538
|
+
export interface PetOutputParent {
|
|
539
|
+
name: string;
|
|
540
|
+
weight?: number;
|
|
541
|
+
"kind": "Pet" | "cat" | "dog";
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export interface CatOutput extends PetOutputParent {
|
|
545
|
+
kind: "cat";
|
|
546
|
+
meow: number;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface DogOutput extends PetOutputParent {
|
|
550
|
+
kind: "dog";
|
|
551
|
+
bark: string;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export type PetOutput = CatOutput | DogOutput;`
|
|
555
|
+
);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("should handle multiple inheritance model -> multiple types/interfaces", async () => {
|
|
559
|
+
const schemaOutput = await emitModelsFromCadl(`
|
|
560
|
+
@doc("This is base model for polymorphic multiple levels inheritance with a discriminator.")
|
|
561
|
+
@discriminator("kind")
|
|
562
|
+
model Fish {
|
|
563
|
+
age: int32;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
@doc("The second level model in polymorphic multiple levels inheritance and it defines a new discriminator.")
|
|
567
|
+
@discriminator("sharktype")
|
|
568
|
+
model Shark extends Fish {
|
|
569
|
+
kind: "shark";
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
@doc("The second level model in polymorphic multiple levels inheritance which contains references to other polymorphic instances.")
|
|
573
|
+
model Salmon extends Fish {
|
|
574
|
+
kind: "salmon";
|
|
575
|
+
friends?: Fish[];
|
|
576
|
+
hate?: Record<Fish>;
|
|
577
|
+
partner?: Fish;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
@doc("The third level model SawShark in polymorphic multiple levels inheritance.")
|
|
581
|
+
@discriminator("sharktype")
|
|
582
|
+
model SawShark extends Shark {
|
|
583
|
+
sharktype: "saw";
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
@doc("The third level model GoblinShark in polymorphic multiple levels inheritance.")
|
|
587
|
+
model GoblinShark extends Shark {
|
|
588
|
+
sharktype: "goblin";
|
|
589
|
+
}
|
|
590
|
+
op read(): { @body body: Fish };
|
|
591
|
+
`);
|
|
592
|
+
assert.ok(schemaOutput);
|
|
593
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
594
|
+
assert.ok(!inputModelFile?.content);
|
|
595
|
+
assert.strictEqual(outputModelFile?.path, "outputModels.ts");
|
|
596
|
+
assertEqualContent(
|
|
597
|
+
outputModelFile?.content!,
|
|
598
|
+
`
|
|
599
|
+
/** This is base model for polymorphic multiple levels inheritance with a discriminator. */
|
|
600
|
+
export interface FishOutputParent {
|
|
601
|
+
age: number;
|
|
602
|
+
kind: "Fish" | "shark" | "salmon";
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** The second level model in polymorphic multiple levels inheritance and it defines a new discriminator. */
|
|
606
|
+
export interface SharkOutputParent extends FishOutputParent {
|
|
607
|
+
kind: "shark";
|
|
608
|
+
sharktype: "Shark" | "saw" | "goblin";
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** The third level model SawShark in polymorphic multiple levels inheritance. */
|
|
612
|
+
export interface SawSharkOutput extends SharkOutputParent {
|
|
613
|
+
sharktype: "saw";
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** The third level model GoblinShark in polymorphic multiple levels inheritance. */
|
|
617
|
+
export interface GoblinSharkOutput extends SharkOutputParent {
|
|
618
|
+
sharktype: "goblin";
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** The second level model in polymorphic multiple levels inheritance which contains references to other polymorphic instances. */
|
|
622
|
+
export interface SalmonOutput extends FishOutputParent {
|
|
623
|
+
kind: "salmon";
|
|
624
|
+
friends?: Array<FishOutput>;
|
|
625
|
+
hate?: Record<string, FishOutput>;
|
|
626
|
+
partner?: FishOutput;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** This is base model for polymorphic multiple levels inheritance with a discriminator. */
|
|
630
|
+
export type FishOutput = SharkOutput | SalmonOutput;
|
|
631
|
+
/** The second level model in polymorphic multiple levels inheritance and it defines a new discriminator. */
|
|
632
|
+
export type SharkOutput = SawSharkOutput | GoblinSharkOutput;
|
|
633
|
+
`
|
|
634
|
+
);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
it("should handle basic model with special words -> type/interface", async () => {
|
|
638
|
+
const cadlDefinition = `
|
|
639
|
+
model SimpleModel {
|
|
640
|
+
"model.kind": "derived";
|
|
641
|
+
"derived.name": string;
|
|
642
|
+
}`;
|
|
643
|
+
const cadlType = "SimpleModel";
|
|
644
|
+
const inputModelName = "SimpleModel";
|
|
645
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
646
|
+
additionalCadlDefinition: cadlDefinition,
|
|
647
|
+
outputType: `${inputModelName}Output`,
|
|
648
|
+
additionalInputContent: `
|
|
649
|
+
export interface ${inputModelName} {
|
|
650
|
+
"model.kind": "derived";
|
|
651
|
+
"derived.name": string;
|
|
652
|
+
}`,
|
|
653
|
+
additionalOutputContent: `
|
|
654
|
+
export interface ${inputModelName}Output {
|
|
655
|
+
"model.kind": "derived";
|
|
656
|
+
"derived.name": string;
|
|
657
|
+
}`
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it("should handle inheritance model with special words -> type/interface", async () => {
|
|
662
|
+
const cadlDefinition = `
|
|
663
|
+
@doc("This is a base model has discriminator name containing dot.")
|
|
664
|
+
@discriminator("model.kind")
|
|
665
|
+
model BaseModel {}
|
|
666
|
+
|
|
667
|
+
@doc("This is a model has property names of special words or characters.")
|
|
668
|
+
@discriminator("model.kind")
|
|
669
|
+
model DerivedModel extends BaseModel {
|
|
670
|
+
"model.kind": "derived";
|
|
671
|
+
"derived.name": string;
|
|
672
|
+
for: string;
|
|
673
|
+
}`;
|
|
674
|
+
const cadlType = "DerivedModel";
|
|
675
|
+
const inputModelName = "DerivedModel";
|
|
676
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
677
|
+
additionalCadlDefinition: cadlDefinition,
|
|
678
|
+
outputType: `${inputModelName}Output`,
|
|
679
|
+
additionalInputContent: `
|
|
680
|
+
/** This is a model has property names of special words or characters. */
|
|
681
|
+
export interface ${inputModelName} extends BaseModelParent {
|
|
682
|
+
"model.kind": "derived";
|
|
683
|
+
"derived.name": string;
|
|
684
|
+
for: string;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** This is a base model has discriminator name containing dot. */
|
|
688
|
+
export interface BaseModelParent {
|
|
689
|
+
"model.kind": "BaseModel" | "derived";
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/** This is a base model has discriminator name containing dot. */
|
|
693
|
+
export type BaseModel = ${inputModelName};
|
|
694
|
+
`,
|
|
695
|
+
additionalOutputContent: `
|
|
696
|
+
/** This is a model has property names of special words or characters. */
|
|
697
|
+
export interface ${inputModelName}Output extends BaseModelOutputParent {
|
|
698
|
+
"model.kind": "derived";
|
|
699
|
+
"derived.name": string;
|
|
700
|
+
for: string;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** This is a base model has discriminator name containing dot. */
|
|
704
|
+
export interface BaseModelOutputParent {
|
|
705
|
+
"model.kind": "BaseModel" | "derived";
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/** This is a base model has discriminator name containing dot. */
|
|
709
|
+
export type BaseModelOutput = ${inputModelName}Output;
|
|
710
|
+
`
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
describe("bytes generation as property", () => {
|
|
716
|
+
it("should handle bytes -> string", async () => {
|
|
717
|
+
await verifyPropertyType("bytes", "string");
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
describe("duration generation", () => {
|
|
721
|
+
it("should handle duration -> string", async () => {
|
|
722
|
+
await verifyPropertyType("duration", "string");
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
describe("datetime generation", () => {
|
|
726
|
+
it("should handle plainDate -> string in output model & `Date | string` in input model", async () => {
|
|
727
|
+
const inputType = "Date | string";
|
|
728
|
+
const outputType = "string";
|
|
729
|
+
await verifyPropertyType("plainDate", inputType, {
|
|
730
|
+
outputType
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
it("should handle plainTime -> string in output model & `Date | string` in input model", async () => {
|
|
734
|
+
const inputType = "Date | string";
|
|
735
|
+
const outputType = "string";
|
|
736
|
+
await verifyPropertyType("plainTime", inputType, {
|
|
737
|
+
outputType
|
|
738
|
+
});
|
|
739
|
+
});
|
|
740
|
+
it("should handle zonedDateTime -> string in output model & `Date | string` in input model", async () => {
|
|
741
|
+
const inputType = "Date | string";
|
|
742
|
+
const outputType = "string";
|
|
743
|
+
await verifyPropertyType("zonedDateTime", inputType, {
|
|
744
|
+
outputType
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
describe("record generation", () => {
|
|
749
|
+
it("should handle Record<int32> -> Record<string, number>", async () => {
|
|
750
|
+
await verifyPropertyType("Record<int32>", "Record<string, number>");
|
|
751
|
+
});
|
|
752
|
+
it("should handle Record<boolean> -> Record<string, boolean>", async () => {
|
|
753
|
+
await verifyPropertyType("Record<boolean>", "Record<string, boolean>");
|
|
754
|
+
});
|
|
755
|
+
it("should handle Record<string> -> Record<string, string>", async () => {
|
|
756
|
+
await verifyPropertyType("Record<string>", "Record<string, string>");
|
|
757
|
+
});
|
|
758
|
+
it("should handle Record<unknown> -> input 'Record<unknown>' output type 'Record<any>'", async () => {
|
|
759
|
+
const cadlType = "Record<unknown>";
|
|
760
|
+
const inputType = "Record<string, unknown>";
|
|
761
|
+
const outputType = "Record<string, any>";
|
|
762
|
+
await verifyPropertyType(cadlType, inputType, { outputType });
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
describe("Record Model generation", () => {
|
|
767
|
+
it("should handle Record<SimpleModel> -> Record<string, SimpleModel>", async () => {
|
|
768
|
+
const cadlDefinition = `
|
|
769
|
+
model SimpleModel {
|
|
770
|
+
prop1: string;
|
|
771
|
+
prop2: int32;
|
|
772
|
+
}
|
|
773
|
+
`;
|
|
774
|
+
const cadlType = "Record<SimpleModel>";
|
|
775
|
+
const inputModelName = "Record<string, SimpleModel>";
|
|
776
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
777
|
+
additionalCadlDefinition: cadlDefinition,
|
|
778
|
+
outputType: `Record<string, SimpleModelOutput>`,
|
|
779
|
+
additionalInputContent: `
|
|
780
|
+
export interface SimpleModel {
|
|
781
|
+
prop1:string;
|
|
782
|
+
prop2:number;
|
|
783
|
+
}`,
|
|
784
|
+
additionalOutputContent: `
|
|
785
|
+
export interface SimpleModelOutput {
|
|
786
|
+
prop1:string;
|
|
787
|
+
prop2:number;
|
|
788
|
+
}`
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
describe("property definition correctness", () => {
|
|
794
|
+
it("should handle @visibility(read) -> readonly ", async () => {
|
|
795
|
+
const cadlDefinition = `
|
|
796
|
+
model SimpleModel {
|
|
797
|
+
@visibility("read")
|
|
798
|
+
prop: int32;
|
|
799
|
+
prop1: int32;
|
|
800
|
+
}
|
|
801
|
+
`;
|
|
802
|
+
const cadlType = `SimpleModel`;
|
|
803
|
+
const inputModelName = "SimpleModel";
|
|
804
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
805
|
+
additionalCadlDefinition: cadlDefinition,
|
|
806
|
+
outputType: `${inputModelName}Output`,
|
|
807
|
+
additionalInputContent: `
|
|
808
|
+
export interface ${inputModelName} {
|
|
809
|
+
prop1:number;
|
|
810
|
+
}`,
|
|
811
|
+
additionalOutputContent: `
|
|
812
|
+
export interface ${inputModelName}Output {
|
|
813
|
+
readonly prop:number;
|
|
814
|
+
prop1:number;
|
|
815
|
+
}`
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
it("should handle optional parameter -> with question mark ", async () => {
|
|
820
|
+
const cadlDefinition = `
|
|
821
|
+
model SimpleModel {
|
|
822
|
+
prop?: int32;
|
|
823
|
+
}
|
|
824
|
+
`;
|
|
825
|
+
const cadlType = `SimpleModel`;
|
|
826
|
+
const inputModelName = cadlType;
|
|
827
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
828
|
+
additionalCadlDefinition: cadlDefinition,
|
|
829
|
+
outputType: `${inputModelName}Output`,
|
|
830
|
+
additionalInputContent: `
|
|
831
|
+
export interface ${inputModelName} {
|
|
832
|
+
prop?:number;
|
|
833
|
+
}`,
|
|
834
|
+
additionalOutputContent: `
|
|
835
|
+
export interface ${inputModelName}Output {
|
|
836
|
+
prop?:number;
|
|
837
|
+
}`
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it("should handle nullable optional/required parameter", async () => {
|
|
842
|
+
const cadlDefinition = `
|
|
843
|
+
model SimpleModel {
|
|
844
|
+
foo?: string | null;
|
|
845
|
+
bar: string | null;
|
|
846
|
+
baz: string;
|
|
847
|
+
}
|
|
848
|
+
`;
|
|
849
|
+
const cadlType = `SimpleModel`;
|
|
850
|
+
const inputModelName = cadlType;
|
|
851
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
852
|
+
additionalCadlDefinition: cadlDefinition,
|
|
853
|
+
outputType: `${inputModelName}Output`,
|
|
854
|
+
additionalInputContent: `
|
|
855
|
+
export interface ${inputModelName} {
|
|
856
|
+
foo?: string | null;
|
|
857
|
+
bar: string | null;
|
|
858
|
+
baz: string;
|
|
859
|
+
}`,
|
|
860
|
+
additionalOutputContent: `
|
|
861
|
+
export interface ${inputModelName}Output {
|
|
862
|
+
foo?: string | null;
|
|
863
|
+
bar: string | null;
|
|
864
|
+
baz: string;
|
|
865
|
+
}`
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
it("should handle optional parameter with defaul value -> general type ", async () => {
|
|
870
|
+
const cadlDefinition = `
|
|
871
|
+
model SimpleModel {
|
|
872
|
+
prop?: int32 = 0;
|
|
873
|
+
}
|
|
874
|
+
`;
|
|
875
|
+
const cadlType = `SimpleModel`;
|
|
876
|
+
const inputModelName = cadlType;
|
|
877
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
878
|
+
additionalCadlDefinition: cadlDefinition,
|
|
879
|
+
outputType: `${inputModelName}Output`,
|
|
880
|
+
additionalInputContent: `
|
|
881
|
+
export interface ${inputModelName} {
|
|
882
|
+
prop?:number;
|
|
883
|
+
}`,
|
|
884
|
+
additionalOutputContent: `
|
|
885
|
+
export interface ${inputModelName}Output {
|
|
886
|
+
prop?:number;
|
|
887
|
+
}`
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
describe("Union basic generation", () => {
|
|
892
|
+
it("should handle string | integer -> string | number", async () => {
|
|
893
|
+
const cadlType = "string | integer";
|
|
894
|
+
const typeScriptType = "string | number";
|
|
895
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
it("should handle int32 | string -> number | string", async () => {
|
|
899
|
+
const cadlType = "int32 | string";
|
|
900
|
+
const typeScriptType = "number | string";
|
|
901
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
it("should handle float32[] | string[] -> number[] | string[]", async () => {
|
|
905
|
+
const cadlType = "float32[] | string[]";
|
|
906
|
+
const typeScriptType = "number[] | string[]";
|
|
907
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
908
|
+
});
|
|
909
|
+
|
|
910
|
+
it("should handle boolean[] | string[] -> boolean[] | string[]", async () => {
|
|
911
|
+
const cadlType = "boolean[] | string[]";
|
|
912
|
+
const typeScriptType = "boolean[] | string[]";
|
|
913
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
it("should handle true[] | string[] -> true[] | string[]", async () => {
|
|
917
|
+
const cadlType = "true[] | string[]";
|
|
918
|
+
const typeScriptType = "true[] | string[]";
|
|
919
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
it("should handle 32[] | string[] -> 32[] | string[]", async () => {
|
|
923
|
+
const cadlType = "32[] | string[]";
|
|
924
|
+
const typeScriptType = "32[] | string[]";
|
|
925
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
it("should handle 'job'[] | string[] -> 'job'[] | string[]", async () => {
|
|
929
|
+
const cadlType = `"job"[] | string[]`;
|
|
930
|
+
const typeScriptType = `"job"[] | string[]`;
|
|
931
|
+
await verifyPropertyType(cadlType, typeScriptType);
|
|
932
|
+
});
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
describe("Union Models generation", () => {
|
|
936
|
+
it("should handle named unions", async () => {
|
|
937
|
+
const cadlDefinition = `
|
|
938
|
+
@doc("This is a base model.")
|
|
939
|
+
model BaseModel {
|
|
940
|
+
name: string;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
@doc("The first one of the unioned model type.")
|
|
944
|
+
model Model1 extends BaseModel {
|
|
945
|
+
prop1: int32;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
@doc("The second one of the unioned model type.")
|
|
949
|
+
model Model2 extends BaseModel {
|
|
950
|
+
prop2: int32;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
union MyNamedUnion {
|
|
954
|
+
one: Model1,
|
|
955
|
+
two: Model2,
|
|
956
|
+
}
|
|
957
|
+
`;
|
|
958
|
+
const cadlType = "MyNamedUnion";
|
|
959
|
+
const inputModelName = "MyNamedUnion";
|
|
960
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
961
|
+
additionalCadlDefinition: cadlDefinition,
|
|
962
|
+
outputType: `MyNamedUnionOutput`,
|
|
963
|
+
additionalInputContent: `
|
|
964
|
+
/** The first one of the unioned model type. */
|
|
965
|
+
export interface Model1 extends BaseModel {
|
|
966
|
+
prop1: number;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** This is a base model. */
|
|
970
|
+
export interface BaseModel {
|
|
971
|
+
name: string;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/** The second one of the unioned model type. */
|
|
975
|
+
export interface Model2 extends BaseModel {
|
|
976
|
+
prop2: number;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
export type MyNamedUnion = Model1 | Model2;`,
|
|
980
|
+
additionalOutputContent: `
|
|
981
|
+
/** The first one of the unioned model type. */
|
|
982
|
+
export interface Model1Output extends BaseModelOutput {
|
|
983
|
+
prop1: number;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/** This is a base model. */
|
|
987
|
+
export interface BaseModelOutput {
|
|
988
|
+
name: string;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/** The second one of the unioned model type. */
|
|
992
|
+
export interface Model2Output extends BaseModelOutput {
|
|
993
|
+
prop2: number;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export type MyNamedUnionOutput = Model1Output | Model2Output;`
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
it("should handle named unions with null variant", async () => {
|
|
1001
|
+
const cadlDefinition = `
|
|
1002
|
+
@doc("The first one of the unioned model type.")
|
|
1003
|
+
model Model1 {
|
|
1004
|
+
prop1: int32;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
@doc("The second one of the unioned model type.")
|
|
1008
|
+
model Model2 {
|
|
1009
|
+
prop2: int32;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
union MyNamedUnion {
|
|
1013
|
+
one: Model1,
|
|
1014
|
+
two: Model2,
|
|
1015
|
+
three: null
|
|
1016
|
+
}
|
|
1017
|
+
`;
|
|
1018
|
+
const cadlType = "MyNamedUnion";
|
|
1019
|
+
const inputModelName = "MyNamedUnion";
|
|
1020
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1021
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1022
|
+
outputType: `MyNamedUnionOutput`,
|
|
1023
|
+
additionalInputContent: `
|
|
1024
|
+
/** The first one of the unioned model type. */
|
|
1025
|
+
export interface Model1 {
|
|
1026
|
+
prop1: number;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/** The second one of the unioned model type. */
|
|
1030
|
+
export interface Model2 {
|
|
1031
|
+
prop2: number;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
export type MyNamedUnion = Model1 | Model2 | null;`,
|
|
1035
|
+
additionalOutputContent: `
|
|
1036
|
+
/** The first one of the unioned model type. */
|
|
1037
|
+
export interface Model1Output {
|
|
1038
|
+
prop1: number;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/** The second one of the unioned model type. */
|
|
1042
|
+
export interface Model2Output {
|
|
1043
|
+
prop2: number;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
export type MyNamedUnionOutput = Model1Output | Model2Output | null;`
|
|
1047
|
+
});
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
it("should handle nullable named unions", async () => {
|
|
1051
|
+
const cadlDefinition = `
|
|
1052
|
+
@doc("The first one of the unioned model type.")
|
|
1053
|
+
model Model1 {
|
|
1054
|
+
prop1: int32;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
@doc("The second one of the unioned model type.")
|
|
1058
|
+
model Model2 {
|
|
1059
|
+
prop2: int32;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
union MyNamedUnion {
|
|
1063
|
+
one: Model1,
|
|
1064
|
+
two: Model2,
|
|
1065
|
+
}
|
|
1066
|
+
`;
|
|
1067
|
+
const cadlType = "MyNamedUnion | null";
|
|
1068
|
+
const inputModelName = "MyNamedUnion | null";
|
|
1069
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1070
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1071
|
+
outputType: `MyNamedUnionOutput | null`,
|
|
1072
|
+
additionalInputContent: `
|
|
1073
|
+
/** The first one of the unioned model type. */
|
|
1074
|
+
export interface Model1 {
|
|
1075
|
+
prop1: number;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/** The second one of the unioned model type. */
|
|
1079
|
+
export interface Model2 {
|
|
1080
|
+
prop2: number;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
export type MyNamedUnion = Model1 | Model2;`,
|
|
1084
|
+
additionalOutputContent: `
|
|
1085
|
+
/** The first one of the unioned model type. */
|
|
1086
|
+
export interface Model1Output {
|
|
1087
|
+
prop1: number;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/** The second one of the unioned model type. */
|
|
1091
|
+
export interface Model2Output {
|
|
1092
|
+
prop2: number;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
export type MyNamedUnionOutput = Model1Output | Model2Output;`
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
describe("'is' keyword generation", () => {
|
|
1101
|
+
it("should handle A is B, only A is referenced", async () => {
|
|
1102
|
+
const cadlDefinition = `
|
|
1103
|
+
model B {
|
|
1104
|
+
"prop": string;
|
|
1105
|
+
}
|
|
1106
|
+
model A is B{
|
|
1107
|
+
"prop1": string;
|
|
1108
|
+
}`;
|
|
1109
|
+
const cadlType = "A";
|
|
1110
|
+
const inputModelName = "A";
|
|
1111
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1112
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1113
|
+
outputType: `${inputModelName}Output`,
|
|
1114
|
+
additionalInputContent: `
|
|
1115
|
+
export interface ${inputModelName} {
|
|
1116
|
+
"prop": string;
|
|
1117
|
+
"prop1": string;
|
|
1118
|
+
}`,
|
|
1119
|
+
additionalOutputContent: `
|
|
1120
|
+
export interface ${inputModelName}Output {
|
|
1121
|
+
"prop": string;
|
|
1122
|
+
"prop1": string;
|
|
1123
|
+
}`
|
|
1124
|
+
});
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
it("should handle A is B, both A and B are referenced", async () => {
|
|
1128
|
+
const schemaOutput = await emitModelsFromCadl(`
|
|
1129
|
+
model B {
|
|
1130
|
+
"prop": string;
|
|
1131
|
+
}
|
|
1132
|
+
model A is B{
|
|
1133
|
+
"prop1": string;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
@route("/models")
|
|
1137
|
+
@get
|
|
1138
|
+
op getModel(@body input: A): B;`);
|
|
1139
|
+
assert.ok(schemaOutput);
|
|
1140
|
+
const { inputModelFile, outputModelFile } = schemaOutput!;
|
|
1141
|
+
assert.ok(inputModelFile?.content);
|
|
1142
|
+
assert.strictEqual(outputModelFile?.path, "outputModels.ts");
|
|
1143
|
+
assertEqualContent(
|
|
1144
|
+
inputModelFile?.content!,
|
|
1145
|
+
`
|
|
1146
|
+
export interface A {
|
|
1147
|
+
"prop": string;
|
|
1148
|
+
"prop1": string;
|
|
1149
|
+
}
|
|
1150
|
+
`
|
|
1151
|
+
);
|
|
1152
|
+
assertEqualContent(
|
|
1153
|
+
outputModelFile?.content!,
|
|
1154
|
+
`
|
|
1155
|
+
export interface BOutput {
|
|
1156
|
+
"prop": string;
|
|
1157
|
+
}
|
|
1158
|
+
`
|
|
1159
|
+
);
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
it("should handle A is B, B is string", async () => {
|
|
1163
|
+
const cadlDefinition = `
|
|
1164
|
+
scalar MyStr extends string;`;
|
|
1165
|
+
const cadlType = "MyStr";
|
|
1166
|
+
const inputModelName = "string";
|
|
1167
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1168
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1169
|
+
outputType: `${inputModelName}`
|
|
1170
|
+
});
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
describe("@projectedName", () => {
|
|
1175
|
+
it("should generate projected json name for property", async () => {
|
|
1176
|
+
const cadlDefinition = `
|
|
1177
|
+
@doc("This is a Foo model.")
|
|
1178
|
+
model FooModel {
|
|
1179
|
+
@projectedName("json", "xJson")
|
|
1180
|
+
@projectedName("javascript", "MadeForTS")
|
|
1181
|
+
@projectedName("client", "NotToUseMeAsName") // Should be ignored
|
|
1182
|
+
x: int32;
|
|
1183
|
+
|
|
1184
|
+
y: string;
|
|
1185
|
+
}
|
|
1186
|
+
`;
|
|
1187
|
+
const cadlType = "FooModel";
|
|
1188
|
+
const inputModelName = "FooModel";
|
|
1189
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1190
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1191
|
+
outputType: `FooModelOutput`,
|
|
1192
|
+
additionalInputContent: `
|
|
1193
|
+
/** This is a Foo model. */
|
|
1194
|
+
export interface FooModel {
|
|
1195
|
+
xJson: number;
|
|
1196
|
+
y: string;
|
|
1197
|
+
}`,
|
|
1198
|
+
additionalOutputContent: `
|
|
1199
|
+
/** This is a Foo model. */
|
|
1200
|
+
export interface FooModelOutput {
|
|
1201
|
+
xJson: number;
|
|
1202
|
+
y: string;
|
|
1203
|
+
}`
|
|
1204
|
+
});
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
it("should generate augmented projected json name for property", async () => {
|
|
1208
|
+
const cadlDefinition = `
|
|
1209
|
+
@doc("This is a Foo model.")
|
|
1210
|
+
model FooModel {
|
|
1211
|
+
x: int32;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
@@projectedName(FooModel.x, "client", "NotToUseMeAsName") // Should be ignored
|
|
1215
|
+
@@projectedName(FooModel.x, "javascript", "MadeForTS")
|
|
1216
|
+
@@projectedName(FooModel.x, "json", "xJson")
|
|
1217
|
+
`;
|
|
1218
|
+
const cadlType = "FooModel";
|
|
1219
|
+
const inputModelName = "FooModel";
|
|
1220
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1221
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1222
|
+
outputType: `FooModelOutput`,
|
|
1223
|
+
additionalInputContent: `
|
|
1224
|
+
/** This is a Foo model. */
|
|
1225
|
+
export interface FooModel {
|
|
1226
|
+
xJson: number;
|
|
1227
|
+
}`,
|
|
1228
|
+
additionalOutputContent: `
|
|
1229
|
+
/** This is a Foo model. */
|
|
1230
|
+
export interface FooModelOutput {
|
|
1231
|
+
xJson: number;
|
|
1232
|
+
}`
|
|
1233
|
+
});
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
it("should generate projected model name over friendly name", async () => {
|
|
1237
|
+
const cadlDefinition = `
|
|
1238
|
+
@projectedName("javascript", "CustomProjectedModelTS")
|
|
1239
|
+
@projectedName("json", "CustomProjectedModel")
|
|
1240
|
+
@friendlyName("CustomFriendlyModel")
|
|
1241
|
+
@doc("This is a Foo model.")
|
|
1242
|
+
model FooModel {
|
|
1243
|
+
x: int32;
|
|
1244
|
+
}
|
|
1245
|
+
`;
|
|
1246
|
+
const cadlType = "FooModel";
|
|
1247
|
+
const inputModelName = "CustomProjectedModelTS";
|
|
1248
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1249
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1250
|
+
outputType: `CustomProjectedModelTSOutput`,
|
|
1251
|
+
additionalInputContent: `
|
|
1252
|
+
/** This is a Foo model. */
|
|
1253
|
+
export interface CustomProjectedModelTS {
|
|
1254
|
+
x: number;
|
|
1255
|
+
}`,
|
|
1256
|
+
additionalOutputContent: `
|
|
1257
|
+
/** This is a Foo model. */
|
|
1258
|
+
export interface CustomProjectedModelTSOutput {
|
|
1259
|
+
x: number;
|
|
1260
|
+
}`
|
|
1261
|
+
});
|
|
1262
|
+
});
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
describe("@friendlyName for model", () => {
|
|
1266
|
+
it("should generate friendly name", async () => {
|
|
1267
|
+
const cadlDefinition = `
|
|
1268
|
+
@friendlyName("MyNameIsA")
|
|
1269
|
+
model A { }
|
|
1270
|
+
`;
|
|
1271
|
+
const cadlType = "A";
|
|
1272
|
+
const inputModelName = "MyNameIsA";
|
|
1273
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1274
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1275
|
+
outputType: `MyNameIsAOutput`,
|
|
1276
|
+
additionalInputContent: `
|
|
1277
|
+
export interface MyNameIsA {}
|
|
1278
|
+
`,
|
|
1279
|
+
additionalOutputContent: `
|
|
1280
|
+
export interface MyNameIsAOutput {}
|
|
1281
|
+
`
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
it("should generate templated friendly name", async () => {
|
|
1286
|
+
const cadlDefinition = `
|
|
1287
|
+
@friendlyName("{name}Model", Base)
|
|
1288
|
+
model Base { }
|
|
1289
|
+
|
|
1290
|
+
@friendlyName("Templated{name}", T)
|
|
1291
|
+
model Templated<T> {
|
|
1292
|
+
prop: T;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
model X is Templated<Base>{};
|
|
1296
|
+
`;
|
|
1297
|
+
const cadlType = "X";
|
|
1298
|
+
const inputModelName = "TemplatedBase";
|
|
1299
|
+
await verifyPropertyType(cadlType, inputModelName, {
|
|
1300
|
+
additionalCadlDefinition: cadlDefinition,
|
|
1301
|
+
outputType: `TemplatedBaseOutput`,
|
|
1302
|
+
additionalInputContent: `
|
|
1303
|
+
export interface TemplatedBase {
|
|
1304
|
+
prop: BaseModel;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
export interface BaseModel {}
|
|
1308
|
+
`,
|
|
1309
|
+
additionalOutputContent: `
|
|
1310
|
+
export interface TemplatedBaseOutput {
|
|
1311
|
+
prop: BaseModelOutput;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
export interface BaseModelOutput {}
|
|
1315
|
+
`
|
|
1316
|
+
});
|
|
1317
|
+
});
|
|
1318
|
+
});
|
|
1319
|
+
});
|