Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate the cadl-ranch cases for encode and empty model cases #1875

Merged
merged 8 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading