Skip to content

Commit e6a1d96

Browse files
authored
Add cadl ranch model inheritance other test cases for RLC (#2009)
* add-cadl-ranch-mode-inheritacn-other-test-cases * fix inheritance * resolve comments of description
1 parent 8f5b8a9 commit e6a1d96

49 files changed

Lines changed: 2037 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/typespec-ts/test/commands/cadl-ranch-list.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ export const rlcTsps: TypeSpecRanchConfig[] = [
8989
outputPath: "models/inheritance",
9090
inputPath: "type/model/inheritance/nested-discriminator"
9191
},
92+
{
93+
outputPath: "models/inheritance-not-discriminated",
94+
inputPath: "type/model/inheritance/not-discriminated"
95+
},
96+
{
97+
outputPath: "models/inheritance-enum-discriminator",
98+
inputPath: "type/model/inheritance/enum-discriminator"
99+
},
100+
{
101+
outputPath: "models/inheritance-single-discriminator",
102+
inputPath: "type/model/inheritance/single-discriminator"
103+
},
92104
{
93105
outputPath: "models/propertyOptional",
94106
inputPath: "type/property/optional"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"plugins": ["@azure/azure-sdk"],
3+
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
4+
"rules": {
5+
"@azure/azure-sdk/ts-modules-only-named": "warn",
6+
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
7+
"@azure/azure-sdk/ts-package-json-types": "warn",
8+
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
9+
"tsdoc/syntax": "warn"
10+
}
11+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# EnumDiscriminator REST client library for JavaScript
2+
3+
Illustrates inheritance with enum discriminator.
4+
5+
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
6+
7+
Key links:
8+
9+
- [Package (NPM)](https://www.npmjs.com/package/@msinternal/model-inheritance-enum-discriminator)
10+
11+
## Getting started
12+
13+
### Currently supported environments
14+
15+
- LTS versions of Node.js
16+
17+
### Prerequisites
18+
19+
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
20+
21+
### Install the `@msinternal/model-inheritance-enum-discriminator` package
22+
23+
Install the EnumDiscriminator REST client REST client library for JavaScript with `npm`:
24+
25+
```bash
26+
npm install @msinternal/model-inheritance-enum-discriminator
27+
```
28+
29+
### Create and authenticate a `EnumDiscriminatorClient`
30+
31+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
32+
provide an instance of the desired credential type obtained from the
33+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
34+
35+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
36+
37+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
38+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
39+
can be used to authenticate the client.
40+
41+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
42+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
43+
44+
## Troubleshooting
45+
46+
### Logging
47+
48+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
49+
50+
```javascript
51+
const { setLogLevel } = require("@azure/logger");
52+
53+
setLogLevel("info");
54+
```
55+
56+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "./types/index.d.ts",
4+
"docModel": { "enabled": true },
5+
"apiReport": { "enabled": true, "reportFolder": "./review" },
6+
"dtsRollup": {
7+
"enabled": true,
8+
"untrimmedFilePath": "",
9+
"publicTrimmedFilePath": "./types/model-inheritance-enum-discriminator.d.ts"
10+
},
11+
"messages": {
12+
"tsdocMessageReporting": { "default": { "logLevel": "none" } },
13+
"extractorMessageReporting": {
14+
"ae-missing-release-tag": { "logLevel": "none" },
15+
"ae-unresolved-link": { "logLevel": "none" }
16+
}
17+
}
18+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"name": "@msinternal/model-inheritance-enum-discriminator",
3+
"sdk-type": "client",
4+
"author": "Microsoft Corporation",
5+
"version": "1.0.0",
6+
"description": "Model Inheritance Test Service",
7+
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
8+
"license": "MIT",
9+
"main": "dist/index.js",
10+
"module": "./dist-esm/index.js",
11+
"types": "./types/model-inheritance-enum-discriminator.d.ts",
12+
"repository": "github:Azure/azure-sdk-for-js",
13+
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
14+
"files": [
15+
"dist/",
16+
"dist-esm/",
17+
"types/model-inheritance-enum-discriminator.d.ts",
18+
"README.md",
19+
"LICENSE",
20+
"review/*"
21+
],
22+
"engines": { "node": ">=14.0.0" },
23+
"scripts": {
24+
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
25+
"build:browser": "echo skipped.",
26+
"build:node": "echo skipped.",
27+
"build:samples": "echo skipped.",
28+
"build:test": "echo skipped.",
29+
"build:debug": "echo skipped.",
30+
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
31+
"clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log",
32+
"execute:samples": "echo skipped",
33+
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
34+
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
35+
"generate:client": "echo skipped",
36+
"integration-test:browser": "echo skipped",
37+
"integration-test:node": "echo skipped",
38+
"integration-test": "echo skipped",
39+
"lint:fix": "eslint package.json api-extractor.json src --ext .ts --fix --fix-type [problem,suggestion]",
40+
"lint": "eslint package.json api-extractor.json src --ext .ts",
41+
"pack": "npm pack 2>&1",
42+
"test:browser": "echo skipped",
43+
"test:node": "echo skipped",
44+
"test": "echo \"Error: no test specified\" && exit 1",
45+
"unit-test": "echo skipped",
46+
"unit-test:node": "echo skipped",
47+
"unit-test:browser": "echo skipped",
48+
"build": "npm run clean && tsc && rollup -c 2>&1 && npm run minify && mkdirp ./review && npm run extract-api",
49+
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js"
50+
},
51+
"sideEffects": false,
52+
"autoPublish": false,
53+
"dependencies": {
54+
"@azure/core-auth": "^1.3.0",
55+
"@azure-rest/core-client": "^1.1.4",
56+
"@azure/core-rest-pipeline": "^1.12.0",
57+
"@azure/logger": "^1.0.0",
58+
"tslib": "^2.2.0"
59+
},
60+
"devDependencies": {
61+
"@microsoft/api-extractor": "^7.31.1",
62+
"autorest": "latest",
63+
"@types/node": "^14.0.0",
64+
"dotenv": "^16.0.0",
65+
"eslint": "^8.0.0",
66+
"mkdirp": "^2.1.2",
67+
"prettier": "^2.5.1",
68+
"rimraf": "^5.0.0",
69+
"source-map-support": "^0.5.9",
70+
"typescript": "~5.0.0",
71+
"@rollup/plugin-commonjs": "^24.0.0",
72+
"@rollup/plugin-json": "^6.0.0",
73+
"@rollup/plugin-multi-entry": "^6.0.0",
74+
"@rollup/plugin-node-resolve": "^13.1.3",
75+
"rollup": "^2.66.1",
76+
"rollup-plugin-sourcemaps": "^0.6.3",
77+
"uglify-js": "^3.4.9"
78+
},
79+
"type": "module"
80+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import nodeResolve from "@rollup/plugin-node-resolve";
5+
import cjs from "@rollup/plugin-commonjs";
6+
import sourcemaps from "rollup-plugin-sourcemaps";
7+
import multiEntry from "@rollup/plugin-multi-entry";
8+
import json from "@rollup/plugin-json";
9+
10+
import nodeBuiltins from "builtin-modules";
11+
12+
// #region Warning Handler
13+
14+
/**
15+
* A function that can determine whether a rollup warning should be ignored. If
16+
* the function returns `true`, then the warning will not be displayed.
17+
*/
18+
19+
function ignoreNiseSinonEval(warning) {
20+
return (
21+
warning.code === "EVAL" &&
22+
warning.id &&
23+
(warning.id.includes("node_modules/nise") ||
24+
warning.id.includes("node_modules/sinon")) === true
25+
);
26+
}
27+
28+
function ignoreChaiCircularDependency(warning) {
29+
return (
30+
warning.code === "CIRCULAR_DEPENDENCY" &&
31+
warning.importer &&
32+
warning.importer.includes("node_modules/chai") === true
33+
);
34+
}
35+
36+
const warningInhibitors = [ignoreChaiCircularDependency, ignoreNiseSinonEval];
37+
38+
/**
39+
* Construct a warning handler for the shared rollup configuration
40+
* that ignores certain warnings that are not relevant to testing.
41+
*/
42+
function makeOnWarnForTesting() {
43+
return (warning, warn) => {
44+
// If every inhibitor returns false (i.e. no inhibitors), then show the warning
45+
if (warningInhibitors.every((inhib) => !inhib(warning))) {
46+
warn(warning);
47+
}
48+
};
49+
}
50+
51+
// #endregion
52+
53+
function makeBrowserTestConfig() {
54+
const config = {
55+
input: {
56+
include: ["dist-esm/test/**/*.spec.js"],
57+
exclude: ["dist-esm/test/**/node/**"],
58+
},
59+
output: {
60+
file: `dist-test/index.browser.js`,
61+
format: "umd",
62+
sourcemap: true,
63+
},
64+
preserveSymlinks: false,
65+
plugins: [
66+
multiEntry({ exports: false }),
67+
nodeResolve({
68+
mainFields: ["module", "browser"],
69+
}),
70+
cjs(),
71+
json(),
72+
sourcemaps(),
73+
//viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
74+
],
75+
onwarn: makeOnWarnForTesting(),
76+
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0,
77+
// rollup started respecting the "sideEffects" field in package.json. Since
78+
// our package.json sets "sideEffects=false", this also applies to test
79+
// code, which causes all tests to be removed by tree-shaking.
80+
treeshake: false,
81+
};
82+
83+
return config;
84+
}
85+
86+
const defaultConfigurationOptions = {
87+
disableBrowserBundle: false,
88+
};
89+
90+
export function makeConfig(pkg, options) {
91+
options = {
92+
...defaultConfigurationOptions,
93+
...(options || {}),
94+
};
95+
96+
const baseConfig = {
97+
// Use the package's module field if it has one
98+
input: pkg["module"] || "dist-esm/src/index.js",
99+
external: [
100+
...nodeBuiltins,
101+
...Object.keys(pkg.dependencies),
102+
...Object.keys(pkg.devDependencies),
103+
],
104+
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
105+
preserveSymlinks: false,
106+
plugins: [sourcemaps(), nodeResolve()],
107+
};
108+
109+
const config = [baseConfig];
110+
111+
if (!options.disableBrowserBundle) {
112+
config.push(makeBrowserTestConfig());
113+
}
114+
115+
return config;
116+
}
117+
118+
export default makeConfig(require("./package.json"));

0 commit comments

Comments
 (0)