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

Sample generation for MPG for cliassical client #2770

Merged
merged 110 commits into from
Sep 18, 2024

Conversation

MaryGao
Copy link
Contributor

@MaryGao MaryGao commented Aug 26, 2024

fixes #2539

Scope

This pr would support sample generation for classical client from TCGC SdkPackage. And the api layer sample generation is not in this pr's scope.

The main test cases are covered under modularUnit/scenarios/samples. And we also enable serveral test cases in smoke testing.

Non Scope

Full support for client-level parameter will be covered

Some known issues

case "null":
case "any":
case "union":
retValue = `${value.value}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about union of models where the model have different serializeName and client name?

Copy link
Contributor Author

@MaryGao MaryGao Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not covered by current tcgc and issue tracked here: Azure/typespec-azure#1556. and we are blocked by tcgc design yet and let me know if any service impacted especially for mpg. Our issue is here: #2826.

@@ -259,6 +265,15 @@ export async function $onEmit(context: EmitContext) {

const isMultiClients = modularCodeModel.clients.length > 1;

// Enable modular sample generation when explicitly set to true or MPG
if (emitterOptions?.generateSample === true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since RLC sample generation is not supported yet, what would happen if generateSample is true but isModularLibrary is false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be crashed as

$ npx tsp compile ./client.tsp
TypeSpec compiler v0.59.0

Emitter "@azure-tools/typespec-ts" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.typescript/issues

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:569:31)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at handleHttpResponse (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:318:13)

--------------------------------------------------
Library Version                0.33.0
TypeSpec Compiler Version      0.59.0
--------------------------------------------------

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RLC sample generation from given example is not supported and it should be covered in issue: #2538.

But we have implemented a version for sample generation from fake value. So if generateSample is true but isModularLibrary is false even though this is not recommanded but it should generate fake values and see smoke case here: https://github.com/Azure/autorest.typescript/blob/main/packages/typespec-test/test/loadTest/tspconfig.yaml#L25.

Copy link
Contributor Author

@MaryGao MaryGao Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be crashed as

$ npx tsp compile ./client.tsp
TypeSpec compiler v0.59.0

Emitter "@azure-tools/typespec-ts" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.typescript/issues

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:569:31)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at getSdkModelExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:573:11)
    at getSdkTypeExample (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:443:16)
    at handleHttpResponse (file:///D:/Git/autorest.typescript/common/temp/node_modules/.pnpm/@[email protected]_rxzquxnvxkwebgrumlsfc6ni5i/node_modules/@azure-tools/typespec-client-generator-core/src/example.ts:318:13)

--------------------------------------------------
Library Version                0.33.0
TypeSpec Compiler Version      0.59.0
--------------------------------------------------

@kazrael2119 there should be no issue even if we enable sample gen for RLC and example folder. and this issue is thrown from tcgc before running it could you ensure the example and tsp are latest?

Copy link
Contributor

@kazrael2119 kazrael2119 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I update isModularLibrary as false in networkanalytics , and it would generate samples, but for loadtest, it failed as above error message, I create a draft pr to investigate MaryGao#45

Copy link
Contributor Author

@MaryGao MaryGao Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue confirmed is a tcgc bug and should be fixed in latest version(not integrate yet) in loadtest.

async function read() {
const client = new TestingClient();
const result = await client.read("required path param", "required query", {
body: { name: "body name" },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check if we need body key for optional body in HLC and if this is correct in the modular ?

Copy link
Contributor Author

@MaryGao MaryGao Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaryGao MaryGao merged commit 2d85b98 into Azure:main Sep 18, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate samples for modular classical client
9 participants