-
Notifications
You must be signed in to change notification settings - Fork 230
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
Behavior of op test(...Model)
#1392
Comments
The introduction of a Thus, a generic Under what circumstances would it be preferable for a client library to not take a (please note that a given emitter may map things differently - e.g. an emitter that distinguishes between inputs and outputs would be free to manufacture an output type based on the input. But since different emitters will have different mappings of the service model into their design patterns, that is really an emitter concern and not something that goes into the conceptual description of the service) |
Without syntax for #1140 we can't really disambiguate the two cases clearly in Cadl syntax. But even with that syntax, the behavior is still not entirely clear as it moves the question into the model you spread (i.e., is UserContent a model we want to represent, or is it just a convenient way to compose the User model). Going back to the thought we had in mind when we started using Which leaves the question of, how would I override this behavior? One possible way, assuming the service has a concept of a user but for this method for whatever reason wants to be clear that the operation takes the same data a user holds but does not take a nominal User, might be All that said, I think a reasonable alternative approach is to say that |
@johanste if I understand you correctly would you lean towards using the following to differentiate? If we want an option bag In other words there is no short hand for spread into parameters unless |
I started a doc showing different Cadl operation styles, what it means in http context and what we'd want the client to be https://cadlwebsite.z1.web.core.windows.net/prs/1396/standard-library/rest/examples.html |
It appears you are leaning towards this as well then? Spread operation means OptionsBag and if you don't want an options bag you must be explicit on your op definition? Can you add an example that shows the case where I want to spread the query / header params but use a single param for the entire body? |
Sorry, I entered those examples on how we envisioned things before this issue to represent the current state and make sure we cover all cases . It is still open for discussion. will add that example |
FWIW what we send to emitters is very strongly implied by the source code, I don't think we can change that. The behavior you want requires syntax like #1140. But it would be a fairly simple matter for a helper to construct the view you want in the meantime. |
I don't think I would advocate to change the meaning of "spread operator" to mean single parameter if its a model we are spreading and enumerated properties if its an alias we are spreading. I was just trying to repeat back what I am hearing being suggested to make sure I understand what is being suggested. |
Correct. In general, it is my belief (experience?) you will find fewer compelling reasons to "spread" into individual parameters for any model types that are ever used as outputs. And if you do spread, it is more likely going to be a client-only overload rather than a separate service operation. Models that are used as input-only in multiple operations are less common and we should review their existence when we review the service API description (and make them into aliases if necessary). For specific operations, a given emitter may have an established design pattern - e.g. python prefers spreading properties to keyword-only parameters over creating separate named models for json-merge-patch PATCH operations. The python emitter is responsible for said transformation of the signature. It feels like what we are talking about is (at least partially) an override in how a given emitter generates code for a specific operation or model. Which feels like an augment decorator in an emitter-specific client side-car (i.e. cadl-dpg for our DPG emitters). |
Regarding #1392 (comment) There is a REST-layer API built on a similarly named compiler API that is used by the openapi emitters to recover a named model from an anonymous model consisting entirely of properties spread/sourced from something named. It handles more than just this top-level spread body parameter case. It also deals with things like Calling this API is part of the documentation I am writing for #1083. I tried to move this call into the REST layer API that enumerates routes but that turned out to be too difficult in general because you have to do it recursively, but it is not currently tractable for the rest layer to recursively transform the core Cadl type graph before passing it along to emitters. It is also not feasible to change the core semantics so that these names are recovered automatically. The API is here, next to other API that are useful to reason about metadata and visibility: What is happening when an alias changes the openapi behavior is that it makes the name recovery done by this API impossible since aliases are erased in the type graph. My document will walk through a sample emitter much smaller than the openapi emitter that calls all of the relevant API. |
Tagging @lmazuel since he showed an interest in this topic as well... |
Summary of meeting
|
I'm still working on the doc mentioned, but I have written a sample and some summary notes for the text that should help in the meantime. See #1083 (comment) |
I believe the meeting summary above is enough to close this at this point. I have gathered that DPG emitters have already started using getEffectiveModelType effectively (couldn't resist the pun, sorry). We also settled on https://github.com/Azure/cadl-azure/issues/2360 that using explicit I think DPG decorators like Let me know if you disagree and I can re-open, or even better, it might help to split off new issues that are more targeted at work that is still needed. |
Dpg emitters have been confused by what we mean and what we want the generated code to look like
Here what we expected this too look like
however they have interpreted that as spreading properties but still combining the body together(which is another question of its own)
Problem
Now if we decide to keep our original meaning
...User
meansUser
is the input then we cannot represent the case where we actually want to spread the properties and this is something DPG teams have said is a behavior wantedBasically how do I represent those 2 signature from the
User
modelOption 1:
...User
still means input is UserThat means we would need to create some new core type
SpreadProps
which would remove the reference to theUser
Option 2:
...User
means spreadThat means we would need a new syntax to specify the input (related to #1140)
cc: @m-nash
The text was updated successfully, but these errors were encountered: