-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
…into sample-experienmental
packages/typespec-ts/test/modularIntegration/generated/azure/example/basic/src/index.d.ts
Show resolved
Hide resolved
packages/typespec-ts/test/modularUnit/scenarios/samples/operations/multipleExamplesInOneFile.md
Outdated
Show resolved
Hide resolved
...tworkAnalytics.Management/generated/typespec-ts/samples-dev/dataProductsAddUserRoleSample.ts
Show resolved
Hide resolved
...st/NetworkAnalytics.Management/generated/typespec-ts/samples-dev/dataProductsCreateSample.ts
Show resolved
Hide resolved
case "null": | ||
case "any": | ||
case "union": | ||
retValue = `${value.value}`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
--------------------------------------------------
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" }, |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems there exists in-consistancy between hlc and modular: #2827. I prefer skipping this case for now until we finalize the modular design.
see hlc swagger: https://github.com/Azure/autorest.typescript/blob/main/packages/autorest.typescript/test/integration/swaggers/appconfiguration.json#L457-L462
hlc generated code: https://github.com/Azure/autorest.typescript/blob/main/packages/autorest.typescript/test/integration/generated/appconfiguration/src/models/index.ts#L512-L513
modular generated code:
https://github.com/Azure/autorest.typescript/blob/main/packages/typespec-ts/test/modularIntegration/generated/parameters/body-optionality/src/index.d.ts#L25-L26
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