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

Upgrade typespec dep version to v0.56 in May #2503

Merged
merged 30 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
addcb8e
upgrade typespec dep version
kazrael2119 May 8, 2024
9669ef5
fix issues in serialize utils
qiaozha May 8, 2024
44b6eb5
merge to the main
MaryGao May 13, 2024
1b401ec
Merge remote-tracking branch 'origin/main' into upgrade-typespec-dep
MaryGao May 13, 2024
1d48824
Update the lock file
MaryGao May 13, 2024
c9c7f5e
Fix the rlc to mitigate typepsec breakings
MaryGao May 13, 2024
51f2069
Fix the modular issue for ut
MaryGao May 13, 2024
9f38fb0
Merge remote-tracking branch 'origin/main' into upgrade-typespec-dep
MaryGao May 13, 2024
f5960ee
Revert serialize changes
MaryGao May 13, 2024
83551ae
Update the UTs for modular
MaryGao May 13, 2024
c1e75d2
Fail to generate smoke testing
MaryGao May 13, 2024
e45599c
Fix the stateMap issue
MaryGao May 14, 2024
938a387
Update the smoke testing
MaryGao May 14, 2024
bc3d8d8
update the smoke testing
MaryGao May 14, 2024
26632b8
Regen todo spec and mavd spec
MaryGao May 15, 2024
da096f0
Regen to fix issues
MaryGao May 15, 2024
18fdbbb
Regen batch
MaryGao May 15, 2024
1ca73b6
Regen batch and todo non branded tsp
MaryGao May 15, 2024
09f5475
Update the tsp
MaryGao May 15, 2024
5e3b755
Update the case
MaryGao May 15, 2024
7ddc829
Update the tsp
MaryGao May 15, 2024
e489298
update the lock file
MaryGao May 15, 2024
419cad1
Merge branch 'main' into upgrade-typespec-dep
MaryGao May 15, 2024
e5e8cb9
Update the lock file
MaryGao May 15, 2024
04128ee
Regen rlc test
MaryGao May 15, 2024
139c9e1
Update .vscode/launch.json
MaryGao May 15, 2024
cd7dce6
Merge branch 'upgrade-typespec-dep' of https://github.com/kazrael2119…
MaryGao May 15, 2024
7e7d279
Update .vscode/launch.json
MaryGao May 15, 2024
cce551c
Update the version to resolve issues
MaryGao May 16, 2024
c49c26a
Change to openapi3 emitter
MaryGao May 16, 2024
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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
{
"name": "[TypeSpec] Smoke Test Debug",
"request": "launch",
"cwd": "${workspaceFolder}/packages/typespec-test/test/customWrapper",
"cwd": "${workspaceFolder}/packages/typespec-test/test/contoso",
"runtimeArgs": ["tsp", "compile", "./spec"],
"runtimeExecutable": "npx",
"skipFiles": ["<node_internals>/**"],
Expand Down
266 changes: 104 additions & 162 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"type": "module",
"dependencies": {
"@azure-tools/typespec-ts": "workspace:^0.28.0",
"@typespec/openapi": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.41.0 <1.0.0",
"@typespec/openapi3": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.5 <1.0.0",
"@typespec/compiler": ">=0.55.0 <1.0.0",
"@typespec/http": ">=0.55.0 <1.0.0",
"@typespec/rest": ">=0.55.0 <1.0.0",
"@typespec/versioning": ">=0.55.0 <1.0.0",
"@typespec/openapi": ">=0.56.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.42.0 <1.0.0",
"@typespec/openapi3": ">=0.56.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.42.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.42 <1.0.0",
"@typespec/compiler": ">=0.56.0 <1.0.0",
"@typespec/http": ">=0.56.0 <1.0.0",
"@typespec/rest": ">=0.56.0 <1.0.0",
"@typespec/versioning": ">=0.56.0 <1.0.0",
"prettier": "^3.1.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ export interface ResourceOperationStatusOutput {
result?: WidgetOutput;
}

/** Provides status details for long running operations. */
export interface OperationStatusOutput {
/** The unique ID of the operation. */
id: string;
/** The status of the operation */
status: OperationStateOutput;
/** Error object that describes the error when status is "Failed". */
error?: ErrorModel;
}

/** Enum describing allowed operation states. */
export type OperationStateOutput =
| "NotStarted"
Expand Down
24 changes: 12 additions & 12 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@
"@azure/core-util": "^1.4.0",
"eslint-plugin-require-extensions": "0.1.3",
"@typespec/ts-http-runtime": "1.0.0-alpha.20240314.2",
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.5 <1.0.0",
"@typespec/compiler": ">=0.55.0 <1.0.0",
"@typespec/http": ">=0.55.0 <1.0.0",
"@typespec/rest": ">=0.55.0 <1.0.0",
"@typespec/versioning": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.42.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.42.2 <1.0.0",
"@typespec/compiler": ">=0.56.0 <1.0.0",
"@typespec/http": ">=0.56.0 <1.0.0",
"@typespec/rest": ">=0.56.0 <1.0.0",
"@typespec/versioning": ">=0.56.0 <1.0.0",
"npm-run-all": "~4.1.5"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.5 <1.0.0",
"@typespec/compiler": ">=0.55.0 <1.0.0",
"@typespec/http": ">=0.55.0 <1.0.0",
"@typespec/rest": ">=0.55.0 <1.0.0",
"@typespec/versioning": ">=0.55.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.42.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.42.2 <1.0.0",
"@typespec/compiler": ">=0.56.0 <1.0.0",
"@typespec/http": ">=0.56.0 <1.0.0",
"@typespec/rest": ">=0.56.0 <1.0.0",
"@typespec/versioning": ">=0.56.0 <1.0.0"
},
"dependencies": {
"prettier": "^3.1.0",
Expand Down
44 changes: 22 additions & 22 deletions packages/typespec-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,6 @@ export async function $onEmit(context: EmitContext) {
};
}

function createContextWithDefaultOptions(
context: EmitContext<Record<string, any>>
): SdkContext {
const tcgcSettings = {
"generate-protocol-methods": true,
"generate-convenience-methods": true,
"flatten-union-as-enum": false,
emitters: [
{
main: "@azure-tools/typespec-ts",
metadata: { name: "@azure-tools/typespec-ts" }
}
]
};
context.options = {
...context.options,
...tcgcSettings
};

return createSdkContext(context) as SdkContext;
}

async function clearSrcFolder() {
await fsextra.emptyDir(
dpgContext.generationPathDetail?.modularSourcesDir ??
Expand Down Expand Up @@ -347,3 +325,25 @@ export async function $onEmit(context: EmitContext) {
}
}
}

export function createContextWithDefaultOptions(
context: EmitContext<Record<string, any>>
): SdkContext {
const tcgcSettings = {
"generate-protocol-methods": true,
"generate-convenience-methods": true,
"flatten-union-as-enum": false,
emitters: [
{
main: "@azure-tools/typespec-ts",
metadata: { name: "@azure-tools/typespec-ts" }
}
]
};
context.options = {
...context.options,
...tcgcSettings
};

return createSdkContext(context) as SdkContext;
}
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ describe("anonymous model", () => {
foo?: string;
};
}
op read(@body body: Test): void;
op read(@bodyRoot body: Test): void;
`;
const modelFile = await emitModularModelsFromTypeSpec(tspContent);
assert.ok(modelFile);
Expand Down Expand Up @@ -723,7 +723,7 @@ describe("anonymous model", () => {
}
it("should map empty anonymous model({}) => Record<string, any>", async () => {
const tspContent = `
op read(): {};
op read(): { @body _: {}; };
`;
// No models.ts file generated
assert.isUndefined(await emitModularModelsFromTypeSpec(tspContent));
Expand All @@ -741,7 +741,7 @@ describe("anonymous model", () => {
const tspContent = `
model PublishResult {
}
op read(): PublishResult;
op read(): {@body _: PublishResult};
`;
const modelFile = await emitModularModelsFromTypeSpec(tspContent);
await assertEqualContent(
Expand Down
6 changes: 3 additions & 3 deletions packages/typespec-ts/test/modularUnit/enumUnion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("header parameters", () => {
op get(
@header("test-header") testHeader: SchemaContentTypeValues,
@body body: string,
): { @header("test-header") testHeader: SchemaContentTypeValues };
): { @header("test-header") testHeader: SchemaContentTypeValues; @statusCode _: 204; };
`;
const schemaOutput = await emitModularModelsFromTypeSpec(
tspDefinition,
Expand Down Expand Up @@ -307,7 +307,7 @@ describe("header parameters", () => {
op get(
@header("test-header") testHeader: "A" | "B",
@body body: string,
): { @header("test-header") testHeader: "A" | "B" };
): { @header("test-header") testHeader: "A" | "B"; @statusCode _: 204; };
`;
const schemaOutput = await emitModularModelsFromTypeSpec(
tspDefinition,
Expand Down Expand Up @@ -386,7 +386,7 @@ describe("header parameters", () => {
op get(
@header("test-header") testHeader: "A" | "B" | string,
@body body: string,
): { @header("test-header") testHeader: "A" | "B" | string };
): { @header("test-header") testHeader: "A" | "B" | string; @statusCode _: 204; };
`;
const schemaOutput = await emitModularModelsFromTypeSpec(
tspDefinition,
Expand Down
12 changes: 6 additions & 6 deletions packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ describe("inheritance & polymorphism", () => {
op get(
@header("test-header") testHeader: SchemaContentTypeValues,
@body body: string,
): { @header("test-header") testHeader: SchemaContentTypeValues };
): { @header("test-header") testHeader: SchemaContentTypeValues; @statusCode _: 204; };
`;
const schemaOutput = await emitModularModelsFromTypeSpec(
tspDefinition,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ describe("inheritance & polymorphism", () => {
op get(
@header("test-header") testHeader: "A" | "B",
@body body: string,
): { @header("test-header") testHeader: "A" | "B" };
): { @header("test-header") testHeader: "A" | "B"; @statusCode _: 204; };
`;
const schemaOutput = await emitModularModelsFromTypeSpec(
tspDefinition,
Expand Down Expand Up @@ -1732,7 +1732,7 @@ describe("`is`", () => {
@query
name: string;
};
op read(@body body: A): void;
op read(@bodyRoot body: A): void;
`);
assert.ok(modelFile);
await assertEqualContent(
Expand All @@ -1757,7 +1757,7 @@ describe("`extends`", () => {
@query
name: string;
};
op read(@body body: A): void;
op read(@bodyRoot body: A): void;
`);
assert.ok(modelFile);
await assertEqualContent(
Expand Down Expand Up @@ -1829,7 +1829,7 @@ describe("spread record", () => {
true
);
assert.ok(modelFile);
assert.strictEqual(modelFile?.getFilePath(), "/models/models.ts");
assert.isTrue(modelFile?.getFilePath()?.endsWith("/models/models.ts"));
await assertEqualContent(
modelFile!.getFullText()!,
`
Expand Down Expand Up @@ -1883,7 +1883,7 @@ describe("spread record", () => {
true
);
assert.ok(modelFile);
assert.strictEqual(modelFile?.getFilePath(), "/models/models.ts");
assert.isTrue(modelFile?.getFilePath()?.endsWith("/models/models.ts"));
await assertEqualContent(
modelFile!.getFullText()!,
`
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-ts/test/unit/modelsGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Input/output model type", () => {
#suppress "@azure-tools/typespec-azure-core/documentation-required" "for test"
@route("/models")
@get
op getModel(@body input: InputOutputModel): InputOutputModel;`,
op getModel(@bodyRoot input: InputOutputModel): InputOutputModel;`,
needAzureCore,
needTCGC
);
Expand Down Expand Up @@ -1658,7 +1658,7 @@ describe("Input/output model type", () => {
assert.ok(schemaOutput);
const { inputModelFile } = schemaOutput!;
assert.ok(inputModelFile);
assert.strictEqual(inputModelFile?.path, "models.ts");
assert.isTrue(inputModelFile?.path?.endsWith("models.ts"));
await assertEqualContent(
inputModelFile?.content!,
`
Expand Down Expand Up @@ -3524,7 +3524,7 @@ describe("Input/output model type", () => {
op get(
@header("test-header") testHeader: SchemaContentTypeValues,
@body body: string,
): { @header("test-header") testHeader: SchemaContentTypeValues };
): { @header("test-header") testHeader: SchemaContentTypeValues; @statusCode _: 204; };
`;
const schemaOutput = await emitModelsFromTypeSpec(
tspDefinition,
Expand Down Expand Up @@ -3634,7 +3634,7 @@ describe("Input/output model type", () => {
op get(
@header("test-header") testHeader: "A" | "B",
@body body: string,
): { @header("test-header") testHeader: "A" | "B" };
): { @header("test-header") testHeader: "A" | "B"; @statusCode _: 204; };
`;
const schemaOutput = await emitModelsFromTypeSpec(
tspDefinition,
Expand Down
8 changes: 5 additions & 3 deletions packages/typespec-ts/test/unit/responsesGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { assertEqualContent } from "../util/testUtil.js";

describe("Responses.ts", () => {
describe("property name generation", () => {
it("should generate property name with custome name", async () => {
it("should generate property name with custom name", async () => {
const responses = await emitResponsesFromTypeSpec(`
model SimpleModel {}
@doc("Metadata for long running operation status monitor locations")
model LongRunningStatusLocation {
@statusCode _: 204;
@doc("The location for monitoring the operation state.")
@header("Operation-Location")
operationLocation: ResourceLocation<SimpleModel>;
Expand All @@ -38,11 +39,12 @@ describe("Responses.ts", () => {
);
});

it("should generate property name without custome name", async () => {
it("should generate property name without custom name", async () => {
const responses = await emitResponsesFromTypeSpec(`
model SimpleModel {}
@doc("Metadata for long running operation status monitor locations")
model LongRunningStatusLocation {
@statusCode _: 204;
@doc("The location for monitoring the operation state.")
@header
operationLocation: ResourceLocation<SimpleModel>;
Expand Down Expand Up @@ -71,7 +73,7 @@ describe("Responses.ts", () => {
});

describe("statusCode generation", () => {
it("should generate property name with custome name", async () => {
it("should generate property name with custom name", async () => {
const responses = await emitResponsesFromTypeSpec(`
@doc("Error")
@error
Expand Down
25 changes: 8 additions & 17 deletions packages/typespec-ts/test/util/testUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Program } from "@typespec/compiler";
import { EmitContext, Program } from "@typespec/compiler";
import { createTestHost } from "@typespec/compiler/testing";
import { TestHost } from "@typespec/compiler/testing";
import { RestTestLibrary } from "@typespec/rest/testing";
Expand All @@ -10,6 +10,7 @@ import { SdkContext } from "../../src/utils/interfaces.js";
import { assert } from "chai";
import { format } from "prettier";
import { prettierTypeScriptOptions } from "../../src/lib.js";
import { createContextWithDefaultOptions } from "../../src/index.js";

export async function createRLCEmitterTestHost() {
return createTestHost({
Expand Down Expand Up @@ -75,23 +76,13 @@ export function createDpgContextTestHelper(
program: Program,
enableModelNamespace = false
): SdkContext {
const defaultOptions = {
generateProtocolMethods: true,
generateConvenienceMethods: true,
flattenUnionAsEnum: false,
emitters: [
{
main: "@azure-tools/typespec-ts",
metadata: { name: "@azure-tools/typespec-ts" }
}
]
};
const resolvedOptions = { ...defaultOptions };
program.emitters = resolvedOptions.emitters as any;
const context = createContextWithDefaultOptions({
program
} as EmitContext);

return {
program: program,
generateProtocolMethods: resolvedOptions.generateProtocolMethods,
generateConvenienceMethods: resolvedOptions.generateConvenienceMethods,
...context,
program,
rlcOptions: { flavor: "azure", enableModelNamespace },
generationPathDetail: {},
emitterName: "@azure-tools/typespec-ts",
Expand Down
Loading