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

[tcgc] add getHttpOperationParameter helper function #2010

Open
wants to merge 5 commits into
base: release/december-2024
Choose a base branch
from

Conversation

tadelesh
Copy link
Member

resolve: #1441

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 23, 2024

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - feature ✏️

add getHttpOperationParameter helper function

@azure-tools/typespec-client-generator-core - fix ✏️

ensure operation examples to be ordered

@azure-tools/typespec-client-generator-core - fix ✏️

get correct pageable info for azure pageable operation with inheritance return model

@azure-tools/typespec-client-generator-core - breaking ✏️

fix typo of crossLanguageDefinitionId of method.

@azure-tools/typespec-client-generator-core - feature ✏️

Add @isApiVersion decorator to override whether a parameter is an api version or not

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

}
}
}
if (result.length === 0 && param?.type.kind === "model" && !visited.has(param.type)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this a case of spread?

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 24, 2024

Choose a reason for hiding this comment

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

Seems grouping? Again, better to add comment.

BTW, do we have a UT on grouping (@override)?

Copy link
Member Author

@tadelesh tadelesh Dec 24, 2024

Choose a reason for hiding this comment

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

it is for @bodyRoot, for example:

model TestRequest {
  @header
  h: string;

  @query
  q: string;

  prop1: string;
  prop2: string;
}
op test(@bodyRoot request: TestRequest): void;

Copy link
Member Author

Choose a reason for hiding this comment

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

added a test with @override.

}
}
}
if (result.length === 0 && param?.type.kind === "model" && !visited.has(param.type)) {
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 24, 2024

Choose a reason for hiding this comment

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

Seems grouping? Again, better to add comment.

BTW, do we have a UT on grouping (@override)?

// 1. The property itself is an http parameter.
// 2. The property is a model, and the properties of the model are http parameters, recursively.
// 3. The property is a model, and the base model of the model has http parameters, recursively.
// When we find one, we return directly since a method/client parameter or property could only be used in one http parameter.
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 24, 2024

Choose a reason for hiding this comment

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

Is this assert valid for below case?

      model Params {
        @query foo: string;
        @query bar: string;
      }
      op func(...Params): void;
      `,
      `
      namespace MyCustomizations;
      op func(params: MyService.Params): void;
      @@override(MyService.func, MyCustomizations.func);

Example of this: grouping long list of query params in a e.g. List

Copy link
Member Author

@tadelesh tadelesh Dec 24, 2024

Choose a reason for hiding this comment

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

i think so. it is applied to 1. for params, its corresponding http parameters is undefined. you need to get them with foo and bar property. see my last test.

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 24, 2024

Choose a reason for hiding this comment

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

Ok, so a method parameter would map to at most 1 parameter, and strictly an HTTP parameter (body param or query param or header param or undefined, but not to property in body).

It is somewhat unexpected that one can go to the properties inside the model and call getHttpOperationParameter on it. Especially the @bodyRoot case of Shelf.name which most language won't generate a name in Shelf.

      model Shelf {
        @query
        name: string;
        theme?: string;
      }
      model CreateShelfRequest {
        @bodyRoot
        body: Shelf;
      }

Let's see what other reviewers think.

Copy link
Member Author

Choose a reason for hiding this comment

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

a little bit force and back for this. just want to make it simple. current spec does not contain such mix usage at least.

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 25, 2024

Choose a reason for hiding this comment

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

One concern is, if I call the method, and find the parameter maps to a kind=body, I seems not be able to tell at this state, whether the parameter is the body, or it actually be a property within that body?

Copy link
Member Author

@tadelesh tadelesh Dec 25, 2024

Choose a reason for hiding this comment

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

for current code, it will tell you this parameter is used as body. but it could not tell you the property of this parameter is also used as a query parameter.

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Dec 25, 2024

Choose a reason for hiding this comment

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

What I mean is,

model Model { key: string }

op myOp(@header h: string, @query q: string, @path p: string, @body body: Model): void;

call on "body" method param would map to body body param of the Model.

And

op myOp(@header h: string, @query q: string, @path p: string, ...Model): void;

call on "key" method param would also map to body body param of the Model.

Maybe it is not that bad, maybe we can use the mapping from the other side to determine...

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 got your point. you mean there is no way to tell how to map the exact value. then you are right, tcgc suggest to map from http parameter to method parameter.

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft left a comment

Choose a reason for hiding this comment

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

We can go with it, if no one objects.

Though I'd expect refinements or breaks, when dev start using it.

@tadelesh tadelesh requested a review from qiaozha December 25, 2024 02:55
@tadelesh
Copy link
Member Author

@qiaozha please help to review. current solution is kind of a tradeoff which should meet all language's requirement, but not so convenience for exact value mapping.

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.

4 participants