-
Notifications
You must be signed in to change notification settings - Fork 75
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
Refactor the sample generation into rlc-common & Generate samples with mock content #2002
Conversation
…ample-refactoring
...est.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodySample.ts
Outdated
Show resolved
Hide resolved
.../test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodyNoAcceptHeaderSample.ts
Outdated
Show resolved
Hide resolved
leave some comments |
packages/autorest.typescript/src/restLevelClient/transforms/transformParameterTypes.ts
Outdated
Show resolved
Hide resolved
packages/autorest.typescript/src/generators/samples/rlcSampleGenerator.ts
Show resolved
Hide resolved
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.
LGTM, just some minor comments
sample.methodParamAssignments = getAssignmentStrArray(parameters.method); | ||
sample.methodParamNames = parameters.method.length > 0 ? "options" : ""; | ||
sample.methodParamNames = | ||
parameters.method.length > 0 ? parameters.method[0].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.
Just a little curious about the priority between ? and ??. should we use parentheses to be explicit here ?
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 priority should be good if i added parentheses explicitly the formatter would remove them automatically.
parameters.method.length > 0 ? (parameters.method[0].value ?? "") : "";
I mean something like true[] or 12[] or "test"[]
updated.
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.
LGTM, just some minor comments
fixes #2000
The pr is mainly focusing on generating samples if no real examples provided. Here is the high-level design:
rlc-common
In common layer we provide a transform function which could generate sample content based on path/schema/operation details in RLCModel. Currently we only provide mock value generation which could be improved if we have suggested values in future.
Helper functions to help generate values, the idea here is to try to suggest the ts-type from schema, if can't we will fallback to suggest ts-type from the generated type iteself, e.g
Record<string, "test" | 1>
would be a record type.Helper utils to detect the detailed ts types.
typespec-ts
The only thing in typespec project needs to do is apply the common transform logic and small improvements in schema for better detection.
autorest.typescript
We prefer to generate sample from swagger examples first and if no swagger examples, we will generate mock sample.
Testing
rlc-common/test/helpers/typeUtil.spec.ts
testing for different type convertiontypespec-ts/test/unit/transform/transformSchemas.spec.ts
testing for distinct schema datatypespec-ts/test/unit/sample/generateSampleContent.spec.ts
integration testing from typespec to generated values