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

Optional Query Parameter Test #722

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

mcgallan
Copy link
Member

@mcgallan mcgallan commented Sep 10, 2024

This PR is for migrating Parameter-TypeSpec from autorest.csharp, mainly to test the combination of optional query parameters and their generation behavior in the generated code.

Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 3d81e86

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@azure-tools/cadl-ranch-specs Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

op FromRequired(@query start: string, @query end?: string, @query("api-version") apiVersion: string): void;

@scenario
@scenarioDoc("""
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have tests like these in versioning, what is this adding?

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, the versioning only tests a single optional query parameter and does not test its combination with other query parameters. Additionally, this operation is intended to contrast with the following operation to demonstrate that, regardless of whether the optional parameter is before or after the required parameter, in the generated SDK, the required parameter always precedes the optional parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we want to test more ordering, we can have http/parameters/optionality with a query section. And the naming shouldn't be fromRequired, because that signifies a growing-up from a required param to a required param + an optional param. Instead we can call this orderingWithRequired or something like that. I also don't see what the difference is between the fromOptional and fromRequired tests in this tsp. They both seem to be testing ordering to me, can you describe how they're different?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think if we want to test more ordering, we can have http/parameters/optionality with a query section. And the naming shouldn't be fromRequired, because that signifies a growing-up from a required param to a required param + an optional param. Instead we can call this orderingWithRequired or something like that. I also don't see what the difference is between the fromOptional and fromRequired tests in this tsp. They both seem to be testing ordering to me, can you describe how they're different?

Regarding the placement and naming of the operations in this part, I believe your suggestion is a more suitable solution. As for the difference between the two, it might be more intuitive in the generated code from Autorest.Csharp: operation2 represents the expected form from fromoptional, while operation represents the expected form from fromrequired. The difference between the two is that in fromrequired, the required query parameter is placed first, followed by the optional parameter. In fromoptional, it is the opposite, with the required parameter placed after the optional parameter. However, in the generated code, the optional parameter is always placed after the required parameter. This test is meant to illustrate this issue, and the Parameter-TypeSpec project is also aimed at testing this issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

@iscai-msft Do you have any suggestions on how to handle this part?

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, missed this during vacation. Do you see this test as testing ordering more or optionality? Since the file name is optionality, but the operation names are more ordering

Copy link
Member Author

Choose a reason for hiding this comment

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

@iscai-msft I think this test focuses more on testing ordering, specifically the impact of optional query parameters on the ordering of query parameters. Since the optional query test case has already appeared in Cadl Ranch, it is not necessary to add this test if it is meant to test optional query parameters. Therefore, renaming this file to query-ordering or something else might be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think this could also be included with the optional query test case, since this tests ordering with optionality. What are your thoughts on adding these 2 tests next to existing tests about optional parameters. Additionally, I'm not sure how important it is that they are "query" parameters, this seems to be testing ordering with optionality

Copy link
Member Author

Choose a reason for hiding this comment

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

@iscai-msft I made some modifications based on your suggestions. How does this version of the test look now?

Copy link
Member Author

Choose a reason for hiding this comment

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

@iscai-msft I have optimized the query parameter to a general parameter to ensure the test focuses on the optionality ordering of the parameters. I have also moved it to the parameter/body-optionality section. Additionally, I have made changes to the code based on the subsequent mockapi upgrades for the PR. Please help review.

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.

2 participants