Skip to content

Commit

Permalink
Integrate the cadl-ranch cases for encode and empty model cases (#1875)
Browse files Browse the repository at this point in the history
* Update the test case

* Update the encode cases

* UPdate the changes

* Update the logic

* Update the logic

* Improve the encode cases

* Update the empty cases
  • Loading branch information
MaryGao committed Jun 2, 2023
1 parent ae1228f commit 9d38d3b
Show file tree
Hide file tree
Showing 27 changed files with 982 additions and 59 deletions.
32 changes: 16 additions & 16 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"ts-node": "^10.9.1",
"typescript": "~5.0.0",
"prettier": "~2.7.1",
"@azure-tools/cadl-ranch-specs": "~0.15.0",
"@azure-tools/cadl-ranch-specs": "~0.15.4",
"@typespec/versioning": "~0.44.0",
"@azure-tools/cadl-ranch-expect": "^0.3.1",
"@azure-tools/cadl-ranch": "~0.4.14",
"@azure-tools/cadl-ranch-expect": "^0.3.2",
"@azure-tools/cadl-ranch": "~0.4.17",
"chalk": "^4.0.0",
"@azure-rest/core-client": "^1.1.3",
"@azure/core-auth": "^1.3.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/typespec-ts/src/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ function getSchemaForScalar(
scalar: Scalar,
relevantProperty?: ModelProperty
) {
let result = getSchemaForStdScalar(program, scalar, relevantProperty);
const encodeData = getEncode(program, scalar);
let result: any = encodeData
? getSchemaForScalar(program, dpgContext, encodeData.type)
: getSchemaForStdScalar(program, scalar, relevantProperty);
if (!result && scalar.baseScalar) {
result = getSchemaForScalar(program, dpgContext, scalar.baseScalar);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/typespec-ts/test/commands/cadl-ranch-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const cadls: CadlRanchConfig[] = [
outputPath: "models/usage",
inputPath: "type/model/usage"
},
{
outputPath: "models/empty",
inputPath: "type/model/empty"
},
{
outputPath: "resiliency/srvDriven1",
inputPath: "resiliency/srv-driven/old.tsp"
Expand Down
49 changes: 49 additions & 0 deletions packages/typespec-ts/test/integration/emptyModel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { assert } from "chai";
import TypeModelEmptyClientFactory, {
TypeModelEmptyClient
} from "./generated/models/empty/src/index.js";
describe("TypeModelEmptyClient Rest Client", () => {
let client: TypeModelEmptyClient;

beforeEach(() => {
client = TypeModelEmptyClientFactory({
allowInsecureConnection: true,
retryOptions: {
maxRetries: 0
}
});
});

it(`should put empty model`, async () => {
try {
const result = await client.path("/type/model/empty/alone").put({
body: {}
});
assert.strictEqual(result.status, "204");
} catch (err) {
assert.fail(err as string);
}
});

it(`should get empty model`, async () => {
try {
const result = await client.path("/type/model/empty/alone").get();
assert.strictEqual(result.status, "200");
assert.isEmpty(result.body);
} catch (err) {
assert.fail(err as string);
}
});

it(`should post round-trip empty model`, async () => {
try {
const result = await client.path("/type/model/empty/round-trip").post({
body: {}
});
assert.strictEqual(result.status, "200");
assert.isEmpty(result.body);
} catch (err) {
assert.fail(err as string);
}
});
});
Loading

0 comments on commit 9d38d3b

Please sign in to comment.