-
Notifications
You must be signed in to change notification settings - Fork 245
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
[Bug]: A model containing an @header property doesn't keep that property when the object is generated #4244
Comments
|
Decide whether we want to generate the property and skip serialization, or if we want to collapse this into the method signature. |
If the model that contains the header is an "OptionsBag" then we leave it in the model and skip serialization. If the model that contains the header is NOT an "OptionsBag" then we move it to the signature. In tsp an options bag would be indicated by a operation that takes the entire model instead of the spread of the model. op foo(payload: Model): void vs op foo(...Model): void vs output op foo(): Model The header property is included on the Model as long as it has at least read visibility. |
This also needs to be considered for response headers and whether the behavior should differ between request/response headers. We should get architect feedback. This should also be a Spector scenario. |
This part isn't true. The header does appear on the signature in C#, but we want to decide whether we should change the behavior to more closely match the tsp. |
Given the fact that the model properties will no longer contain the request/response bodies as per the protocol definition, we should consider the concept of protocol vs convenience models as per @KrzysztofCwalina. A protocol model represents the request/response body exactly, whereas a convenience model may contain additional things like headers. We would always generate protocol models, and sometimes there would be a separate convenience model. When implementing the support for generating header properties within a model, we should consider still generating an internal protocol model that does not have the extra property and use that when serializing/deserializing the body. The extra information from the header would be used to construct the convenience model, e.g. header + protocol model == convenience model. If we ever decide to make protocol models a public concept for use with protocol methods, we will be better positioned to do that if we generate internal protocol models now. The downside to having the separate models is we would have to do a copy when going from protocol to convenience and vice versa. One other thing to note is that it is by design that header properties will not work inside of a model that is annotated with body, or for which there is no annotation (as body is the default location). If tracing is enabled, you will see a warning like this:
To enable header properties, the container needs to be decorated with |
This is blocked on Azure/typespec-azure#2122 |
Visibililty has been added for non-body properties in Azure/typespec-azure#2163 |
So we are really filtering out those non-payload properties here:
I think "fixing" this requires quite a few changes in our generator.
|
Describe the bug
When I specify a model in typespec which contains a property with the @Header decorator, the generated code produces an object for the model which doesn't contain the header property. This is true regardless of whether the model is spread in an operation or not. I've repro'ed with a basic solution, below.
Reproduction
I put the typespec I used in a playground here, but I'm not exactly sure what pieces need to be included for it to compile, and felt like the C# code which was produced is relevant as well, so I've included that here.
So the typespec, with a model containing a header and a property:
And an operation asking for the model to be spread:
Produces (I removed most of the comments to make it smaller)
An anonymous model without the header property:
And a request method with the parameters spread, including the header
If I change the operation to not spread the model
It produces
The model from the typespec, but without the header property
The anonymous model, now taking in the defined model instead of just the property
And a request method which includes both the header and the model object
Checklist
The text was updated successfully, but these errors were encountered: